[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.109,1.110
Guido van Rossum
gvanrossum@users.sourceforge.net
Wed, 05 Dec 2001 14:45:50 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv5060/Lib/test
Modified Files:
test_descr.py
Log Message:
Fix SF bug #489581: __slots__ leak.
It was easier than I thought, assuming that no other things contribute
to the instance size besides slots -- a pretty good bet. With a test
suite, no less!
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.109
retrieving revision 1.110
diff -C2 -d -r1.109 -r1.110
*** test_descr.py 2001/12/05 19:46:42 1.109
--- test_descr.py 2001/12/05 22:45:48 1.110
***************
*** 1001,1004 ****
--- 1001,1038 ----
vereq(x.c, 3)
+ # Test leaks
+ class Counted(object):
+ counter = 0 # counts the number of instances alive
+ def __init__(self):
+ Counted.counter += 1
+ def __del__(self):
+ Counted.counter -= 1
+ class C(object):
+ __slots__ = ['a', 'b', 'c']
+ x = C()
+ x.a = Counted()
+ x.b = Counted()
+ x.c = Counted()
+ vereq(Counted.counter, 3)
+ del x
+ vereq(Counted.counter, 0)
+ class D(C):
+ pass
+ x = D()
+ x.a = Counted()
+ x.z = Counted()
+ vereq(Counted.counter, 2)
+ del x
+ vereq(Counted.counter, 0)
+ class E(D):
+ __slots__ = ['e']
+ x = E()
+ x.a = Counted()
+ x.z = Counted()
+ x.e = Counted()
+ vereq(Counted.counter, 3)
+ del x
+ vereq(Counted.counter, 0)
+
def dynamics():
if verbose: print "Testing class attribute propagation..."