def test_get_blacklist(self): roots = HTML5Strip.parse("<p>hello, world<br></p>") fragment = HTML5Fragment(roots[0]) self.assertEqual(fragment.blacklist, set(roots[0].findall("br")))
def test_parse(self): roots = HTML5Strip.parse("<p>hello, world</p>") self.assertEqual(roots[0].text, "hello, world")
def test_has_no_text_on_html(self): roots = HTML5Strip.parse(u"<p>\u2000</p>") self.assertFalse(HTML5Fragment.has_text(roots[0].text))
def test_has_text_on_html(self): roots = HTML5Strip.parse(u"<p>hello, world</p>") self.assertTrue(HTML5Fragment.has_text(roots[0].text))
def test_strip_tail(self): fragment = HTML5Fragment(HTML5Strip.parse("<p>hello,<br>world</p>")[0]) res = fragment.strip(set(fragment.root.findall("br"))) self.assertEqual(res, "<p>hello,world</p>")
def test_strip_root(self): fragment = HTML5Fragment(HTML5Strip.parse("<p>hello, world</p>")[0]) res = fragment.strip(set([fragment.root])) self.assertEqual(res, "")
def test_parse_fragments(self): roots = HTML5Strip.parse("<p>hello</p><p>world</p>") self.assertEqual([r.text for r in roots], ["hello", "world"])