MCPcopy Create free account
hub / github.com/gawel/pyquery / TestHTMLParser

Class TestHTMLParser

tests/test_pyquery.py:787–821  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

785
786
787class TestHTMLParser(TestCase):
788 xml = "<div>I'm valid XML</div>"
789 html = ''&#x27;<div class="portlet">
790 <a href="/toto">TestimageMy link text</a>
791 <a href="/toto2">imageMy link text 2</a>
792 Behind you, a three-headed HTML&dash;Entity!
793 </div>''&#x27;
794
795 def test_parser_persistance(self):
796 d = pq(self.xml, parser='xml')
797 self.assertRaises(etree.XMLSyntaxError, lambda: d.after(self.html))
798 d = pq(self.xml, parser='html')
799 d.after(self.html) # this should not fail
800
801 def test_replaceWith(self):
802 expected = ''&#x27;<div class="portlet">
803 <a href="/toto">TestimageMy link text</a>
804 <a href="/toto2">imageMy link text 2</a>
805 Behind you, a three-headed HTML&amp;dash;Entity!
806 </div>''&#x27;
807 d = pq(self.html)
808 d('img').replace_with('image')
809 val = d.__html__()
810 assert val == expected, (repr(val), repr(expected))
811
812 def test_replaceWith_with_function(self):
813 expected = ''&#x27;<div class="portlet">
814 TestimageMy link text
815 imageMy link text 2
816 Behind you, a three-headed HTML&amp;dash;Entity!
817 </div>''&#x27;
818 d = pq(self.html)
819 d('a').replace_with(lambda i, e: pq(e).html())
820 val = d.__html__()
821 assert val == expected, (repr(val), repr(expected))
822
823
824class TestXMLNamespace(TestCase):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…