[Python-checkins] python/dist/src/Lib/test test_copy.py, 1.11.8.2, 1.11.8.3

aleax at users.sourceforge.net aleax at users.sourceforge.net
Mon Feb 7 13:18:29 CET 2005


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31915

Modified Files:
      Tag: release23-maint
	test_copy.py 
Log Message:
sligtly strengthen unit tests for copy.py

Index: test_copy.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_copy.py,v
retrieving revision 1.11.8.2
retrieving revision 1.11.8.3
diff -u -d -r1.11.8.2 -r1.11.8.3
--- test_copy.py	6 Feb 2005 07:56:18 -0000	1.11.8.2
+++ test_copy.py	7 Feb 2005 12:18:26 -0000	1.11.8.3
@@ -185,7 +185,33 @@
         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



More information about the Python-checkins mailing list