summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_copy.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-19 01:19:28 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-19 01:19:28 (GMT)
commite690883ccf8081e5baab0e9d71f596f26245b569 (patch)
tree57c21839dbb39b03056f9d19c9c054fbb060900f /Lib/test/test_copy.py
parenta43fd0c8996eec2bdd0ec59edc252cb4f4ff4436 (diff)
downloadcpython-e690883ccf8081e5baab0e9d71f596f26245b569.zip
cpython-e690883ccf8081e5baab0e9d71f596f26245b569.tar.gz
cpython-e690883ccf8081e5baab0e9d71f596f26245b569.tar.bz2
Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Diffstat (limited to 'Lib/test/test_copy.py')
-rw-r--r--Lib/test/test_copy.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index 6a31f75..cde545d 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -46,6 +46,16 @@ class TestCopy(unittest.TestCase):
copy_reg.pickle(C, pickle_C, C)
y = copy.copy(x)
+ def test_copy_reduce_ex(self):
+ class C(object):
+ def __reduce_ex__(self, proto):
+ return ""
+ def __reduce__(self):
+ raise test_support.TestFailed, "shouldn't call this"
+ x = C()
+ y = copy.copy(x)
+ self.assert_(y is x)
+
def test_copy_reduce(self):
class C(object):
def __reduce__(self):
@@ -55,13 +65,11 @@ class TestCopy(unittest.TestCase):
self.assert_(y is x)
def test_copy_cant(self):
- class Meta(type):
+ class C(object):
def __getattribute__(self, name):
- if name == "__reduce__":
+ if name.startswith("__reduce"):
raise AttributeError, name
return object.__getattribute__(self, name)
- class C:
- __metaclass__ = Meta
x = C()
self.assertRaises(copy.Error, copy.copy, x)
@@ -209,6 +217,16 @@ class TestCopy(unittest.TestCase):
copy_reg.pickle(C, pickle_C, C)
y = copy.deepcopy(x)
+ def test_deepcopy_reduce_ex(self):
+ class C(object):
+ def __reduce_ex__(self, proto):
+ return ""
+ def __reduce__(self):
+ raise test_support.TestFailed, "shouldn't call this"
+ x = C()
+ y = copy.deepcopy(x)
+ self.assert_(y is x)
+
def test_deepcopy_reduce(self):
class C(object):
def __reduce__(self):
@@ -218,13 +236,11 @@ class TestCopy(unittest.TestCase):
self.assert_(y is x)
def test_deepcopy_cant(self):
- class Meta(type):
+ class C(object):
def __getattribute__(self, name):
- if name == "__reduce__":
+ if name.startswith("__reduce"):
raise AttributeError, name
return object.__getattribute__(self, name)
- class C:
- __metaclass__ = Meta
x = C()
self.assertRaises(copy.Error, copy.deepcopy, x)