@@ -311,7 +311,12 @@ def test_spam_lists(self):
311311 # Testing spamlist operations...
312312 import copy , xxsubtype as spam
313313
314- spamlist = spam .spamlist
314+ def spamlist (l , memo = None ):
315+ import xxsubtype as spam
316+ return spam .spamlist (l )
317+
318+ # This is an ugly hack:
319+ copy ._deepcopy_dispatch [spam .spamlist ] = spamlist
315320
316321 self .binop_test (spamlist ([1 ]), spamlist ([2 ]), spamlist ([1 ,2 ]), "a+b" ,
317322 "__add__" )
@@ -345,22 +350,19 @@ def foo(self): return 1
345350 a .setstate (42 )
346351 self .assertEqual (a .getstate (), 42 )
347352
348- # test deepcopy makes a deep copy of the elements of a spamlist
349- a .append ([])
350- a_copy = copy .deepcopy (a )
351- assert a_copy is not a
352- assert a_copy [- 1 ] is not a [- 1 ]
353- assert a_copy == a
354- # the spamlist does not explictly implement deepcopy, the state is not copied
355- assert a_copy .getstate () != a .getstate ()
356-
357353 @support .impl_detail ("the module 'xxsubtype' is internal" )
358354 @unittest .skipIf (xxsubtype is None , "requires xxsubtype module" )
359355 def test_spam_dicts (self ):
360356 # Testing spamdict operations...
361357 import copy , xxsubtype as spam
362-
363- spamdict = spam .spamdict
358+ def spamdict (d , memo = None ):
359+ import xxsubtype as spam
360+ sd = spam .spamdict ()
361+ for k , v in list (d .items ()):
362+ sd [k ] = v
363+ return sd
364+ # This is an ugly hack:
365+ copy ._deepcopy_dispatch [spam .spamdict ] = spamdict
364366
365367 self .binop_test (spamdict ({1 :2 ,3 :4 }), 1 , 1 , "b in a" , "__contains__" )
366368 self .binop_test (spamdict ({1 :2 ,3 :4 }), 2 , 0 , "b in a" , "__contains__" )
@@ -399,15 +401,6 @@ def foo(self): return 1
399401 a .setstate (100 )
400402 self .assertEqual (a .getstate (), 100 )
401403
402- # test deepcopy makes a deep copy of the elements of a spamdict
403- a [- 1 ] = []
404- a_copy = copy .deepcopy (a )
405- assert a_copy is not a
406- assert a_copy [- 1 ] is not a [- 1 ]
407- assert a_copy == a
408- # the spamdict does not explictly implement deepcopy, the state is not copied
409- assert a_copy .getstate () != a .getstate ()
410-
411404 def test_wrap_lenfunc_bad_cast (self ):
412405 self .assertEqual (range (sys .maxsize ).__len__ (), sys .maxsize )
413406
0 commit comments