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

Method test_issue14818

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

Source from the content-addressed store, hash-verified

4490 # Test various issues with keyword arguments passed to ET.Element
4491 # constructor and methods
4492 def test_issue14818(self):
4493 x = ET.XML("<a>foo</a>")
4494 self.assertEqual(x.find('a', None),
4495 x.find(path='a', namespaces=None))
4496 self.assertEqual(x.findtext('a', None, None),
4497 x.findtext(path='a', default=None, namespaces=None))
4498 self.assertEqual(x.findall('a', None),
4499 x.findall(path='a', namespaces=None))
4500 self.assertEqual(list(x.iterfind('a', None)),
4501 list(x.iterfind(path='a', namespaces=None)))
4502
4503 self.assertEqual(ET.Element('a').attrib, {})
4504 elements = [
4505 ET.Element('a', dict(href="#", id="foo")),
4506 ET.Element('a', attrib=dict(href="#", id="foo")),
4507 ET.Element('a', dict(href="#"), id="foo"),
4508 ET.Element('a', href="#", id="foo"),
4509 ET.Element('a', dict(href="#", id="foo"), href="#", id="foo"),
4510 ET.Element('a', frozendict(href="#", id="foo")),
4511 ET.Element('a', frozendict(href="#"), id="foo"),
4512 ET.Element('a', attrib=frozendict(href="#", id="foo")),
4513 ]
4514 for e in elements:
4515 self.assertEqual(e.tag, 'a')
4516 self.assertEqual(e.attrib, dict(href="#", id="foo"))
4517
4518 e2 = ET.SubElement(elements[0], 'foobar', attrib={'key1': 'value1'})
4519 self.assertEqual(e2.attrib['key1'], 'value1')
4520 e3 = ET.SubElement(elements[0], 'foobar',
4521 attrib=frozendict({'key1': 'value1'}))
4522 self.assertEqual(e3.attrib['key1'], 'value1')
4523
4524 errmsg = 'must be dict or frozendict, not str'
4525 with self.assertRaisesRegex(TypeError, errmsg):
4526 ET.Element('a', "I'm not a dict")
4527 with self.assertRaisesRegex(TypeError, errmsg):
4528 ET.Element('a', attrib="I'm not a dict")
4529
4530# --------------------------------------------------------------------
4531

Callers

nothing calls this directly

Calls 8

listClass · 0.85
frozendictClass · 0.85
assertRaisesRegexMethod · 0.80
assertEqualMethod · 0.45
findMethod · 0.45
findtextMethod · 0.45
findallMethod · 0.45
iterfindMethod · 0.45

Tested by

no test coverage detected