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

Skip to content

Commit db26437

Browse files
authored
[3.11] gh-100871: Improve copy module tests (GH-100872) (#100976)
(cherry picked from commit 729ab9b) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent e8097d4 commit db26437

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):
@@ -313,6 +316,9 @@ def pickle_C(obj):
313316
self.assertRaises(TypeError, copy.deepcopy, x)
314317
copyreg.pickle(C, pickle_C, C)
315318
y = copy.deepcopy(x)
319+
self.assertIsNot(x, y)
320+
self.assertEqual(type(y), C)
321+
self.assertEqual(y.foo, x.foo)
316322

317323
def test_deepcopy_reduce_ex(self):
318324
class C(object):
@@ -356,8 +362,8 @@ class NewStyle(object):
356362
pass
357363
def f():
358364
pass
359-
tests = [None, 42, 2**100, 3.14, True, False, 1j,
360-
"hello", "hello\u1234", f.__code__,
365+
tests = [None, ..., NotImplemented, 42, 2**100, 3.14, True, False, 1j,
366+
b"bytes", "hello", "hello\u1234", f.__code__,
361367
NewStyle, range(10), Classic, max, property()]
362368
for x in tests:
363369
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
@@ -242,6 +243,41 @@ def test_pickle(self):
242243
self.assertEqual(s.indices(15), t.indices(15))
243244
self.assertNotEqual(id(s), id(t))
244245

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

0 commit comments

Comments
 (0)
0