summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorAmmar Askar <ammar@ammaraskar.com>2020-11-09 07:02:39 (GMT)
committerGitHub <noreply@github.com>2020-11-09 07:02:39 (GMT)
commit97e8b1eaeaf3aa325c84ff2e13417c30414d0269 (patch)
treed1979f9ac520d18afa0e089568dfb92794a64e44 /Lib/test/test_xml_etree.py
parent4eb41d055e8307b8206f680287e492a6db068acd (diff)
downloadcpython-97e8b1eaeaf3aa325c84ff2e13417c30414d0269.zip
cpython-97e8b1eaeaf3aa325c84ff2e13417c30414d0269.tar.gz
cpython-97e8b1eaeaf3aa325c84ff2e13417c30414d0269.tar.bz2
bpo-40624: Add support for the XPath != operator in xml.etree (GH-22147)
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 3f1f378..fd4a385 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -2852,8 +2852,12 @@ class ElementFindTest(unittest.TestCase):
['tag'] * 3)
self.assertEqual(summarize_list(e.findall('.//tag[@class="a"]')),
['tag'])
+ self.assertEqual(summarize_list(e.findall('.//tag[@class!="a"]')),
+ ['tag'] * 2)
self.assertEqual(summarize_list(e.findall('.//tag[@class="b"]')),
['tag'] * 2)
+ self.assertEqual(summarize_list(e.findall('.//tag[@class!="b"]')),
+ ['tag'])
self.assertEqual(summarize_list(e.findall('.//tag[@id]')),
['tag'])
self.assertEqual(summarize_list(e.findall('.//section[tag]')),
@@ -2875,6 +2879,19 @@ class ElementFindTest(unittest.TestCase):
self.assertEqual(summarize_list(e.findall(".//section[ tag = 'subtext' ]")),
['section'])
+ # Negations of above tests. They match nothing because the sole section
+ # tag has subtext.
+ self.assertEqual(summarize_list(e.findall(".//section[tag!='subtext']")),
+ [])
+ self.assertEqual(summarize_list(e.findall(".//section[tag !='subtext']")),
+ [])
+ self.assertEqual(summarize_list(e.findall(".//section[tag!= 'subtext']")),
+ [])
+ self.assertEqual(summarize_list(e.findall(".//section[tag != 'subtext']")),
+ [])
+ self.assertEqual(summarize_list(e.findall(".//section[ tag != 'subtext' ]")),
+ [])
+
self.assertEqual(summarize_list(e.findall(".//tag[.='subtext']")),
['tag'])
self.assertEqual(summarize_list(e.findall(".//tag[. ='subtext']")),
@@ -2890,6 +2907,24 @@ class ElementFindTest(unittest.TestCase):
self.assertEqual(summarize_list(e.findall(".//tag[.= ' subtext']")),
[])
+ # Negations of above tests.
+ # Matches everything but the tag containing subtext
+ self.assertEqual(summarize_list(e.findall(".//tag[.!='subtext']")),
+ ['tag'] * 3)
+ self.assertEqual(summarize_list(e.findall(".//tag[. !='subtext']")),
+ ['tag'] * 3)
+ self.assertEqual(summarize_list(e.findall('.//tag[.!= "subtext"]')),
+ ['tag'] * 3)
+ self.assertEqual(summarize_list(e.findall('.//tag[ . != "subtext" ]')),
+ ['tag'] * 3)
+ self.assertEqual(summarize_list(e.findall(".//tag[. != 'subtext']")),
+ ['tag'] * 3)
+ # Matches all tags.
+ self.assertEqual(summarize_list(e.findall(".//tag[. != 'subtext ']")),
+ ['tag'] * 4)
+ self.assertEqual(summarize_list(e.findall(".//tag[.!= ' subtext']")),
+ ['tag'] * 4)
+
# duplicate section => 2x tag matches
e[1] = e[2]
self.assertEqual(summarize_list(e.findall(".//section[tag = 'subtext']")),