diff options
author | Guido van Rossum <guido@python.org> | 2003-02-07 17:30:18 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-02-07 17:30:18 (GMT) |
commit | c06e3acc735a6e9cf28d0f511493bcfd8829117d (patch) | |
tree | ef2384f941d942527cef0f87e2307d28c42b4382 /Lib/test/test_copy.py | |
parent | 2731c5cf460778f02c5e713f6fff25cbbebedd37 (diff) | |
download | cpython-c06e3acc735a6e9cf28d0f511493bcfd8829117d.zip cpython-c06e3acc735a6e9cf28d0f511493bcfd8829117d.tar.gz cpython-c06e3acc735a6e9cf28d0f511493bcfd8829117d.tar.bz2 |
Add support for copy_reg.dispatch_table.
Rewrote copy() and deepcopy() without avoidable try/except statements;
getattr(x, name, None) or dict.get() are much faster than try/except.
Diffstat (limited to 'Lib/test/test_copy.py')
-rw-r--r-- | Lib/test/test_copy.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index c97d54d..35ce46a 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -2,6 +2,7 @@ import sys import copy +import copy_reg import unittest from test import test_support @@ -32,6 +33,19 @@ class TestCopy(unittest.TestCase): self.assertEqual(y.__class__, x.__class__) self.assertEqual(y.foo, x.foo) + def test_copy_registry(self): + class C(object): + def __new__(cls, foo): + obj = object.__new__(cls) + obj.foo = foo + return obj + def pickle_C(obj): + return (C, (obj.foo,)) + x = C(42) + self.assertRaises(TypeError, copy.copy, x) + copy_reg.pickle(C, pickle_C, C) + y = copy.copy(x) + def test_copy_reduce(self): class C(object): def __reduce__(self): @@ -182,6 +196,19 @@ class TestCopy(unittest.TestCase): self.assertEqual(y.__class__, x.__class__) self.assertEqual(y.foo, x.foo) + def test_deepcopy_registry(self): + class C(object): + def __new__(cls, foo): + obj = object.__new__(cls) + obj.foo = foo + return obj + def pickle_C(obj): + return (C, (obj.foo,)) + x = C(42) + self.assertRaises(TypeError, copy.deepcopy, x) + copy_reg.pickle(C, pickle_C, C) + y = copy.deepcopy(x) + def test_deepcopy_reduce(self): class C(object): def __reduce__(self): |