Skip to content

Commit 4d05077

Browse files
committed
Update test_copy.py from CPython 3.11
1 parent 5b6a4c4 commit 4d05077

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

Lib/test/test_copy.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def pickle_C(obj):
5151
self.assertRaises(TypeError, copy.copy, x)
5252
copyreg.pickle(C, pickle_C, C)
5353
y = copy.copy(x)
54+
self.assertIsNot(x, y)
55+
self.assertEqual(type(y), C)
56+
self.assertEqual(y.foo, x.foo)
5457

5558
def test_copy_reduce_ex(self):
5659
class C(object):
@@ -315,6 +318,9 @@ def pickle_C(obj):
315318
self.assertRaises(TypeError, copy.deepcopy, x)
316319
copyreg.pickle(C, pickle_C, C)
317320
y = copy.deepcopy(x)
321+
self.assertIsNot(x, y)
322+
self.assertEqual(type(y), C)
323+
self.assertEqual(y.foo, x.foo)
318324

319325
def test_deepcopy_reduce_ex(self):
320326
class C(object):
@@ -351,17 +357,15 @@ def __getattribute__(self, name):
351357

352358
# Type-specific _deepcopy_xxx() methods
353359

354-
# TODO: RUSTPYTHON
355-
@unittest.expectedFailure
356360
def test_deepcopy_atomic(self):
357361
class Classic:
358362
pass
359363
class NewStyle(object):
360364
pass
361365
def f():
362366
pass
363-
tests = [None, 42, 2**100, 3.14, True, False, 1j,
364-
"hello", "hello\u1234", f.__code__,
367+
tests = [None, ..., NotImplemented, 42, 2**100, 3.14, True, False, 1j,
368+
b"bytes", "hello", "hello\u1234", f.__code__,
365369
NewStyle, range(10), Classic, max, property()]
366370
for x in tests:
367371
self.assertIs(copy.deepcopy(x), x)
@@ -684,6 +688,28 @@ def __eq__(self, other):
684688
self.assertIsNot(x, y)
685689
self.assertIsNot(x["foo"], y["foo"])
686690

691+
def test_reduce_6tuple(self):
692+
def state_setter(*args, **kwargs):
693+
self.fail("shouldn't call this")
694+
class C:
695+
def __reduce__(self):
696+
return C, (), self.__dict__, None, None, state_setter
697+
x = C()
698+
with self.assertRaises(TypeError):
699+
copy.copy(x)
700+
with self.assertRaises(TypeError):
701+
copy.deepcopy(x)
702+
703+
def test_reduce_6tuple_none(self):
704+
class C:
705+
def __reduce__(self):
706+
return C, (), self.__dict__, None, None, None
707+
x = C()
708+
with self.assertRaises(TypeError):
709+
copy.copy(x)
710+
with self.assertRaises(TypeError):
711+
copy.deepcopy(x)
712+
687713
def test_copy_slots(self):
688714
class C(object):
689715
__slots__ = ["foo"]

0 commit comments

Comments
 (0)