[Python-checkins] CVS: python/dist/src/Lib/test test_gc.py,1.8,1.9
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 02 Oct 2001 12:49:49 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv8698
Modified Files:
test_gc.py
Log Message:
The error reporting here was a bit sparse. In verbose mode, the code
in run_test() referenced two non-existent variables, and in
non-verbose mode, the tests didn't report the actual number, when it
differed from the expected number. Fixed this.
Also added an extra call to gc.collect() at the start of test_all().
This will be needed when I check in the changes to add GC to new-style
classes.
Index: test_gc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_gc.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** test_gc.py 2001/07/12 13:25:53 1.8
--- test_gc.py 2001/10/02 19:49:47 1.9
***************
*** 3,19 ****
import gc
def run_test(name, thunk):
if verbose:
print "testing %s..." % name,
! try:
! thunk()
! except TestFailed:
! if verbose:
! print "failed (expected %s but got %s)" % (result,
! test_result)
! raise TestFailed, name
! else:
! if verbose:
! print "ok"
def test_list():
--- 3,21 ----
import gc
+ def expect(actual, expected, name):
+ if actual != expected:
+ raise TestFailed, "test_%s: actual %d, expected %d" % (
+ name, actual, expected)
+
+ def expect_not(actual, expected, name):
+ if actual == expected:
+ raise TestFailed, "test_%s: actual %d unexpected" % (name, actual)
+
def run_test(name, thunk):
if verbose:
print "testing %s..." % name,
! thunk()
! if verbose:
! print "ok"
def test_list():
***************
*** 22,27 ****
gc.collect()
del l
! if gc.collect() != 1:
! raise TestFailed
def test_dict():
--- 24,28 ----
gc.collect()
del l
! expect(gc.collect(), 1, "list")
def test_dict():
***************
*** 30,35 ****
gc.collect()
del d
! if gc.collect() != 1:
! raise TestFailed
def test_tuple():
--- 31,35 ----
gc.collect()
del d
! expect(gc.collect(), 1, "dict")
def test_tuple():
***************
*** 41,46 ****
del t
del l
! if gc.collect() != 2:
! raise TestFailed
def test_class():
--- 41,45 ----
del t
del l
! expect(gc.collect(), 2, "tuple")
def test_class():
***************
*** 50,55 ****
gc.collect()
del A
! if gc.collect() == 0:
! raise TestFailed
def test_instance():
--- 49,53 ----
gc.collect()
del A
! expect_not(gc.collect(), 0, "class")
def test_instance():
***************
*** 60,65 ****
gc.collect()
del a
! if gc.collect() == 0:
! raise TestFailed
def test_method():
--- 58,62 ----
gc.collect()
del a
! expect_not(gc.collect(), 0, "instance")
def test_method():
***************
*** 71,76 ****
gc.collect()
del a
! if gc.collect() == 0:
! raise TestFailed
def test_finalizer():
--- 68,72 ----
gc.collect()
del a
! expect_not(gc.collect(), 0, "method")
def test_finalizer():
***************
*** 89,94 ****
del a
del b
! if gc.collect() == 0:
! raise TestFailed
for obj in gc.garbage:
if id(obj) == id_a:
--- 85,89 ----
del a
del b
! expect_not(gc.collect(), 0, "finalizer")
for obj in gc.garbage:
if id(obj) == id_a:
***************
*** 96,100 ****
break
else:
! raise TestFailed
gc.garbage.remove(obj)
--- 91,95 ----
break
else:
! raise TestFailed, "didn't find obj in garbage (finalizer)"
gc.garbage.remove(obj)
***************
*** 106,111 ****
gc.collect()
del d
! if gc.collect() != 2:
! raise TestFailed
def test_frame():
--- 101,105 ----
gc.collect()
del d
! expect(gc.collect(), 2, "function")
def test_frame():
***************
*** 114,119 ****
gc.collect()
f()
! if gc.collect() != 1:
! raise TestFailed
--- 108,112 ----
gc.collect()
f()
! expect(gc.collect(), 1, "frame")
***************
*** 134,138 ****
break
else:
! raise TestFailed
gc.garbage.remove(obj)
finally:
--- 127,131 ----
break
else:
! raise TestFailed, "didn't find obj in garbage (saveall)"
gc.garbage.remove(obj)
finally:
***************
*** 156,159 ****
--- 149,153 ----
def test_all():
+ gc.collect() # Delete 2nd generation garbage
run_test("lists", test_list)
run_test("dicts", test_dict)