mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-31648: Improve ElementPath (#3835)
* Allow whitespace inside of ElementPath predicates. * Add ElementPath predicate support for text comparison of the current node, like "[.='text']".
This commit is contained in:
parent
9811e80fd0
commit
101a5e84ac
5 changed files with 68 additions and 7 deletions
|
|
@ -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')), [])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue