Commits

Eli Bendersky committed 2e23517 Draft

Add some tests for XPath numeric indexing

  • Participants
  • Parent commits 6b1e393
  • Branches 3.3

Comments (0)

Files changed (1)

File Lib/test/test_xml_etree.py

         # Issue #16922
         self.assertEqual(ET.XML('<tag><empty /></tag>').findtext('empty'), '')
 
+    def test_find_xpath(self):
+        LINEAR_XML = '''
+        <body>
+            <tag class='a'/>
+            <tag class='b'/>
+            <tag class='c'/>
+            <tag class='d'/>
+        </body>'''
+        e = ET.XML(LINEAR_XML)
+
+        # Test for numeric indexing and last()
+        self.assertEqual(e.find('./tag[1]').attrib['class'], 'a')
+        self.assertEqual(e.find('./tag[2]').attrib['class'], 'b')
+        self.assertEqual(e.find('./tag[last()]').attrib['class'], 'd')
+        self.assertEqual(e.find('./tag[last()-1]').attrib['class'], 'c')
+        self.assertEqual(e.find('./tag[last()-2]').attrib['class'], 'b')
+
     def test_findall(self):
         e = ET.XML(SAMPLE_XML)
         e[2] = ET.XML(SAMPLE_SECTION)