mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-100933: Improve check_element
helper in test_xml_etree
(#100934)
Items checked by this test are always `str` and `dict` instances.
This commit is contained in:
parent
feec49c407
commit
eb49d32b9a
1 changed files with 4 additions and 23 deletions
|
@ -203,25 +203,6 @@ class ElementTreeTest(unittest.TestCase):
|
||||||
def test_interface(self):
|
def test_interface(self):
|
||||||
# Test element tree interface.
|
# Test element tree interface.
|
||||||
|
|
||||||
def check_string(string):
|
|
||||||
len(string)
|
|
||||||
for char in string:
|
|
||||||
self.assertEqual(len(char), 1,
|
|
||||||
msg="expected one-character string, got %r" % char)
|
|
||||||
new_string = string + ""
|
|
||||||
new_string = string + " "
|
|
||||||
string[:0]
|
|
||||||
|
|
||||||
def check_mapping(mapping):
|
|
||||||
len(mapping)
|
|
||||||
keys = mapping.keys()
|
|
||||||
items = mapping.items()
|
|
||||||
for key in keys:
|
|
||||||
item = mapping[key]
|
|
||||||
mapping["key"] = "value"
|
|
||||||
self.assertEqual(mapping["key"], "value",
|
|
||||||
msg="expected value string, got %r" % mapping["key"])
|
|
||||||
|
|
||||||
def check_element(element):
|
def check_element(element):
|
||||||
self.assertTrue(ET.iselement(element), msg="not an element")
|
self.assertTrue(ET.iselement(element), msg="not an element")
|
||||||
direlem = dir(element)
|
direlem = dir(element)
|
||||||
|
@ -231,12 +212,12 @@ class ElementTreeTest(unittest.TestCase):
|
||||||
self.assertIn(attr, direlem,
|
self.assertIn(attr, direlem,
|
||||||
msg='no %s visible by dir' % attr)
|
msg='no %s visible by dir' % attr)
|
||||||
|
|
||||||
check_string(element.tag)
|
self.assertIsInstance(element.tag, str)
|
||||||
check_mapping(element.attrib)
|
self.assertIsInstance(element.attrib, dict)
|
||||||
if element.text is not None:
|
if element.text is not None:
|
||||||
check_string(element.text)
|
self.assertIsInstance(element.text, str)
|
||||||
if element.tail is not None:
|
if element.tail is not None:
|
||||||
check_string(element.tail)
|
self.assertIsInstance(element.tail, str)
|
||||||
for elem in element:
|
for elem in element:
|
||||||
check_element(elem)
|
check_element(elem)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue