summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorBar Harel <bzvi7919@gmail.com>2019-05-19 13:57:13 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2019-05-19 13:57:13 (GMT)
commitf4e1babf44792bdeb0c01da96821ba0800a51fd8 (patch)
treebc551ef155b52026cee8408766e7259f06024b45 /Lib/test/test_collections.py
parentc661b30f89ffe7a7995538d3b1649469b184bee4 (diff)
downloadcpython-f4e1babf44792bdeb0c01da96821ba0800a51fd8.zip
cpython-f4e1babf44792bdeb0c01da96821ba0800a51fd8.tar.gz
cpython-f4e1babf44792bdeb0c01da96821ba0800a51fd8.tar.bz2
bpo-27141: Fix collections.UserList and UserDict shallow copy. (GH-4094)
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r--Lib/test/test_collections.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 1f619bc..e2d04d5 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -37,6 +37,20 @@ class TestUserObjects(unittest.TestCase):
b=b.__name__,
),
)
+
+ def _copy_test(self, obj):
+ # Test internal copy
+ obj_copy = obj.copy()
+ self.assertIsNot(obj.data, obj_copy.data)
+ self.assertEqual(obj.data, obj_copy.data)
+
+ # Test copy.copy
+ obj.test = [1234] # Make sure instance vars are also copied.
+ obj_copy = copy.copy(obj)
+ self.assertIsNot(obj.data, obj_copy.data)
+ self.assertEqual(obj.data, obj_copy.data)
+ self.assertIs(obj.test, obj_copy.test)
+
def test_str_protocol(self):
self._superset_test(UserString, str)
@@ -46,6 +60,16 @@ class TestUserObjects(unittest.TestCase):
def test_dict_protocol(self):
self._superset_test(UserDict, dict)
+ def test_list_copy(self):
+ obj = UserList()
+ obj.append(123)
+ self._copy_test(obj)
+
+ def test_dict_copy(self):
+ obj = UserDict()
+ obj[123] = "abc"
+ self._copy_test(obj)
+
################################################################################
### ChainMap (helper class for configparser and the string module)