MCPcopy Index your code
hub / github.com/python/cpython / test_findall_wildcard

Method test_findall_wildcard

Lib/test/test_xml_etree.py:3540–3582  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3538 self.assertEqual(len(root.findall(".//b", namespaces=nsmap)), 1)
3539
3540 def test_findall_wildcard(self):
3541 root = ET.XML('''
3542 <a xmlns:x="X" xmlns:y="Y">
3543 <x:b><c/></x:b>
3544 <b/>
3545 <c><x:b/><b/></c><y:b/>
3546 </a>''&#x27;)
3547 root.append(ET.Comment('test'))
3548
3549 self.assertEqual(summarize_list(root.findall("{*}b")),
3550 ['{X}b', 'b', '{Y}b'])
3551 self.assertEqual(summarize_list(root.findall("{*}c")),
3552 ['c'])
3553 self.assertEqual(summarize_list(root.findall("{X}*")),
3554 ['{X}b'])
3555 self.assertEqual(summarize_list(root.findall("{Y}*")),
3556 ['{Y}b'])
3557 self.assertEqual(summarize_list(root.findall("{}*")),
3558 ['b', 'c'])
3559 self.assertEqual(summarize_list(root.findall("{}b")), # only for consistency
3560 ['b'])
3561 self.assertEqual(summarize_list(root.findall("{}b")),
3562 summarize_list(root.findall("b")))
3563 self.assertEqual(summarize_list(root.findall("{*}*")),
3564 ['{X}b', 'b', 'c', '{Y}b'])
3565 # This is an unfortunate difference, but that's how find('*') works.
3566 self.assertEqual(summarize_list(root.findall("{*}*") + [root[-1]]),
3567 summarize_list(root.findall("*")))
3568
3569 self.assertEqual(summarize_list(root.findall(".//{*}b")),
3570 ['{X}b', 'b', '{X}b', 'b', '{Y}b'])
3571 self.assertEqual(summarize_list(root.findall(".//{*}c")),
3572 ['c', 'c'])
3573 self.assertEqual(summarize_list(root.findall(".//{X}*")),
3574 ['{X}b', '{X}b'])
3575 self.assertEqual(summarize_list(root.findall(".//{Y}*")),
3576 ['{Y}b'])
3577 self.assertEqual(summarize_list(root.findall(".//{}*")),
3578 ['c', 'b', 'c', 'b'])
3579 self.assertEqual(summarize_list(root.findall(".//{}b")), # only for consistency
3580 ['b', 'b'])
3581 self.assertEqual(summarize_list(root.findall(".//{}b")),
3582 summarize_list(root.findall(".//b")))
3583
3584 def test_bad_find(self):
3585 e = ET.XML(SAMPLE_XML)

Callers

nothing calls this directly

Calls 4

summarize_listFunction · 0.85
appendMethod · 0.45
assertEqualMethod · 0.45
findallMethod · 0.45

Tested by

no test coverage detected