summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2017-09-30 13:35:21 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-30 13:35:21 (GMT)
commit101a5e84acbab9d880e150195f23185dfb5449a9 (patch)
tree9fd7915a7e4049f33f9d083312d2c1b78d4eeb38 /Lib/test/test_xml_etree.py
parent9811e80fd0ed9d74c76a66f1dd4e4b8afa9e8f53 (diff)
downloadcpython-101a5e84acbab9d880e150195f23185dfb5449a9.zip
cpython-101a5e84acbab9d880e150195f23185dfb5449a9.tar.gz
cpython-101a5e84acbab9d880e150195f23185dfb5449a9.tar.bz2
bpo-31648: Improve ElementPath (#3835)
* Allow whitespace inside of ElementPath predicates. * Add ElementPath predicate support for text comparison of the current node, like "[.='text']".
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 661ad8b..02812f3 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -2237,6 +2237,39 @@ class ElementFindTest(unittest.TestCase):
['tag'] * 2)
self.assertEqual(e.findall('section//'), e.findall('section//*'))
+ self.assertEqual(summarize_list(e.findall(".//section[tag='subtext']")),
+ ['section'])
+ self.assertEqual(summarize_list(e.findall(".//section[tag ='subtext']")),
+ ['section'])
+ self.assertEqual(summarize_list(e.findall(".//section[tag= 'subtext']")),
+ ['section'])
+ self.assertEqual(summarize_list(e.findall(".//section[tag = 'subtext']")),
+ ['section'])
+ self.assertEqual(summarize_list(e.findall(".//section[ tag = 'subtext' ]")),
+ ['section'])
+
+ self.assertEqual(summarize_list(e.findall(".//tag[.='subtext']")),
+ ['tag'])
+ self.assertEqual(summarize_list(e.findall(".//tag[. ='subtext']")),
+ ['tag'])
+ self.assertEqual(summarize_list(e.findall('.//tag[.= "subtext"]')),
+ ['tag'])
+ self.assertEqual(summarize_list(e.findall('.//tag[ . = "subtext" ]')),
+ ['tag'])
+ self.assertEqual(summarize_list(e.findall(".//tag[. = 'subtext']")),
+ ['tag'])
+ self.assertEqual(summarize_list(e.findall(".//tag[. = 'subtext ']")),
+ [])
+ self.assertEqual(summarize_list(e.findall(".//tag[.= ' subtext']")),
+ [])
+
+ # duplicate section => 2x tag matches
+ e[1] = e[2]
+ self.assertEqual(summarize_list(e.findall(".//section[tag = 'subtext']")),
+ ['section', 'section'])
+ self.assertEqual(summarize_list(e.findall(".//tag[. = 'subtext']")),
+ ['tag', 'tag'])
+
def test_test_find_with_ns(self):
e = ET.XML(SAMPLE_XML_NS)
self.assertEqual(summarize_list(e.findall('tag')), [])