[Python-checkins] cpython (merge 3.3 -> default): Add some tests for XPath numeric indexing
eli.bendersky
python-checkins at python.org
Tue Jan 22 15:15:41 CET 2013
http://hg.python.org/cpython/rev/05b41ae10db8
changeset: 81655:05b41ae10db8
parent: 81653:90dd276d3beb
parent: 81654:2e2351733a6f
user: Eli Bendersky <eliben at gmail.com>
date: Tue Jan 22 06:15:29 2013 -0800
summary:
Add some tests for XPath numeric indexing
files:
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
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1776,6 +1776,23 @@
# 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)
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list