(original) (raw)
changeset: 100427:52d7a308e3b4 branch: 3.5 parent: 100424:dfef42311c71 user: Serhiy Storchaka storchaka@gmail.com date: Sun Mar 06 15:03:07 2016 +0200 files: Lib/test/test_copy.py description: Issue #26167: Backported copy tests. diff -r dfef42311c71 -r 52d7a308e3b4 Lib/test/test_copy.py --- a/Lib/test/test_copy.py Sun Mar 06 14:10:24 2016 +0200 +++ b/Lib/test/test_copy.py Sun Mar 06 15:03:07 2016 +0200 @@ -95,24 +95,67 @@ 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), + 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: /storchaka@gmail.com