summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-01-22 14:12:54 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-01-22 14:12:54 (GMT)
commita80f761a6d23f42abc529a338477741ba4973168 (patch)
tree99cfc45e57993cd318b5a2bdd33eabd9e1d5af4f /Lib/test/test_xml_etree.py
parent076b97ea27aed132bd3ee99549529a13c09b2bd3 (diff)
downloadcpython-a80f761a6d23f42abc529a338477741ba4973168.zip
cpython-a80f761a6d23f42abc529a338477741ba4973168.tar.gz
cpython-a80f761a6d23f42abc529a338477741ba4973168.tar.bz2
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 b4edd74..f6505d6 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)