Added simple test for parser of annotated text

pull/21/head
Mišo Belica 11 years ago
parent 05d2230015
commit d054823958

@ -0,0 +1,18 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Paragraphs</title>
</head>
<body>
<div>
<h1>Nadpis H1, ktorý chce byť prvý s textom ale predbehol ho "title"</h1>
<p>
Toto je prvý odstavec a to je fajn.
</p>
<p>
Tento text je tu aby vyplnil prázdne miesto v srdci súboru.
Aj súbory majú predsa city.
</p>
</div>
</body>
</html>

@ -3,9 +3,10 @@
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
from lxml.html import fragment_fromstring
from lxml.html import fragment_fromstring, document_fromstring
from readability.annotated_text import AnnotatedTextHandler
from .compat import unittest
from .utils import load_snippet
class TestAnnotatedText(unittest.TestCase):
@ -115,3 +116,18 @@ class TestAnnotatedText(unittest.TestCase):
("6", ("em",)),
)
self.assertEqual(paragraph, expected)
def test_include_heading(self):
dom = document_fromstring(load_snippet("h1_and_2_paragraphs.html"))
annotated_text = AnnotatedTextHandler.parse(dom.find("body"))
expected = [
(
('Nadpis H1, ktorý chce byť prvý s textom ale predbehol ho "title"', ("h1",)),
("Toto je prvý odstavec a to je fajn.", None),
),
(
("Tento text je tu aby vyplnil prázdne miesto v srdci súboru.\nAj súbory majú predsa city.", None),
),
]
self.assertSequenceEqual(annotated_text, expected)

Loading…
Cancel
Save