def testAssertEqualsLxmlsXpathToHereWithProcessingInstructions(self): xml = '''\ <?pro cessing instruction?> <a xmlns="n:s/#"> <?php ...?> <?notphp Intermezzo?> <?php just kidding!?> <b/> </a> <?xml-stylesheet href="what.css" type="text/ever"?> <?pro with newlines?>''' lxml = parseString(xml) _pro_cessing = lxml.getroot().getprevious() _xml_style = lxml.getroot().getnext() _pro_newline = _xml_style.getnext() _inside_1_php = lxml.getroot().getchildren()[0] _inside_2_notphp = lxml.getroot().getchildren()[1] _inside_3_php = lxml.getroot().getchildren()[2] c = CompareXml(expectedNode=lxml, resultNode=lxml) self.assertEqual("{n:s/#}a", c.xpathToHere(_inside_1_php)) self.assertEqual("{n:s/#}a", c.xpathToHere(_inside_2_notphp)) self.assertEqual("{n:s/#}a", c.xpathToHere(_inside_3_php)) self.assertEqual("{n:s/#}a/processing-instruction('php')[1]", c.xpathToHere(_inside_1_php, includeCurrent=True)) self.assertEqual("{n:s/#}a/processing-instruction('notphp')", c.xpathToHere(_inside_2_notphp, includeCurrent=True)) self.assertEqual("{n:s/#}a/processing-instruction('php')[2]", c.xpathToHere(_inside_3_php, includeCurrent=True)) self.assertEqual("", c.xpathToHere(_pro_cessing)) self.assertEqual("", c.xpathToHere(_xml_style)) self.assertEqual("", c.xpathToHere(_pro_newline)) self.assertEqual("processing-instruction('pro')[1]", c.xpathToHere(_pro_cessing, includeCurrent=True)) self.assertEqual("processing-instruction('xml-stylesheet')", c.xpathToHere(_xml_style, includeCurrent=True)) self.assertEqual("processing-instruction('pro')[2]", c.xpathToHere(_pro_newline, includeCurrent=True))
def testAssertEqualsLxmlsXpathToHereWithCommentNodes(self): xml = '''\ <!-- 1st Comment --> <!-- Pre-Root Comment --> <a xmlns="n:s/#"> <!-- 1st Comment inside --> <!-- 2nd Comment inside --> <b/> </a> <!-- Post-Root Comment --> <!-- last Comment -->''' lxml = parseString(xml) _pre_root = lxml.getroot().getprevious() _1st = _pre_root.getprevious() _post_root = lxml.getroot().getnext() _last = _post_root.getnext() _1st_inside = lxml.getroot().getchildren()[0] _2nd_inside = lxml.getroot().getchildren()[1] c = CompareXml(expectedNode=lxml, resultNode=lxml) self.assertEqual('{n:s/#}a', c.xpathToHere(_1st_inside)) self.assertEqual('{n:s/#}a', c.xpathToHere(_2nd_inside)) self.assertEqual('{n:s/#}a/comment()[1]', c.xpathToHere(_1st_inside, includeCurrent=True)) self.assertEqual('{n:s/#}a/comment()[2]', c.xpathToHere(_2nd_inside, includeCurrent=True)) self.assertEqual('', c.xpathToHere(_1st)) self.assertEqual('', c.xpathToHere(_pre_root)) self.assertEqual('comment()[1]', c.xpathToHere(_1st, includeCurrent=True)) self.assertEqual('comment()[2]', c.xpathToHere(_pre_root, includeCurrent=True)) self.assertEqual('', c.xpathToHere(_post_root)) self.assertEqual('', c.xpathToHere(_last)) self.assertEqual('comment()[3]', c.xpathToHere(_post_root, includeCurrent=True)) self.assertEqual('comment()[4]', c.xpathToHere(_last, includeCurrent=True))