summaryrefslogtreecommitdiff
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-01-22 06:15:29 -0800
committerEli Bendersky <eliben@gmail.com>2013-01-22 06:15:29 -0800
commitd561db74f9bccf771d8f0432889b383b723e0aad (patch)
tree3014e615917a1203bc907edbe1a234f808459211 /Lib/test/test_xml_etree.py
parent45133aa76d2eb5201a1a30f3d163b0bbf46e327e (diff)
parentc97775f50aace4a44ebb1a135dbe399fcf1a3bd1 (diff)
downloadcpython-d561db74f9bccf771d8f0432889b383b723e0aad.tar.gz
Add some tests for XPath numeric indexing
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index f2bbb4c742..00db44cdb7 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1776,6 +1776,23 @@ class ElementFindTest(unittest.TestCase):
# 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)