diff options
author | Guido van Rossum <guido@python.org> | 2007-08-18 00:10:33 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-18 00:10:33 (GMT) |
commit | 3de862df45480438dc6756103109ea9010d2825e (patch) | |
tree | fe708edef01528ab29e5e9eb1c6ec88016cbb20b /Lib | |
parent | 787794f8e2566a0d6561a7fdad84e580dc9c7d05 (diff) | |
download | cpython-3de862df45480438dc6756103109ea9010d2825e.zip cpython-3de862df45480438dc6756103109ea9010d2825e.tar.gz cpython-3de862df45480438dc6756103109ea9010d2825e.tar.bz2 |
Make the cleanup between -R passes deal better with ABC registries,
*restoring* selected registries instead of *resetting* them all. Also
change the default for the huntrleaks parameter to None everywhere, as
its other value is a list of three elements, so it is not a bool.
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/test/regrtest.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 6e6bb73..0c7ef7c 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -184,7 +184,7 @@ def usage(msg): def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, exclude=False, single=False, randomize=False, fromfile=None, findleaks=False, use_resources=None, trace=False, coverdir='coverage', - runleaks=False, huntrleaks=False, verbose2=False, debug=False, + runleaks=False, huntrleaks=None, verbose2=False, debug=False, start=None): """Execute a test suite. @@ -518,7 +518,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): return stdtests + tests def runtest(test, generate, verbose, quiet, testdir=None, - huntrleaks=False, debug=False): + huntrleaks=None, debug=False): """Run a single test. test -- the name of the test @@ -545,7 +545,7 @@ def runtest(test, generate, verbose, quiet, testdir=None, cleanup_test_droppings(test, verbose) def runtest_inner(test, generate, verbose, quiet, - testdir=None, huntrleaks=False, debug=False): + testdir=None, huntrleaks=None, debug=False): test_support.unload(test) if not testdir: testdir = findtestdir() @@ -670,7 +670,7 @@ def cleanup_test_droppings(testname, verbose): def dash_R(the_module, test, indirect_test, huntrleaks): # This code is hackish and inelegant, but it seems to do the job. - import copy_reg + import copy_reg, _abcoll if not hasattr(sys, 'gettotalrefcount'): raise Exception("Tracking reference leaks requires a debug build " @@ -680,6 +680,9 @@ def dash_R(the_module, test, indirect_test, huntrleaks): fs = warnings.filters[:] ps = copy_reg.dispatch_table.copy() pic = sys.path_importer_cache.copy() + abcs = {obj: obj._ABCMeta__registry.copy() + for abc in [getattr(_abcoll, a) for a in _abcoll.__all__] + for obj in abc.__subclasses__() + [abc]} if indirect_test: def run_the_test(): @@ -694,13 +697,13 @@ def dash_R(the_module, test, indirect_test, huntrleaks): repcount = nwarmup + ntracked print("beginning", repcount, "repetitions", file=sys.stderr) print(("1234567890"*(repcount//10 + 1))[:repcount], file=sys.stderr) - dash_R_cleanup(fs, ps, pic) + dash_R_cleanup(fs, ps, pic, abcs) for i in range(repcount): rc = sys.gettotalrefcount() run_the_test() sys.stderr.write('.') sys.stderr.flush() - dash_R_cleanup(fs, ps, pic) + dash_R_cleanup(fs, ps, pic, abcs) if i >= nwarmup: deltas.append(sys.gettotalrefcount() - rc - 2) print(file=sys.stderr) @@ -711,7 +714,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks): print(msg, file=refrep) refrep.close() -def dash_R_cleanup(fs, ps, pic): +def dash_R_cleanup(fs, ps, pic, abcs): import gc, copy_reg import _strptime, linecache, dircache import urlparse, urllib, urllib2, mimetypes, doctest @@ -725,10 +728,10 @@ def dash_R_cleanup(fs, ps, pic): sys.path_importer_cache.clear() sys.path_importer_cache.update(pic) - # Clear ABC registries. + # Clear ABC registries, restoring previously saved ABC registries. for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]: for obj in abc.__subclasses__() + [abc]: - obj._ABCMeta__registry.clear() + obj._ABCMeta__registry = abcs.get(obj, {}).copy() obj._ABCMeta__cache.clear() obj._ABCMeta__negative_cache.clear() |