[Python-checkins] [3.10] gh-100933: Improve `check_element` helper in `test_xml_etree` (GH-100934) (#101687)
ambv
webhook-mailer at python.org
Wed Feb 8 06:40:46 EST 2023
https://github.com/python/cpython/commit/c51cd54b6560879c35ec6d36f8ec72194c4f27a9
commit: c51cd54b6560879c35ec6d36f8ec72194c4f27a9
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2023-02-08T12:40:40+01:00
summary:
[3.10] gh-100933: Improve `check_element` helper in `test_xml_etree` (GH-100934) (#101687)
Items checked by this test are always `str` and `dict` instances.
(cherry picked from commit eb49d32b9af0b3b01a5588626179187f11d145c9)
Co-authored-by: Nikita Sobolev <mail at sobolevn.me>
files:
M Lib/test/test_xml_etree.py
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index d7b5e5208c53..940e02630e90 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -203,25 +203,6 @@ def serialize_check(self, elem, expected):
def test_interface(self):
# 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):
self.assertTrue(ET.iselement(element), msg="not an element")
direlem = dir(element)
@@ -231,12 +212,12 @@ def check_element(element):
self.assertIn(attr, direlem,
msg='no %s visible by dir' % attr)
- check_string(element.tag)
- check_mapping(element.attrib)
+ self.assertIsInstance(element.tag, str)
+ self.assertIsInstance(element.attrib, dict)
if element.text is not None:
- check_string(element.text)
+ self.assertIsInstance(element.text, str)
if element.tail is not None:
- check_string(element.tail)
+ self.assertIsInstance(element.tail, str)
for elem in element:
check_element(elem)
More information about the Python-checkins
mailing list