[Python-checkins] python/dist/src/Lib/test test_copy.py,1.1,1.2

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Thu, 06 Feb 2003 10:18:26 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv827/test

Modified Files:
	test_copy.py 
Log Message:
Support __reduce__ returning a 4-tuple or 5-tuple.


Index: test_copy.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_copy.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_copy.py	6 Feb 2003 17:52:15 -0000	1.1
--- test_copy.py	6 Feb 2003 18:18:23 -0000	1.2
***************
*** 376,379 ****
--- 376,415 ----
          self.assert_(y.foo is not x.foo)
  
+     # Additions for Python 2.3 and pickle protocol 2
+ 
+     def test_reduce_4tuple(self):
+         class C(list):
+             def __reduce__(self):
+                 return (C, (), self.__dict__, iter(self))
+             def __cmp__(self, other):
+                 return (cmp(list(self), list(other)) or
+                         cmp(self.__dict__, other.__dict__))
+         x = C([[1, 2], 3])
+         y = copy.copy(x)
+         self.assertEqual(x, y)
+         self.assert_(x is not y)
+         self.assert_(x[0] is y[0])
+         y = copy.deepcopy(x)
+         self.assertEqual(x, y)
+         self.assert_(x is not y)
+         self.assert_(x[0] is not y[0])
+ 
+     def test_reduce_5tuple(self):
+         class C(dict):
+             def __reduce__(self):
+                 return (C, (), self.__dict__, None, self.iteritems())
+             def __cmp__(self, other):
+                 return (cmp(dict(self), list(dict)) or
+                         cmp(self.__dict__, other.__dict__))
+         x = C([("foo", [1, 2]), ("bar", 3)])
+         y = copy.copy(x)
+         self.assertEqual(x, y)
+         self.assert_(x is not y)
+         self.assert_(x["foo"] is y["foo"])
+         y = copy.deepcopy(x)
+         self.assertEqual(x, y)
+         self.assert_(x is not y)
+         self.assert_(x["foo"] is not y["foo"])
+ 
  def test_main():
      suite = unittest.TestSuite()