[Python-checkins] CVS: python/dist/src/Lib/test test_gc.py,1.3,1.4
Neil Schemenauer
python-dev@python.org
Fri, 15 Sep 2000 15:32:33 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv16973/Lib/test
Modified Files:
test_gc.py
Log Message:
- add a new test
- document some of the tricky tests (hopefully correctly :)
Index: test_gc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_gc.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** test_gc.py 2000/08/06 22:45:31 1.3
--- test_gc.py 2000/09/15 22:32:29 1.4
***************
*** 16,19 ****
--- 16,20 ----
def test_tuple():
+ # since tuples are immutable we close the loop with a list
l = []
t = (l,)
***************
*** 42,45 ****
--- 43,47 ----
def test_method():
+ # Tricky: self.__init__ is a bound method, it references the instance.
class A:
def __init__(self):
***************
*** 51,54 ****
--- 53,58 ----
def test_finalizer():
+ # A() is uncollectable if it is part of a cycle, make sure it shows up
+ # in gc.garbage.
class A:
def __del__(self): pass
***************
*** 68,71 ****
--- 72,77 ----
def test_function():
+ # Tricky: f -> d -> f, code should call d.clear() after the exec to
+ # break the cycle.
d = {}
exec("def f(): pass\n") in d
***************
*** 74,77 ****
--- 80,98 ----
assert gc.collect() == 2
+ def test_del():
+ # __del__ methods can trigger collection, make this to happen
+ thresholds = gc.get_threshold()
+ gc.enable()
+ gc.set_threshold(1)
+
+ class A:
+ def __del__(self):
+ dir(self)
+ a = A()
+ del a
+
+ gc.disable()
+ apply(gc.set_threshold, thresholds)
+
def test_all():
***************
*** 89,92 ****
--- 110,114 ----
test_finalizer()
test_function()
+ test_del()
# test gc.enable() even if GC is disabled by default