[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.76,1.77

Guido van Rossum gvanrossum@users.sourceforge.net
2001年9月28日 11:13:31 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv22311/Lib/test
Modified Files:
	test_descr.py 
Log Message:
Changes to copy() and deepcopy() in copy.py to support __reduce__ as a
fallback for objects that are neither supported by our dispatch table
nor have a __copy__ or __deepcopy__ method.
Changes to _reduce() in copy_reg.py to support reducing objects that
don't have a __dict__ -- copy.copy(complex()) now invokes _reduce().
Add tests for copy.copy() and copy.deepcopy() to test_regrtest.py.
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.76
retrieving revision 1.77
diff -C2 -d -r1.76 -r1.77
*** test_descr.py	2001年09月25日 16:25:58	1.76
--- test_descr.py	2001年09月28日 18:13:29	1.77
***************
*** 2034,2038 ****
 
 def pickles():
! if verbose: print "Testing pickling new-style classes and objects..."
 import pickle, cPickle
 
--- 2034,2039 ----
 
 def pickles():
! if verbose:
! print "Testing pickling and copying new-style classes and objects..."
 import pickle, cPickle
 
***************
*** 2093,2097 ****
--- 2094,2138 ----
 print "b = y =", b
 
+ # Testing copy.deepcopy()
+ import copy
+ for cls in C, C1, C2:
+ cls2 = copy.deepcopy(cls)
+ verify(cls2 is cls)
+ 
+ a = C1(1, 2); a.append(42); a.append(24)
+ b = C2("hello", "world", 42)
+ x, y = copy.deepcopy((a, b))
+ assert x.__class__ == a.__class__
+ assert sorteditems(x.__dict__) == sorteditems(a.__dict__)
+ assert y.__class__ == b.__class__
+ assert sorteditems(y.__dict__) == sorteditems(b.__dict__)
+ assert `x` == `a`
+ assert `y` == `b`
+ if verbose:
+ print "a = x =", a
+ print "b = y =", b
+ 
+ def copies():
+ if verbose: print "Testing copy.copy() and copy.deepcopy()..."
+ import copy
+ class C(object):
+ pass
+ 
+ a = C()
+ a.foo = 12
+ b = copy.copy(a)
+ verify(b.__dict__ == a.__dict__)
+ 
+ a.bar = [1,2,3]
+ c = copy.copy(a)
+ verify(c.bar == a.bar)
+ verify(c.bar is a.bar)
 
+ d = copy.deepcopy(a)
+ verify(d.__dict__ == a.__dict__)
+ a.bar.append(4)
+ verify(d.bar == [1,2,3])
+ 
+ 
 def test_main():
 lists()
***************
*** 2137,2140 ****
--- 2178,2182 ----
 setclass()
 pickles()
+ copies()
 if verbose: print "All OK"
 

AltStyle によって変換されたページ (->オリジナル) /