File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments