[Python-checkins] python/dist/src/Lib/test test_copy.py,1.4,1.5

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Fri, 07 Feb 2003 09:30:23 -0800


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

Modified Files:
	test_copy.py 
Log Message:
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.


Index: test_copy.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_copy.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_copy.py	6 Feb 2003 21:25:12 -0000	1.4
--- test_copy.py	7 Feb 2003 17:30:18 -0000	1.5
***************
*** 3,6 ****
--- 3,7 ----
  import sys
  import copy
+ import copy_reg
  
  import unittest
***************
*** 33,36 ****
--- 34,50 ----
          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):
***************
*** 182,185 ****
--- 196,212 ----
          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):