@@ -2211,6 +2211,35 @@ def test___init__(self):
22112211 self .assertIsNot (element_foo .attrib , attrib )
22122212 self .assertNotEqual (element_foo .attrib , attrib )
22132213
2214+ def test_copy (self ):
2215+ # Only run this test if Element.copy() is defined.
2216+ if "copy" not in dir (ET .Element ):
2217+ raise unittest .SkipTest ("Element.copy() not present" )
2218+
2219+ element_foo = ET .Element ("foo" , { "zix" : "wyp" })
2220+ element_foo .append (ET .Element ("bar" , { "baz" : "qix" }))
2221+
2222+ with self .assertWarns (DeprecationWarning ):
2223+ element_foo2 = element_foo .copy ()
2224+
2225+ # elements are not the same
2226+ self .assertIsNot (element_foo2 , element_foo )
2227+
2228+ # string attributes are equal
2229+ self .assertEqual (element_foo2 .tag , element_foo .tag )
2230+ self .assertEqual (element_foo2 .text , element_foo .text )
2231+ self .assertEqual (element_foo2 .tail , element_foo .tail )
2232+
2233+ # number of children is the same
2234+ self .assertEqual (len (element_foo2 ), len (element_foo ))
2235+
2236+ # children are the same
2237+ for (child1 , child2 ) in itertools .zip_longest (element_foo , element_foo2 ):
2238+ self .assertIs (child1 , child2 )
2239+
2240+ # attrib is a copy
2241+ self .assertEqual (element_foo2 .attrib , element_foo .attrib )
2242+
22142243 def test___copy__ (self ):
22152244 element_foo = ET .Element ("foo" , { "zix" : "wyp" })
22162245 element_foo .append (ET .Element ("bar" , { "baz" : "qix" }))
0 commit comments