Skip to content

Commit d3ee7d1

Browse files
committed
adjust tests
1 parent d2fbcd8 commit d3ee7d1

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

Lib/test/test_descr.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,7 @@ def test_spam_lists(self):
311311
# Testing spamlist operations...
312312
import copy, xxsubtype as spam
313313

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
314+
spamlist = spam.spamlist
320315

321316
self.binop_test(spamlist([1]), spamlist([2]), spamlist([1,2]), "a+b",
322317
"__add__")
@@ -350,19 +345,22 @@ def foo(self): return 1
350345
a.setstate(42)
351346
self.assertEqual(a.getstate(), 42)
352347

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+
353357
@support.impl_detail("the module 'xxsubtype' is internal")
354358
@unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
355359
def test_spam_dicts(self):
356360
# Testing spamdict operations...
357361
import copy, xxsubtype as spam
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
362+
363+
spamdict = spam.spamdict
366364

367365
self.binop_test(spamdict({1:2,3:4}), 1, 1, "b in a", "__contains__")
368366
self.binop_test(spamdict({1:2,3:4}), 2, 0, "b in a", "__contains__")
@@ -375,7 +373,9 @@ def spamdict(d, memo=None):
375373
for i in iter(d):
376374
l.append(i)
377375
self.assertEqual(l, l1)
376+
378377
l = []
378+
379379
for i in d.__iter__():
380380
l.append(i)
381381
self.assertEqual(l, l1)
@@ -389,6 +389,7 @@ def spamdict(d, memo=None):
389389
self.unop_test(spamd, repr(straightd), "repr(a)", "__repr__")
390390
self.set2op_test(spamdict({1:2,3:4}), 2, 3, spamdict({1:2,2:3,3:4}),
391391
"a[b]=c", "__setitem__")
392+
392393
# Test subclassing
393394
class C(spam.spamdict):
394395
def foo(self): return 1
@@ -401,6 +402,15 @@ def foo(self): return 1
401402
a.setstate(100)
402403
self.assertEqual(a.getstate(), 100)
403404

405+
# test deepcopy makes a deep copy of the elements of a spamdict
406+
a[-1] = []
407+
a_copy = copy.deepcopy(a)
408+
assert a_copy is not a
409+
assert a_copy[-1] is not a[-1]
410+
assert a_copy == a
411+
# the spamdict does not explictly implement deepcopy, the state is not copied
412+
assert a_copy.getstate() != a.getstate()
413+
404414
def test_wrap_lenfunc_bad_cast(self):
405415
self.assertEqual(range(sys.maxsize).__len__(), sys.maxsize)
406416

0 commit comments

Comments
 (0)