diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-01-22 14:12:54 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-01-22 14:12:54 (GMT) |
commit | a80f761a6d23f42abc529a338477741ba4973168 (patch) | |
tree | 99cfc45e57993cd318b5a2bdd33eabd9e1d5af4f | |
parent | 076b97ea27aed132bd3ee99549529a13c09b2bd3 (diff) | |
download | cpython-a80f761a6d23f42abc529a338477741ba4973168.zip cpython-a80f761a6d23f42abc529a338477741ba4973168.tar.gz cpython-a80f761a6d23f42abc529a338477741ba4973168.tar.bz2 |
Add some tests for XPath numeric indexing
-rw-r--r-- | Lib/test/test_xml_etree.py | 17 |
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) |