From 4045e88b8b43b2748e7be7ed3f0cae932e612b73 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 29 Oct 2009 20:53:00 +0000 Subject: [PATCH] Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests. --- Lib/test/regrtest.py | 67 ++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 01cb5682b0a..c33784288b8 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -194,6 +194,14 @@ if sys.platform == 'darwin': newsoft = min(hard, max(soft, 1024*2048)) resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard)) +# Test result constants. +PASSED = 1 +FAILED = 0 +ENV_CHANGED = -1 +SKIPPED = -2 +RESOURCE_DENIED = -3 +INTERRUPTED = -4 + from test import test_support RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb', @@ -328,7 +336,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, try: result = runtest(*args, **kwargs) except BaseException, e: - result = -4, e.__class__.__name__ + result = INTERRUPTED, e.__class__.__name__ print # Force a newline (just in case) print json.dumps(result) sys.exit(0) @@ -410,19 +418,18 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, def accumulate_result(test, result): ok, test_time = result test_times.append((test_time, test)) - if ok > 0: + if ok == PASSED: good.append(test) - return 'good' - elif -2 < ok <= 0: + elif ok == FAILED: bad.append(test) - if ok == -1: - environment_changed.append(test) - return 'bad' - else: + elif ok == ENV_CHANGED: + bad.append(test) + environment_changed.append(test) + elif ok == SKIPPED: skipped.append(test) - if ok == -3: - resource_denieds.append(test) - return 'skipped' + elif ok == RESOURCE_DENIED: + skipped.append(test) + resource_denieds.append(test) if use_mp: from threading import Thread @@ -477,7 +484,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, print stdout if stderr: print >>sys.stderr, stderr - if result[0] == -4: + if result[0] == INTERRUPTED: assert result[1] == 'KeyboardInterrupt' pending.clear() raise KeyboardInterrupt # What else? @@ -498,8 +505,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, try: result = runtest(test, verbose, quiet, testdir, huntrleaks) - which = accumulate_result(test, result) - if verbose3 and which == 'bad': + accumulate_result(test, result) + if verbose3 and result[0] == FAILED: print "Re-running test %r in verbose mode" % test runtest(test, True, quiet, testdir, huntrleaks) except KeyboardInterrupt: @@ -646,13 +653,13 @@ def runtest(test, verbose, quiet, testdir -- test directory huntrleaks -- run multiple times to test for leaks; requires a debug build; a triple corresponding to -R's three arguments - Return: - -4 KeyboardInterrupt when run under -j - -3 test skipped because resource denied - -2 test skipped for some other reason - -1 test failed because it changed the execution environment - 0 test failed - 1 test passed + Returns one of the test result constants: + INTERRUPTED KeyboardInterrupt when run under -j + RESOURCE_DENIED test skipped because resource denied + SKIPPED test skipped for some other reason + ENV_CHANGED test failed because it changed the execution environment + FAILED test failed + PASSED test passed """ test_support.verbose = verbose # Tell tests to be moderately quiet @@ -823,18 +830,18 @@ def runtest_inner(test, verbose, quiet, if not quiet: print test, "skipped --", msg sys.stdout.flush() - return -3, test_time + return RESOURCE_DENIED, test_time except unittest.SkipTest, msg: if not quiet: print test, "skipped --", msg sys.stdout.flush() - return -2, test_time + return SKIPPED, test_time except KeyboardInterrupt: raise except test_support.TestFailed, msg: print "test", test, "failed --", msg sys.stdout.flush() - return 0, test_time + return FAILED, test_time except: type, value = sys.exc_info()[:2] print "test", test, "crashed --", str(type) + ":", value @@ -842,24 +849,24 @@ def runtest_inner(test, verbose, quiet, if verbose: traceback.print_exc(file=sys.stdout) sys.stdout.flush() - return 0, test_time + return FAILED, test_time else: if refleak: - return 0, test_time + return FAILED, test_time if environment.changed: - return -1, test_time + return ENVIRONMENT_CHANGED, test_time # Except in verbose mode, tests should not print anything if verbose or huntrleaks: - return 1, test_time + return PASSED, test_time output = capture_stdout.getvalue() if not output: - return 1, test_time + return PASSED, test_time print "test", test, "produced unexpected output:" print "*" * 70 print output print "*" * 70 sys.stdout.flush() - return 0, test_time + return FAILED, test_time def cleanup_test_droppings(testname, verbose): import shutil