[Python-checkins] r75954 - python/trunk/Lib/test/regrtest.py

georg.brandl python-checkins at python.org
Thu Oct 29 21:53:00 CET 2009


Author: georg.brandl
Date: Thu Oct 29 21:53:00 2009
New Revision: 75954

Log:
Use constants instead of magic integers for test result.  Do not re-run with --verbose3 for environment changing tests.

Modified:
   python/trunk/Lib/test/regrtest.py

Modified: python/trunk/Lib/test/regrtest.py
==============================================================================
--- python/trunk/Lib/test/regrtest.py	(original)
+++ python/trunk/Lib/test/regrtest.py	Thu Oct 29 21:53:00 2009
@@ -194,6 +194,14 @@
         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 @@
             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 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)
+        elif ok == RESOURCE_DENIED:
             skipped.append(test)
-            if ok == -3:
-                resource_denieds.append(test)
-            return 'skipped'
+            resource_denieds.append(test)
 
     if use_mp:
         from threading import Thread
@@ -477,7 +484,7 @@
                 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 @@
                 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 @@
     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 @@
         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 @@
         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


More information about the Python-checkins mailing list