← 返回首页
gh-100933: Improve `check_element` helper in `test_xml_etree` (GH-100… · miss-islington/cpython@46cf240 · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Commit 46cf240

Browse files
authored andcommitted
pythongh-100933: Improve check_element helper in test_xml_etree (pythonGH-100934)
Items checked by this test are always `str` and `dict` instances. (cherry picked from commit eb49d32) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent a0b7c3f commit 46cf240

1 file changed

Lines changed: 4 additions & 23 deletions

File tree

‎Lib/test/test_xml_etree.py‎

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,6 @@ def serialize_check(self, elem, expected):
203203
def test_interface(self):
204204
# Test element tree interface.
205205

206-
def check_string(string):
207-
len(string)
208-
for char in string:
209-
self.assertEqual(len(char), 1,
210-
msg="expected one-character string, got %r" % char)
211-
new_string = string + ""
212-
new_string = string + " "
213-
string[:0]
214-
215-
def check_mapping(mapping):
216-
len(mapping)
217-
keys = mapping.keys()
218-
items = mapping.items()
219-
for key in keys:
220-
item = mapping[key]
221-
mapping["key"] = "value"
222-
self.assertEqual(mapping["key"], "value",
223-
msg="expected value string, got %r" % mapping["key"])
224-
225206
def check_element(element):
226207
self.assertTrue(ET.iselement(element), msg="not an element")
227208
direlem = dir(element)
@@ -231,12 +212,12 @@ def check_element(element):
231212
self.assertIn(attr, direlem,
232213
msg='no %s visible by dir' % attr)
233214

234-
check_string(element.tag)
235-
check_mapping(element.attrib)
215+
self.assertIsInstance(element.tag, str)
216+
self.assertIsInstance(element.attrib, dict)
236217
if element.text is not None:
237-
check_string(element.text)
218+
self.assertIsInstance(element.text, str)
238219
if element.tail is not None:
239-
check_string(element.tail)
220+
self.assertIsInstance(element.tail, str)
240221
for elem in element:
241222
check_element(elem)
242223

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.