From: <pj...@us...> - 2009-06-01 04:38:00
|
Revision: 6436 http://jython.svn.sourceforge.net/jython/?rev=6436&view=rev Author: pjenvey Date: 2009-06-01 04:37:42 +0000 (Mon, 01 Jun 2009) Log Message: ----------- change our extra_collect into the 2.7/3.1 style test_support.gc_collect Modified Paths: -------------- trunk/jython/Lib/test/test_array.py trunk/jython/Lib/test/test_class.py trunk/jython/Lib/test/test_deque.py trunk/jython/Lib/test/test_descr.py trunk/jython/Lib/test/test_file.py trunk/jython/Lib/test/test_functools.py trunk/jython/Lib/test/test_generators.py trunk/jython/Lib/test/test_iter.py trunk/jython/Lib/test/test_scope.py trunk/jython/Lib/test/test_set.py trunk/jython/Lib/test/test_support.py trunk/jython/Lib/test/test_weakref.py Modified: trunk/jython/Lib/test/test_array.py =================================================================== --- trunk/jython/Lib/test/test_array.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_array.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -11,7 +11,6 @@ if test_support.is_jython: import operator - from test_weakref import extra_collect class ArraySubclass(array.array): pass @@ -704,8 +703,7 @@ p = proxy(s) self.assertEqual(p.tostring(), s.tostring()) s = None - if test_support.is_jython: - extra_collect() + test_support.gc_collect() self.assertRaises(ReferenceError, len, p) def test_bug_782369(self): Modified: trunk/jython/Lib/test/test_class.py =================================================================== --- trunk/jython/Lib/test/test_class.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_class.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -1,6 +1,6 @@ "Test the functionality of Python classes implementing operators." -from test.test_support import TestFailed +from test.test_support import TestFailed, gc_collect testmeths = [ @@ -249,9 +249,7 @@ # This test has to be last (duh.) del testme -if sys.platform[:4] == 'java': - from test_weakref import extra_collect - extra_collect() +gc_collect() # Interfering tests Modified: trunk/jython/Lib/test/test_deque.py =================================================================== --- trunk/jython/Lib/test/test_deque.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_deque.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -475,9 +475,7 @@ p = proxy(d) self.assertEqual(str(p), str(d)) d = None - if test_support.is_jython: - from test_weakref import extra_collect - extra_collect() + test_support.gc_collect() self.assertRaises(ReferenceError, str, p) def test_strange_subclass(self): Modified: trunk/jython/Lib/test/test_descr.py =================================================================== --- trunk/jython/Lib/test/test_descr.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_descr.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -1,14 +1,9 @@ # Test enhancements related to descriptors and new-style classes -from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout, is_jython +from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout, gc_collect, is_jython from copy import deepcopy import warnings import types -if is_jython: - from test_weakref import extra_collect -else: - def extra_collect(): - pass warnings.filterwarnings("ignore", r'complex divmod\(\), // and % are deprecated$', @@ -1266,7 +1261,7 @@ x.c = Counted() vereq(Counted.counter, 3) del x - extra_collect() + gc_collect() vereq(Counted.counter, 0) class D(C): pass @@ -1275,7 +1270,7 @@ x.z = Counted() vereq(Counted.counter, 2) del x - extra_collect() + gc_collect() vereq(Counted.counter, 0) class E(D): __slots__ = ['e'] @@ -1285,7 +1280,7 @@ x.e = Counted() vereq(Counted.counter, 3) del x - extra_collect() + gc_collect() vereq(Counted.counter, 0) # Test cyclical leaks [SF bug 519621] @@ -1298,7 +1293,7 @@ s = None import gc gc.collect() - extra_collect() + gc_collect() vereq(Counted.counter, 0) # XXX: This tests a CPython GC reference count bug and Jython lacks @@ -1331,7 +1326,7 @@ h = H() try: del h - extra_collect() + gc_collect() finally: sys.stderr = save_stderr @@ -1982,7 +1977,7 @@ r = weakref.ref(c) verify(r() is c) del c - extra_collect() + gc_collect() verify(r() is None) del r class NoWeak(object): @@ -2002,7 +1997,7 @@ r = weakref.ref(yes) verify(r() is yes) del yes - extra_collect() + gc_collect() verify(r() is None) del r @@ -3332,7 +3327,7 @@ c = C() vereq(log, []) del c - extra_collect() + gc_collect() vereq(log, [1]) class D(object): pass Modified: trunk/jython/Lib/test/test_file.py =================================================================== --- trunk/jython/Lib/test/test_file.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_file.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -5,7 +5,7 @@ from array import array from weakref import proxy -from test.test_support import TESTFN, findfile, is_jython, run_unittest +from test.test_support import TESTFN, findfile, gc_collect, is_jython, run_unittest from UserList import UserList class AutoFileTests(unittest.TestCase): @@ -26,9 +26,7 @@ self.assertEquals(self.f.tell(), p.tell()) self.f.close() self.f = None - if is_jython: - from test_weakref import extra_collect - extra_collect() + gc_collect() self.assertRaises(ReferenceError, getattr, p, 'tell') def testAttributes(self): Modified: trunk/jython/Lib/test/test_functools.py =================================================================== --- trunk/jython/Lib/test/test_functools.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_functools.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -131,9 +131,7 @@ p = proxy(f) self.assertEqual(f.func, p.func) f = None - if test_support.is_jython: - from test_weakref import extra_collect - extra_collect() + test_support.gc_collect() self.assertRaises(ReferenceError, getattr, p, 'func') def test_with_bound_and_unbound_methods(self): Modified: trunk/jython/Lib/test/test_generators.py =================================================================== --- trunk/jython/Lib/test/test_generators.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_generators.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -1653,7 +1653,7 @@ >>> g = f() >>> g.next() ->>> del g; extra_collect() +>>> del g; gc_collect() exiting @@ -1678,7 +1678,7 @@ >>> old, sys.stderr = sys.stderr, StringIO.StringIO() >>> g = f() >>> g.next() ->>> del g; extra_collect() +>>> del g; gc_collect() >>> sys.stderr.getvalue().startswith( ... "Exception RuntimeError" ... ) @@ -1795,7 +1795,7 @@ ... raise RuntimeError ... ... l = Leaker() -... del l; extra_collect() +... del l; gc_collect() ... err = sys.stderr.getvalue().strip() ... err.startswith( ... "Exception RuntimeError in <" @@ -1834,13 +1834,8 @@ from test import test_support, test_generators test_support.run_doctest(test_generators, verbose) -def extra_collect(): - import gc - from time import sleep +from test.test_support import gc_collect - gc.collect(); sleep(1); gc.collect(); sleep(0.1); gc.collect() - - # This part isn't needed for regrtest, but for running the test directly. if __name__ == "__main__": test_main(1) Modified: trunk/jython/Lib/test/test_iter.py =================================================================== --- trunk/jython/Lib/test/test_iter.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_iter.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -1,7 +1,7 @@ # Test iterators. import unittest -from test.test_support import run_unittest, TESTFN, unlink, have_unicode +from test.test_support import gc_collect, run_unittest, TESTFN, unlink, have_unicode # Test result of triple loop (too big to inline) TRIPLETS = [(0, 0, 0), (0, 0, 1), (0, 0, 2), @@ -781,7 +781,6 @@ # Test reference count behavior # XXX: Jython new style objects don't support __del__ yet - from test_weakref import extra_collect #class C(object): class C: count = 0 @@ -797,7 +796,7 @@ x = C() self.assertEqual(C.count, 1) del x - extra_collect() + gc_collect() self.assertEqual(C.count, 0) l = [C(), C(), C()] self.assertEqual(C.count, 3) @@ -806,7 +805,7 @@ except ValueError: pass del l - extra_collect() + gc_collect() self.assertEqual(C.count, 0) Modified: trunk/jython/Lib/test/test_scope.py =================================================================== --- trunk/jython/Lib/test/test_scope.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_scope.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -1,4 +1,4 @@ -from test.test_support import verify, TestFailed, check_syntax, vereq, is_jython +from test.test_support import verify, TestFailed, check_syntax, vereq, gc_collect import warnings warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<string>") @@ -435,11 +435,9 @@ for i in range(100): f1() -if is_jython: - from test_weakref import extra_collect - extra_collect() - # A lot of garbage - extra_collect() +gc_collect() +# A lot of garbage +gc_collect() vereq(Foo.count, 0) print "17. class and global" Modified: trunk/jython/Lib/test/test_set.py =================================================================== --- trunk/jython/Lib/test/test_set.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_set.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -1,6 +1,5 @@ import unittest from test import test_support -from test_weakref import extra_collect from weakref import proxy import operator import copy @@ -484,7 +483,7 @@ p = proxy(s) self.assertEqual(str(p), str(s)) s = None - extra_collect() + test_support.gc_collect() self.assertRaises(ReferenceError, str, p) # C API test only available in a debug build Modified: trunk/jython/Lib/test/test_support.py =================================================================== --- trunk/jython/Lib/test/test_support.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_support.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -299,6 +299,22 @@ fn, _ = urllib.urlretrieve(url, filename) return open(fn) +def gc_collect(): + """Force as many objects as possible to be collected. + + In non-CPython implementations of Python, this is needed because timely + deallocation is not guaranteed by the garbage collector. (Even in CPython + this can be the case in case of reference cycles.) This means that __del__ + methods may be called later than expected and weakrefs may remain alive for + longer than expected. This function tries its best to force all garbage + objects to disappear. + """ + import gc + gc.collect() + time.sleep(0.1) + gc.collect() + gc.collect() + #======================================================================= # Decorator for running a function in a different locale, correctly resetting # it afterwards. Modified: trunk/jython/Lib/test/test_weakref.py =================================================================== --- trunk/jython/Lib/test/test_weakref.py 2009-05-31 21:42:09 UTC (rev 6435) +++ trunk/jython/Lib/test/test_weakref.py 2009-06-01 04:37:42 UTC (rev 6436) @@ -6,19 +6,6 @@ from test import test_support -if test_support.is_jython: - import time - - def extra_collect(): - """Kick Java's GC into gear""" - gc.collect() - time.sleep(0.1) - gc.collect() - gc.collect() -else: - def extra_collect(): - pass - # Used in ReferencesTestCase.test_ref_created_during_del() . ref_from_del = None @@ -82,7 +69,7 @@ ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del o - extra_collect() + test_support.gc_collect() self.assert_(ref1() is None, "expected reference to be invalidated") self.assert_(ref2() is None, @@ -118,7 +105,7 @@ def check(proxy): proxy.bar - extra_collect() + test_support.gc_collect() self.assertRaises(weakref.ReferenceError, check, ref1) self.assertRaises(weakref.ReferenceError, check, ref2) # XXX: CPython GC collects C() immediately. use ref1 instead on @@ -143,7 +130,7 @@ o = factory() ref = weakref.ref(o, self.callback) del o - extra_collect() + test_support.gc_collect() self.assert_(self.cbcalled == 1, "callback did not properly set 'cbcalled'") self.assert_(ref() is None, @@ -168,7 +155,7 @@ self.assert_(weakref.getweakrefcount(o) == 2, "wrong weak ref count for object") del proxy - extra_collect() + test_support.gc_collect() self.assert_(weakref.getweakrefcount(o) == 1, "wrong weak ref count for object after deleting proxy") @@ -314,7 +301,7 @@ "got wrong number of weak reference objects") del ref1, ref2, proxy1, proxy2 - extra_collect() + test_support.gc_collect() self.assert_(weakref.getweakrefcount(o) == 0, "weak reference objects not unlinked from" " referent when discarded.") @@ -328,7 +315,7 @@ ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 - extra_collect() + test_support.gc_collect() self.assert_(weakref.getweakrefs(o) == [ref2], "list of refs does not match") @@ -336,7 +323,7 @@ ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 - extra_collect() + test_support.gc_collect() if test_support.is_jython: # XXX: Likely a Jython bug: the following inline declared # [ref1] list isn't garbage collected no matter how many @@ -353,7 +340,7 @@ "list of refs does not match") del ref1 - extra_collect() + test_support.gc_collect() self.assert_(weakref.getweakrefs(o) == [], "list of refs not cleared") @@ -632,7 +619,7 @@ del callback, c, d, C self.assertEqual(alist, []) # del isn't enough to clean up cycles gc.collect() - extra_collect() + test_support.gc_collect() self.assertEqual(alist, ["safe_callback called"]) self.assertEqual(external_wr(), None) @@ -783,18 +770,18 @@ del items1, items2 self.assert_(len(dict) == self.COUNT) del objects[0] - extra_collect() + test_support.gc_collect() self.assert_(len(dict) == (self.COUNT - 1), "deleting object did not cause dictionary update") del objects, o - extra_collect() + test_support.gc_collect() self.assert_(len(dict) == 0, "deleting the values did not clear the dictionary") # regression on SF bug #447152: dict = weakref.WeakValueDictionary() self.assertRaises(KeyError, dict.__getitem__, 1) dict[2] = C() - extra_collect() + test_support.gc_collect() self.assertRaises(KeyError, dict.__getitem__, 2) def test_weak_keys(self): @@ -815,11 +802,11 @@ del items1, items2 self.assert_(len(dict) == self.COUNT) del objects[0] - extra_collect() + test_support.gc_collect() self.assert_(len(dict) == (self.COUNT - 1), "deleting object did not cause dictionary update") del objects, o - extra_collect() + test_support.gc_collect() self.assert_(len(dict) == 0, "deleting the keys did not clear the dictionary") o = Object(42) @@ -1128,7 +1115,7 @@ >>> o is o2 True >>> del o, o2 ->>> extra_collect() +>>> test_support.gc_collect() >>> print r() None @@ -1181,7 +1168,7 @@ >>> id2obj(a_id) is a True >>> del a ->>> extra_collect() +>>> test_support.gc_collect() >>> try: ... id2obj(a_id) ... except KeyError: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |