[Python-checkins] gh-100871: Improve `copy` module tests (GH-100872)
miss-islington
webhook-mailer at python.org
Wed Jan 11 12:15:15 EST 2023
https://github.com/python/cpython/commit/729ab9b622957fef0e9b494af9a71ab02986c741
commit: 729ab9b622957fef0e9b494af9a71ab02986c741
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2023-01-11T09:14:41-08:00
summary:
gh-100871: Improve `copy` module tests (GH-100872)
CC @AlexWaygood as the reviewer of https://github.com/python/cpython/pull/100818
Automerge-Triggered-By: GH:AlexWaygood
files:
M Lib/test/test_copy.py
M Lib/test/test_slice.py
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index cc95a319d35d..826e46824e00 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -51,6 +51,9 @@ def pickle_C(obj):
self.assertRaises(TypeError, copy.copy, x)
copyreg.pickle(C, pickle_C, C)
y = copy.copy(x)
+ self.assertIsNot(x, y)
+ self.assertEqual(type(y), C)
+ self.assertEqual(y.foo, x.foo)
def test_copy_reduce_ex(self):
class C(object):
@@ -311,6 +314,9 @@ def pickle_C(obj):
self.assertRaises(TypeError, copy.deepcopy, x)
copyreg.pickle(C, pickle_C, C)
y = copy.deepcopy(x)
+ self.assertIsNot(x, y)
+ self.assertEqual(type(y), C)
+ self.assertEqual(y.foo, x.foo)
def test_deepcopy_reduce_ex(self):
class C(object):
@@ -352,8 +358,8 @@ class NewStyle:
pass
def f():
pass
- tests = [None, 42, 2**100, 3.14, True, False, 1j,
- "hello", "hello\u1234", f.__code__,
+ tests = [None, ..., NotImplemented, 42, 2**100, 3.14, True, False, 1j,
+ b"bytes", "hello", "hello\u1234", f.__code__,
NewStyle, range(10), max, property()]
for x in tests:
self.assertIs(copy.deepcopy(x), x)
diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py
index c4bc8c82023d..03fde3275e14 100644
--- a/Lib/test/test_slice.py
+++ b/Lib/test/test_slice.py
@@ -5,6 +5,7 @@
import sys
import unittest
import weakref
+import copy
from pickle import loads, dumps
from test import support
@@ -244,6 +245,41 @@ def test_pickle(self):
self.assertEqual(s.indices(15), t.indices(15))
self.assertNotEqual(id(s), id(t))
+ def test_copy(self):
+ s = slice(1, 10)
+ c = copy.copy(s)
+ self.assertIs(s, c)
+
+ s = slice(1, 10, 2)
+ c = copy.copy(s)
+ self.assertIs(s, c)
+
+ # Corner case for mutable indices:
+ s = slice([1, 2], [3, 4], [5, 6])
+ c = copy.copy(s)
+ self.assertIs(s, c)
+ self.assertIs(s.start, c.start)
+ self.assertIs(s.stop, c.stop)
+ self.assertIs(s.step, c.step)
+
+ def test_deepcopy(self):
+ s = slice(1, 10)
+ c = copy.deepcopy(s)
+ self.assertEqual(s, c)
+
+ s = slice(1, 10, 2)
+ c = copy.deepcopy(s)
+ self.assertEqual(s, c)
+
+ # Corner case for mutable indices:
+ s = slice([1, 2], [3, 4], [5, 6])
+ c = copy.deepcopy(s)
+ self.assertIsNot(s, c)
+ self.assertEqual(s, c)
+ self.assertIsNot(s.start, c.start)
+ self.assertIsNot(s.stop, c.stop)
+ self.assertIsNot(s.step, c.step)
+
def test_cycle(self):
class myobj(): pass
o = myobj()
More information about the Python-checkins
mailing list