summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_copy.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-03-06 12:56:57 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-03-06 12:56:57 (GMT)
commit818e18dd94611a2f0f4b0015661488ef0cd867dc (patch)
treeb7a99bee9be1a86bd2d629f89564ce36066c2741 /Lib/test/test_copy.py
parentde128e19e2c6186408692a37f563550df13a390c (diff)
downloadcpython-818e18dd94611a2f0f4b0015661488ef0cd867dc.zip
cpython-818e18dd94611a2f0f4b0015661488ef0cd867dc.tar.gz
cpython-818e18dd94611a2f0f4b0015661488ef0cd867dc.tar.bz2
Issue #26167: Minimized overhead in copy.copy() and copy.deepcopy().
Optimized copying and deepcopying bytearrays, NotImplemented, slices, short lists, tuples, dicts, sets.
Diffstat (limited to 'Lib/test/test_copy.py')
-rw-r--r--Lib/test/test_copy.py55
1 files changed, 49 insertions, 6 deletions
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index 7912c7c..45a6920 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -95,24 +95,67 @@ class TestCopy(unittest.TestCase):
pass
class WithMetaclass(metaclass=abc.ABCMeta):
pass
- tests = [None, 42, 2**100, 3.14, True, False, 1j,
+ tests = [None, ..., NotImplemented,
+ 42, 2**100, 3.14, True, False, 1j,
"hello", "hello\u1234", f.__code__,
- b"world", bytes(range(256)),
- NewStyle, range(10), Classic, max, WithMetaclass]
+ b"world", bytes(range(256)), range(10), slice(1, 10, 2),
+ NewStyle, Classic, max, WithMetaclass]
for x in tests:
self.assertIs(copy.copy(x), x)
def test_copy_list(self):
x = [1, 2, 3]
- self.assertEqual(copy.copy(x), x)
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ x = []
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
def test_copy_tuple(self):
x = (1, 2, 3)
- self.assertEqual(copy.copy(x), x)
+ self.assertIs(copy.copy(x), x)
+ x = ()
+ self.assertIs(copy.copy(x), x)
+ x = (1, 2, 3, [])
+ self.assertIs(copy.copy(x), x)
def test_copy_dict(self):
x = {"foo": 1, "bar": 2}
- self.assertEqual(copy.copy(x), x)
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ x = {}
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+
+ def test_copy_set(self):
+ x = {1, 2, 3}
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ x = set()
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+
+ def test_copy_frozenset(self):
+ x = frozenset({1, 2, 3})
+ self.assertIs(copy.copy(x), x)
+ x = frozenset()
+ self.assertIs(copy.copy(x), x)
+
+ def test_copy_bytearray(self):
+ x = bytearray(b'abc')
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ x = bytearray()
+ y = copy.copy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
def test_copy_inst_vanilla(self):
class C: