[Python-checkins] cpython: Cleanup libregrtest

victor.stinner python-checkins at python.org
Mon Aug 22 08:32:14 EDT 2016


https://hg.python.org/cpython/rev/13b13f4ad285
changeset:   102837:13b13f4ad285
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Aug 22 14:28:52 2016 +0200
summary:
  Cleanup libregrtest

* main.py: remove unused import
* runtest: simplify runtest_inner() parameters, reuse ns parameter

files:
  Lib/test/libregrtest/main.py    |   1 -
  Lib/test/libregrtest/runtest.py |  56 +++++++-------------
  2 files changed, 20 insertions(+), 37 deletions(-)


diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
--- a/Lib/test/libregrtest/main.py
+++ b/Lib/test/libregrtest/main.py
@@ -1,6 +1,5 @@
 import datetime
 import faulthandler
-import math
 import os
 import platform
 import random
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
--- a/Lib/test/libregrtest/runtest.py
+++ b/Lib/test/libregrtest/runtest.py
@@ -74,18 +74,12 @@
 def runtest(ns, test):
     """Run a single test.
 
+    ns -- regrtest namespace of options
     test -- the name of the test
-    verbose -- if true, print more messages
-    quiet -- if true, don't print 'skipped' messages (probably redundant)
-    huntrleaks -- run multiple times to test for leaks; requires a debug
-                  build; a triple corresponding to -R's three arguments
-    output_on_failure -- if true, display test output on failure
-    timeout -- dump the traceback and exit if a test takes more than
-               timeout seconds
-    failfast, match_tests -- See regrtest command-line flags for these.
-    pgo -- if true, suppress any info irrelevant to a generating a PGO build
 
-    Returns the tuple result, test_time, where result is one of the constants:
+    Returns the tuple (result, test_time), where result is one of the
+    constants:
+
         INTERRUPTED      KeyboardInterrupt when run under -j
         RESOURCE_DENIED  test skipped because resource denied
         SKIPPED          test skipped for some other reason
@@ -94,21 +88,14 @@
         PASSED           test passed
     """
 
-    verbose = ns.verbose
-    quiet = ns.quiet
-    huntrleaks = ns.huntrleaks
     output_on_failure = ns.verbose3
-    failfast = ns.failfast
-    match_tests = ns.match_tests
-    timeout = ns.timeout
-    pgo = ns.pgo
 
-    use_timeout = (timeout is not None)
+    use_timeout = (ns.timeout is not None)
     if use_timeout:
-        faulthandler.dump_traceback_later(timeout, exit=True)
+        faulthandler.dump_traceback_later(ns.timeout, exit=True)
     try:
-        support.match_tests = match_tests
-        if failfast:
+        support.match_tests = ns.match_tests
+        if ns.failfast:
             support.failfast = True
         if output_on_failure:
             support.verbose = True
@@ -129,8 +116,7 @@
             try:
                 sys.stdout = stream
                 sys.stderr = stream
-                result = runtest_inner(ns, test, verbose, quiet, huntrleaks,
-                                       display_failure=False, pgo=pgo)
+                result = runtest_inner(ns, test, display_failure=False)
                 if result[0] == FAILED:
                     output = stream.getvalue()
                     orig_stderr.write(output)
@@ -139,19 +125,17 @@
                 sys.stdout = orig_stdout
                 sys.stderr = orig_stderr
         else:
-            support.verbose = verbose  # Tell tests to be moderately quiet
-            result = runtest_inner(ns, test, verbose, quiet, huntrleaks,
-                                   display_failure=not verbose, pgo=pgo)
+            support.verbose = ns.verbose  # Tell tests to be moderately quiet
+            result = runtest_inner(ns, test, display_failure=not ns.verbose)
         return result
     finally:
         if use_timeout:
             faulthandler.cancel_dump_traceback_later()
-        cleanup_test_droppings(test, verbose)
+        cleanup_test_droppings(test, ns.verbose)
 runtest.stringio = None
 
 
-def runtest_inner(ns, test, verbose, quiet,
-                  huntrleaks=False, display_failure=True, *, pgo=False):
+def runtest_inner(ns, test, display_failure=True):
     support.unload(test)
 
     test_time = 0.0
@@ -162,7 +146,7 @@
         else:
             # Always import it from the test package
             abstest = 'test.' + test
-        with saved_test_environment(test, verbose, quiet, pgo=pgo) as environment:
+        with saved_test_environment(test, ns.verbose, ns.quiet, pgo=ns.pgo) as environment:
             start_time = time.time()
             the_module = importlib.import_module(abstest)
             # If the test has a test_main, that will run the appropriate
@@ -178,21 +162,21 @@
                         raise Exception("errors while loading tests")
                     support.run_unittest(tests)
             test_runner()
-            if huntrleaks:
-                refleak = dash_R(the_module, test, test_runner, huntrleaks)
+            if ns.huntrleaks:
+                refleak = dash_R(the_module, test, test_runner, ns.huntrleaks)
             test_time = time.time() - start_time
     except support.ResourceDenied as msg:
-        if not quiet and not pgo:
+        if not ns.quiet and not ns.pgo:
             print(test, "skipped --", msg, flush=True)
         return RESOURCE_DENIED, test_time
     except unittest.SkipTest as msg:
-        if not quiet and not pgo:
+        if not ns.quiet and not ns.pgo:
             print(test, "skipped --", msg, flush=True)
         return SKIPPED, test_time
     except KeyboardInterrupt:
         raise
     except support.TestFailed as msg:
-        if not pgo:
+        if not ns.pgo:
             if display_failure:
                 print("test", test, "failed --", msg, file=sys.stderr,
                       flush=True)
@@ -201,7 +185,7 @@
         return FAILED, test_time
     except:
         msg = traceback.format_exc()
-        if not pgo:
+        if not ns.pgo:
             print("test", test, "crashed --", msg, file=sys.stderr,
                   flush=True)
         return FAILED, test_time

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list