(self)
| 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 |
nothing calls this directly
no test coverage detected