From: Alex Martelli Date: Mon, 7 Feb 2005 12:18:26 +0000 (+0000) Subject: sligtly strengthen unit tests for copy.py X-Git-Tag: v2.3.5~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3560fbd2acd1019db8e791515f9d1f8ae13d2a80;p=thirdparty%2FPython%2Fcpython.git sligtly strengthen unit tests for copy.py --- diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 8ad5c8511f32..e4b57add20c1 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -185,7 +185,33 @@ class TestCopy(unittest.TestCase): self.assert_(x is not y) self.assert_(x.tag is not y.tag) - # regression tests for metaclass-confusion + # regression tests for class-vs-instance and metaclass-confusion + def test_copy_classoverinstance(self): + class C(object): + def __init__(self, v): + self.v = v + def __cmp__(self, other): + return -cmp(other, self.v) + def __copy__(self): + return self.__class__(self.v) + x = C(23) + self.assertEqual(copy.copy(x), x) + x.__copy__ = lambda: 42 + self.assertEqual(copy.copy(x), x) + + def test_deepcopy_classoverinstance(self): + class C(object): + def __init__(self, v): + self.v = v + def __cmp__(self, other): + return -cmp(other, self.v) + def __deepcopy__(self, memo): + return self.__class__(copy.deepcopy(self.v, memo)) + x = C(23) + self.assertEqual(copy.deepcopy(x), x) + x.__deepcopy__ = lambda memo: 42 + self.assertEqual(copy.deepcopy(x), x) + def test_copy_metaclassconfusion(self): class MyOwnError(copy.Error): pass