Skip to content

Commit 97d5fa0

Browse files
committed
Tests for _setroot
Split tests for _setroot into their own function and remove test for element-like objects per feedback from @serhiy-storchaka
1 parent 7c3a3b2 commit 97d5fa0

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Lib/test/test_xml_etree.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,24 @@ def test_constructor(self):
226226
with self.assertRaises(TypeError):
227227
tree = ET.ElementTree(ET.ElementTree())
228228

229-
# Test _setroot as well, since it also sets the _root object.
229+
def test_setroot(self):
230+
# Test _setroot behavior.
231+
232+
tree = ET.ElementTree()
233+
element = ET.Element("tag")
234+
tree._setroot(element)
235+
self.assertEqual(tree.getroot().tag, "tag")
236+
self.assertEqual(tree.getroot(), element)
237+
238+
# Test behavior with an invalid root element
230239

231240
tree = ET.ElementTree()
232241
with self.assertRaises(TypeError):
233242
tree._setroot("")
234243
with self.assertRaises(TypeError):
235244
tree._setroot(ET.ElementTree())
236-
237-
# Make sure it accepts an Element-like object.
238-
239-
class ElementLike:
240-
def __init__(self):
241-
self.tag = "tag"
242-
243-
element_like = ElementLike()
244-
try:
245-
tree = ET.ElementTree(element_like)
246-
except Exception as err:
247-
self.fail(err)
245+
with self.assertRaises(TypeError):
246+
tree._setroot(None)
248247

249248
def test_interface(self):
250249
# Test element tree interface.

0 commit comments

Comments
 (0)