From: <pj...@us...> - 2009-06-01 04:47:02
|
Revision: 6437 http://jython.svn.sourceforge.net/jython/?rev=6437&view=rev Author: pjenvey Date: 2009-06-01 04:46:45 +0000 (Mon, 01 Jun 2009) Log Message: ----------- blah, revert r6435 for now as it breaks running the tests on CPython, which is too useful 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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_array.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -11,6 +11,7 @@ if test_support.is_jython: import operator + from test_weakref import extra_collect class ArraySubclass(array.array): pass @@ -703,7 +704,8 @@ p = proxy(s) self.assertEqual(p.tostring(), s.tostring()) s = None - test_support.gc_collect() + if test_support.is_jython: + extra_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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_class.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -1,6 +1,6 @@ "Test the functionality of Python classes implementing operators." -from test.test_support import TestFailed, gc_collect +from test.test_support import TestFailed testmeths = [ @@ -249,7 +249,9 @@ # This test has to be last (duh.) del testme -gc_collect() +if sys.platform[:4] == 'java': + from test_weakref import extra_collect + extra_collect() # Interfering tests Modified: trunk/jython/Lib/test/test_deque.py =================================================================== --- trunk/jython/Lib/test/test_deque.py 2009-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_deque.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -475,7 +475,9 @@ p = proxy(d) self.assertEqual(str(p), str(d)) d = None - test_support.gc_collect() + if test_support.is_jython: + from test_weakref import extra_collect + extra_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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_descr.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -1,9 +1,14 @@ # Test enhancements related to descriptors and new-style classes -from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout, gc_collect, is_jython +from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout, 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$', @@ -1261,7 +1266,7 @@ x.c = Counted() vereq(Counted.counter, 3) del x - gc_collect() + extra_collect() vereq(Counted.counter, 0) class D(C): pass @@ -1270,7 +1275,7 @@ x.z = Counted() vereq(Counted.counter, 2) del x - gc_collect() + extra_collect() vereq(Counted.counter, 0) class E(D): __slots__ = ['e'] @@ -1280,7 +1285,7 @@ x.e = Counted() vereq(Counted.counter, 3) del x - gc_collect() + extra_collect() vereq(Counted.counter, 0) # Test cyclical leaks [SF bug 519621] @@ -1293,7 +1298,7 @@ s = None import gc gc.collect() - gc_collect() + extra_collect() vereq(Counted.counter, 0) # XXX: This tests a CPython GC reference count bug and Jython lacks @@ -1326,7 +1331,7 @@ h = H() try: del h - gc_collect() + extra_collect() finally: sys.stderr = save_stderr @@ -1977,7 +1982,7 @@ r = weakref.ref(c) verify(r() is c) del c - gc_collect() + extra_collect() verify(r() is None) del r class NoWeak(object): @@ -1997,7 +2002,7 @@ r = weakref.ref(yes) verify(r() is yes) del yes - gc_collect() + extra_collect() verify(r() is None) del r @@ -3327,7 +3332,7 @@ c = C() vereq(log, []) del c - gc_collect() + extra_collect() vereq(log, [1]) class D(object): pass Modified: trunk/jython/Lib/test/test_file.py =================================================================== --- trunk/jython/Lib/test/test_file.py 2009-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_file.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -5,7 +5,7 @@ from array import array from weakref import proxy -from test.test_support import TESTFN, findfile, gc_collect, is_jython, run_unittest +from test.test_support import TESTFN, findfile, is_jython, run_unittest from UserList import UserList class AutoFileTests(unittest.TestCase): @@ -26,7 +26,9 @@ self.assertEquals(self.f.tell(), p.tell()) self.f.close() self.f = None - gc_collect() + if is_jython: + from test_weakref import extra_collect + extra_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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_functools.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -131,7 +131,9 @@ p = proxy(f) self.assertEqual(f.func, p.func) f = None - test_support.gc_collect() + if test_support.is_jython: + from test_weakref import extra_collect + extra_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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_generators.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -1653,7 +1653,7 @@ >>> g = f() >>> g.next() ->>> del g; gc_collect() +>>> del g; extra_collect() exiting @@ -1678,7 +1678,7 @@ >>> old, sys.stderr = sys.stderr, StringIO.StringIO() >>> g = f() >>> g.next() ->>> del g; gc_collect() +>>> del g; extra_collect() >>> sys.stderr.getvalue().startswith( ... "Exception RuntimeError" ... ) @@ -1795,7 +1795,7 @@ ... raise RuntimeError ... ... l = Leaker() -... del l; gc_collect() +... del l; extra_collect() ... err = sys.stderr.getvalue().strip() ... err.startswith( ... "Exception RuntimeError in <" @@ -1834,8 +1834,13 @@ from test import test_support, test_generators test_support.run_doctest(test_generators, verbose) -from test.test_support import gc_collect +def extra_collect(): + import gc + from time import sleep + 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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_iter.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -1,7 +1,7 @@ # Test iterators. import unittest -from test.test_support import gc_collect, run_unittest, TESTFN, unlink, have_unicode +from test.test_support import 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,6 +781,7 @@ # 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 @@ -796,7 +797,7 @@ x = C() self.assertEqual(C.count, 1) del x - gc_collect() + extra_collect() self.assertEqual(C.count, 0) l = [C(), C(), C()] self.assertEqual(C.count, 3) @@ -805,7 +806,7 @@ except ValueError: pass del l - gc_collect() + extra_collect() self.assertEqual(C.count, 0) Modified: trunk/jython/Lib/test/test_scope.py =================================================================== --- trunk/jython/Lib/test/test_scope.py 2009-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_scope.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -1,4 +1,4 @@ -from test.test_support import verify, TestFailed, check_syntax, vereq, gc_collect +from test.test_support import verify, TestFailed, check_syntax, vereq, is_jython import warnings warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<string>") @@ -435,9 +435,11 @@ for i in range(100): f1() -gc_collect() -# A lot of garbage -gc_collect() +if is_jython: + from test_weakref import extra_collect + extra_collect() + # A lot of garbage + extra_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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_set.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -1,5 +1,6 @@ import unittest from test import test_support +from test_weakref import extra_collect from weakref import proxy import operator import copy @@ -483,7 +484,7 @@ p = proxy(s) self.assertEqual(str(p), str(s)) s = None - test_support.gc_collect() + extra_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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_support.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -299,22 +299,6 @@ 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-06-01 04:37:42 UTC (rev 6436) +++ trunk/jython/Lib/test/test_weakref.py 2009-06-01 04:46:45 UTC (rev 6437) @@ -6,6 +6,19 @@ 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 @@ -69,7 +82,7 @@ ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del o - test_support.gc_collect() + extra_collect() self.assert_(ref1() is None, "expected reference to be invalidated") self.assert_(ref2() is None, @@ -105,7 +118,7 @@ def check(proxy): proxy.bar - test_support.gc_collect() + extra_collect() self.assertRaises(weakref.ReferenceError, check, ref1) self.assertRaises(weakref.ReferenceError, check, ref2) # XXX: CPython GC collects C() immediately. use ref1 instead on @@ -130,7 +143,7 @@ o = factory() ref = weakref.ref(o, self.callback) del o - test_support.gc_collect() + extra_collect() self.assert_(self.cbcalled == 1, "callback did not properly set 'cbcalled'") self.assert_(ref() is None, @@ -155,7 +168,7 @@ self.assert_(weakref.getweakrefcount(o) == 2, "wrong weak ref count for object") del proxy - test_support.gc_collect() + extra_collect() self.assert_(weakref.getweakrefcount(o) == 1, "wrong weak ref count for object after deleting proxy") @@ -301,7 +314,7 @@ "got wrong number of weak reference objects") del ref1, ref2, proxy1, proxy2 - test_support.gc_collect() + extra_collect() self.assert_(weakref.getweakrefcount(o) == 0, "weak reference objects not unlinked from" " referent when discarded.") @@ -315,7 +328,7 @@ ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 - test_support.gc_collect() + extra_collect() self.assert_(weakref.getweakrefs(o) == [ref2], "list of refs does not match") @@ -323,7 +336,7 @@ ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 - test_support.gc_collect() + extra_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 @@ -340,7 +353,7 @@ "list of refs does not match") del ref1 - test_support.gc_collect() + extra_collect() self.assert_(weakref.getweakrefs(o) == [], "list of refs not cleared") @@ -619,7 +632,7 @@ del callback, c, d, C self.assertEqual(alist, []) # del isn't enough to clean up cycles gc.collect() - test_support.gc_collect() + extra_collect() self.assertEqual(alist, ["safe_callback called"]) self.assertEqual(external_wr(), None) @@ -770,18 +783,18 @@ del items1, items2 self.assert_(len(dict) == self.COUNT) del objects[0] - test_support.gc_collect() + extra_collect() self.assert_(len(dict) == (self.COUNT - 1), "deleting object did not cause dictionary update") del objects, o - test_support.gc_collect() + extra_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() - test_support.gc_collect() + extra_collect() self.assertRaises(KeyError, dict.__getitem__, 2) def test_weak_keys(self): @@ -802,11 +815,11 @@ del items1, items2 self.assert_(len(dict) == self.COUNT) del objects[0] - test_support.gc_collect() + extra_collect() self.assert_(len(dict) == (self.COUNT - 1), "deleting object did not cause dictionary update") del objects, o - test_support.gc_collect() + extra_collect() self.assert_(len(dict) == 0, "deleting the keys did not clear the dictionary") o = Object(42) @@ -1115,7 +1128,7 @@ >>> o is o2 True >>> del o, o2 ->>> test_support.gc_collect() +>>> extra_collect() >>> print r() None @@ -1168,7 +1181,7 @@ >>> id2obj(a_id) is a True >>> del a ->>> test_support.gc_collect() +>>> extra_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. |