summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-01-22 14:15:29 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-01-22 14:15:29 (GMT)
commit791c97a6a89e30d02fe4b0746daec61de44a5ad3 (patch)
treeb7a633b450831ac873fd1603cf49398fc9b03e19
parentf69f961c68f36198656154de9f93b2f99425c10e (diff)
parenta80f761a6d23f42abc529a338477741ba4973168 (diff)
downloadcpython-791c97a6a89e30d02fe4b0746daec61de44a5ad3.zip
cpython-791c97a6a89e30d02fe4b0746daec61de44a5ad3.tar.gz
cpython-791c97a6a89e30d02fe4b0746daec61de44a5ad3.tar.bz2
Add some tests for XPath numeric indexing
-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 f2bbb4c..00db44c 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)