[Python-checkins] python/dist/src/Lib/test test_descr.py,1.154,1.155

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
2002年8月13日 11:26:29 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv1483
Modified Files:
	test_descr.py 
Log Message:
Add tests for including __dict__ and/or __weakref__ in __slots__.
Add some more rigor to slotmultipleinheritance().
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.154
retrieving revision 1.155
diff -C2 -d -r1.154 -r1.155
*** test_descr.py	13 Aug 2002 17:16:49 -0000	1.154
--- test_descr.py	13 Aug 2002 18:26:26 -0000	1.155
***************
*** 1176,1179 ****
--- 1176,1224 ----
 vereq(orig_objects, new_objects)
 
+ def slotspecials():
+ if verbose: print "Testing __dict__ and __weakref__ in __slots__..."
+ 
+ class D(object):
+ __slots__ = ["__dict__"]
+ a = D()
+ verify(hasattr(a, "__dict__"))
+ verify(not hasattr(a, "__weakref__"))
+ a.foo = 42
+ vereq(a.__dict__, {"foo": 42})
+ 
+ class W(object):
+ __slots__ = ["__weakref__"]
+ a = W()
+ verify(hasattr(a, "__weakref__"))
+ verify(not hasattr(a, "__dict__"))
+ try:
+ a.foo = 42
+ except AttributeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't be allowed to set a.foo"
+ 
+ class C1(W, D):
+ __slots__ = []
+ a = C1()
+ verify(hasattr(a, "__dict__"))
+ verify(hasattr(a, "__weakref__"))
+ a.foo = 42
+ vereq(a.__dict__, {"foo": 42})
+ 
+ class C2(D, W):
+ __slots__ = []
+ a = C2()
+ verify(hasattr(a, "__dict__"))
+ verify(hasattr(a, "__weakref__"))
+ a.foo = 42
+ vereq(a.__dict__, {"foo": 42})
+ 
+ class C3(C1, C2):
+ __slots__ = []
+ 
+ class C4(C2, C1):
+ __slots__ = []
+ 
 def dynamics():
 if verbose: print "Testing class attribute propagation..."
***************
*** 3246,3250 ****
 class C(A,B) :
 __slots__=()
! C().x=2
 
 def testrmul():
--- 3291,3298 ----
 class C(A,B) :
 __slots__=()
! vereq(C.__basicsize__, B.__basicsize__)
! verify(hasattr(C, '__dict__'))
! verify(hasattr(C, '__weakref__'))
! C().x = 2
 
 def testrmul():
***************
*** 3305,3308 ****
--- 3353,3357 ----
 objects()
 slots()
+ slotspecials()
 dynamics()
 errors()

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