Пример #1
0
 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")))
Пример #2
0
 def test_parse(self):
     roots = HTML5Strip.parse("<p>hello, world</p>")
     self.assertEqual(roots[0].text, "hello, world")
Пример #3
0
 def test_has_no_text_on_html(self):
     roots = HTML5Strip.parse(u"<p>\u2000</p>")
     self.assertFalse(HTML5Fragment.has_text(roots[0].text))
Пример #4
0
 def test_has_text_on_html(self):
     roots = HTML5Strip.parse(u"<p>hello, world</p>")
     self.assertTrue(HTML5Fragment.has_text(roots[0].text))
Пример #5
0
 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>")
Пример #6
0
 def test_strip_root(self):
     fragment = HTML5Fragment(HTML5Strip.parse("<p>hello, world</p>")[0])
     res = fragment.strip(set([fragment.root]))
     self.assertEqual(res, "")
Пример #7
0
 def test_parse_fragments(self):
     roots = HTML5Strip.parse("<p>hello</p><p>world</p>")
     self.assertEqual([r.text for r in roots], ["hello", "world"])