8000 gh-100871: Improve `copy` module tests (GH-100872) · python/cpython@729ab9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 729ab9b

Browse files
authored
gh-100871: Improve copy module tests (GH-100872)
CC @AlexWaygood as the reviewer of #100818 Automerge-Triggered-By: GH:AlexWaygood
1 parent 762745a commit 729ab9b

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Lib/test/test_copy.py

Lines changed: 8 additions & 2 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):
@@ -311,6 +314,9 @@ def pickle_C(obj):
311314
self.assertRaises(TypeError, copy.deepcopy, x)
312315
copyreg.pickle(C, pickle_C, C)
313316
y = copy.deepcopy(x)
317+
self.assertIsNot(x, y)
318+
self.assertEqual(type(y), C)
319+
self.assertEqual(y.foo, x.foo)
314320

315321
def test_deepcopy_reduce_ex(self):
316322
class C(object):
@@ -352,8 +358,8 @@ class NewStyle:
352358
pass
353359
def f():
354360
pass
355-
tests = [None, 42, 2**100, 3.14, True, False, 1j,
356-
"hello", "hello\u1234", f.__code__,
361+
tests = [None, ..., NotImplemented, 42, 2**100, 3.14, True, False, 1j,
362+
b"bytes", "hello", "hello\u1234", f.__code__,
357363
NewStyle, range(10), max, property()]
358364
for x in tests:
359365
self.assertIs(copy.deepcopy(x), x)

Lib/test/test_slice.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import unittest
77
import weakref
8+
import copy
89

910
from pickle import loads, dumps
1011
from test import support
@@ -244,6 +245,41 @@ def test_pickle(self):
244245
self.assertEqual(s.indices(15), t.indices(15))
245246
self.assertNotEqual(id(s), id(t))
246247

248+
def test_copy(self):
249+
s = slice(1, 10)
250+
c = copy.copy(s)
251+
self.assertIs(s, c)
252+
253+
s = slice(1, 10, 2)
254+
c = copy.copy(s)
255+
self.assertIs(s, c)
256+
257+
# Corner case for mutable indices:
258+
s = slice([1, 2], [3, 4], [5, 6])
259+
c = copy.copy(s)
260+
self.assertIs(s, c)
261+
self.assertIs(s.start, c.start)
262+
self.assertIs(s.stop, c.stop)
263+
self.assertIs(s.step, c.step)
264+
265+
def test_deepcopy(self):
266+
s = slice(1, 10)
267+
c = copy.deepcopy(s)
268+
self.assertEqual(s, c)
269+
270+
s = slice(1, 10, 2)
271+
c = copy.deepcopy(s)
272+
self.assertEqual(s, c)
273+
274+
# Corner case for mutable indices:
275+
s = slice([1, 2], [3, 4], [5, 6])
276+
c = copy.deepcopy(s)
277+
self.assertIsNot(s, c)
278+
self.assertEqual(s, c)
279+
self.assertIsNot(s.start, c.start)
280+
self.assertIsNot(s.stop, c.stop)
281+
self.assertIsNot(s.step, c.step)
282+
247283
def test_cycle(self):
248284
class myobj(): pass
249285
o = myobj()

0 commit comments

Comments
 (0)
0