From f81de5e1946bcc07b86bac16f51ac0b4d0208da6 Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Fri, 22 Jul 2016 18:47:04 -0400 Subject: Closes issue #24773: Implement PEP 495 (Local Time Disambiguation). --- Lib/test/libregrtest/cmdline.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py index de09a0122a..f2ec0bd4d2 100644 --- a/Lib/test/libregrtest/cmdline.py +++ b/Lib/test/libregrtest/cmdline.py @@ -112,6 +112,8 @@ resources to test. Currently only the following are defined: gui - Run tests that require a running GUI. + tzdata - Run tests that require timezone data. + To enable all resources except one, use '-uall,-'. For example, to run all the tests except for the gui tests, give the option '-uall,-gui'. @@ -119,7 +121,7 @@ option '-uall,-gui'. RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', - 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui') + 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', 'tzdata') class _ArgParser(argparse.ArgumentParser): -- cgit v1.2.1 From e2507f5ffdeb4fc680e7f70e9e1028d3c4c79b2a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Aug 2016 11:25:43 +0200 Subject: regrtest: rename --slow option to --slowest Thanks to optparse, --slow syntax still works ;-) --- Lib/test/libregrtest/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py index f2ec0bd4d2..1f7aaedae3 100644 --- a/Lib/test/libregrtest/cmdline.py +++ b/Lib/test/libregrtest/cmdline.py @@ -168,7 +168,7 @@ def _create_parser(): help='display test output on failure') group.add_argument('-q', '--quiet', action='store_true', help='no output unless one or more tests fail') - group.add_argument('-o', '--slow', action='store_true', dest='print_slow', + group.add_argument('-o', '--slowest', action='store_true', dest='print_slow', help='print the slowest 10 tests') group.add_argument('--header', action='store_true', help='print header with interpreter info') -- cgit v1.2.1 From 95bb93b1a604a35f68a6225f22cfd2891c7fa595 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Aug 2016 12:22:52 +0200 Subject: regrtest: nicer output for durations Use milliseconds and minutes units, not only seconds. --- Lib/test/libregrtest/main.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index e503c131ac..edf38b4d17 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -34,6 +34,16 @@ else: TEMPDIR = os.path.abspath(TEMPDIR) +def format_duration(seconds): + if seconds < 1.0: + return '%.0f ms' % (seconds * 1e3) + if seconds < 60.0: + return '%.0f sec' % seconds + + minutes, seconds = divmod(seconds, 60.0) + return '%.0f min %.0f sec' % (minutes, seconds) + + class Regrtest: """Execute a test suite. @@ -107,14 +117,6 @@ class Regrtest: self.skipped.append(test) self.resource_denieds.append(test) - def time_delta(self, ceil=False): - seconds = time.monotonic() - self.start_time - if ceil: - seconds = math.ceil(seconds) - else: - seconds = int(seconds) - return datetime.timedelta(seconds=seconds) - def display_progress(self, test_index, test): if self.ns.quiet: return @@ -122,12 +124,14 @@ class Regrtest: fmt = "{time} [{test_index:{count_width}}{test_count}/{nbad}] {test_name}" else: fmt = "{time} [{test_index:{count_width}}{test_count}] {test_name}" + test_time = time.monotonic() - self.start_time + test_time = datetime.timedelta(seconds=int(test_time)) line = fmt.format(count_width=self.test_count_width, test_index=test_index, test_count=self.test_count, nbad=len(self.bad), test_name=test, - time=self.time_delta()) + time=test_time) print(line, flush=True) def parse_args(self, kwargs): @@ -286,9 +290,10 @@ class Regrtest: if self.ns.print_slow: self.test_times.sort(reverse=True) + print() print("10 slowest tests:") for time, test in self.test_times[:10]: - print("%s: %.1fs" % (test, time)) + print("- %s: %s" % (test, format_duration(time))) if self.bad: print(count(len(self.bad), "test"), "failed:") @@ -342,7 +347,7 @@ class Regrtest: previous_test = format_test_result(test, result[0]) test_time = time.monotonic() - start_time if test_time >= PROGRESS_MIN_TIME: - previous_test = "%s in %.0f sec" % (previous_test, test_time) + previous_test = "%s in %s" % (previous_test, format_duration(test_time)) elif result[0] == PASSED: # be quiet: say nothing if the test passed shortly previous_test = None @@ -418,7 +423,9 @@ class Regrtest: r.write_results(show_missing=True, summary=True, coverdir=self.ns.coverdir) - print("Total duration: %s" % self.time_delta(ceil=True)) + print() + duration = time.monotonic() - self.start_time + print("Total duration: %s" % format_duration(duration)) if self.ns.runleaks: os.system("leaks %d" % os.getpid()) -- cgit v1.2.1 From d9154139869289351286a063f67cf831087cc5e4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Aug 2016 15:42:21 +0200 Subject: regrtest: add newlines in output for readability --- Lib/test/libregrtest/main.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index edf38b4d17..92ecc5b36f 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -296,15 +296,18 @@ class Regrtest: print("- %s: %s" % (test, format_duration(time))) if self.bad: + print() print(count(len(self.bad), "test"), "failed:") printlist(self.bad) if self.environment_changed: + print() print("{} altered the execution environment:".format( count(len(self.environment_changed), "test"))) printlist(self.environment_changed) if self.skipped and not self.ns.quiet: + print() print(count(len(self.skipped), "test"), "skipped:") printlist(self.skipped) -- cgit v1.2.1 From 6601667e40acf305cffb2db8bc00bcac568ea384 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Aug 2016 16:00:12 +0200 Subject: regrtest: set interrupted to True if re-run is interrupted --- Lib/test/libregrtest/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 92ecc5b36f..0723c435db 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -254,6 +254,7 @@ class Regrtest: self.ns.verbose = True ok = runtest(self.ns, test) except KeyboardInterrupt: + self.interrupted = True # print a newline separate from the ^C print() break @@ -341,8 +342,8 @@ class Regrtest: try: result = runtest(self.ns, test) except KeyboardInterrupt: - self.accumulate_result(test, (INTERRUPTED, None)) self.interrupted = True + self.accumulate_result(test, (INTERRUPTED, None)) break else: self.accumulate_result(test, result) -- cgit v1.2.1 From efb4dbe976b8c43b6d886dc2f99c85178fcec0a9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Aug 2016 16:12:16 +0200 Subject: regrtest: add a summary of the summary, "Result: xxx" It's sometimes hard to check quickly if tests succeeded, failed or something bad happened. I added a final "Result: xxx" line which summarizes all outputs into a single line, written at the end (it should always be the last line of the output). --- Lib/test/libregrtest/main.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 0723c435db..78c52bd48a 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -431,6 +431,14 @@ class Regrtest: duration = time.monotonic() - self.start_time print("Total duration: %s" % format_duration(duration)) + if self.bad: + result = "FAILURE" + elif self.interrupted: + result = "INTERRUPTED" + else: + result = "SUCCESS" + print("Result: %s" % result) + if self.ns.runleaks: os.system("leaks %d" % os.getpid()) -- cgit v1.2.1 From ee6d5c064dc74b80559255e71a20f81d5a7fd4df Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 19 Aug 2016 17:54:25 +0200 Subject: regrtest: replace "Result:" with "Tests result:" --- Lib/test/libregrtest/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 78c52bd48a..b9d7ab4de0 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -437,7 +437,7 @@ class Regrtest: result = "INTERRUPTED" else: result = "SUCCESS" - print("Result: %s" % result) + print("Tests result: %s" % result) if self.ns.runleaks: os.system("leaks %d" % os.getpid()) -- cgit v1.2.1 From 2541d1fd5b2914c638d13b6d0b9a9ba2a979cc5a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 22 Aug 2016 14:28:52 +0200 Subject: Cleanup libregrtest * main.py: remove unused import * runtest: simplify runtest_inner() parameters, reuse ns parameter --- Lib/test/libregrtest/main.py | 1 - Lib/test/libregrtest/runtest.py | 56 +++++++++++++++-------------------------- 2 files changed, 20 insertions(+), 37 deletions(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index b9d7ab4de0..ba9e48b448 100644 --- 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 index ef1feb738a..7d5290e0c7 100644 --- a/Lib/test/libregrtest/runtest.py +++ b/Lib/test/libregrtest/runtest.py @@ -74,18 +74,12 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): 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 @@ def runtest(ns, test): 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 @@ def runtest(ns, test): 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 @@ def runtest(ns, test): 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 @@ def runtest_inner(ns, test, verbose, quiet, 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 @@ def runtest_inner(ns, test, verbose, quiet, 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 @@ def runtest_inner(ns, test, verbose, quiet, 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 -- cgit v1.2.1 From c9db6f51d304d60303b35fc483a801d24e4546f5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 22 Aug 2016 14:29:54 +0200 Subject: Issue #27829: libregrtest.save_env: flush stderr Use flush=True to try to get a warning which is missing in buildbots. Use also f-string to make the code shorter. --- Lib/test/libregrtest/save_env.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index 261c8f4753..96ad3af8df 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -277,11 +277,9 @@ class saved_test_environment: self.changed = True restore(original) if not self.quiet and not self.pgo: - print("Warning -- {} was modified by {}".format( - name, self.testname), - file=sys.stderr) + print(f"Warning -- {name} was modified by {self.testname}", + file=sys.stderr, flush=True) if self.verbose > 1: - print(" Before: {}\n After: {} ".format( - original, current), - file=sys.stderr) + print(f" Before: {original}\n After: {current} ", + file=sys.stderr, flush=True) return False -- cgit v1.2.1 From 85910de019618a6cf261de10b697d444bfc3a127 Mon Sep 17 00:00:00 2001 From: "Eric V. Smith" Date: Sat, 3 Sep 2016 09:18:34 -0400 Subject: Closes issue 27921: Disallow backslashes anywhere in f-strings. This is a temporary restriction. In 3.6 beta 2, the plan is to again allow backslashes in the string parts of f-strings, but disallow them in the expression parts. --- Lib/test/libregrtest/save_env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index 96ad3af8df..eefbc14ad2 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -280,6 +280,6 @@ class saved_test_environment: print(f"Warning -- {name} was modified by {self.testname}", file=sys.stderr, flush=True) if self.verbose > 1: - print(f" Before: {original}\n After: {current} ", + print(f" Before: {original}""\n"f" After: {current} ", file=sys.stderr, flush=True) return False -- cgit v1.2.1 From 0c5d31799ea0cc8ecf4968187f7c7e6fd3dd3d7f Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Tue, 6 Sep 2016 19:38:15 -0700 Subject: Adds test.support.PGO and skips tests that are not useful for PGO. --- Lib/test/libregrtest/main.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index ba9e48b448..dbbf72f1b5 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -473,6 +473,8 @@ class Regrtest: if self.ns.wait: input("Press any key to continue...") + support.PGO = self.ns.pgo + setup_tests(self.ns) self.find_tests(tests) -- cgit v1.2.1 From a360bf1bc1331830525d228d1cba50162bb78c79 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 8 Sep 2016 21:46:56 -0700 Subject: regrtest: log FS and locale encodings --- Lib/test/libregrtest/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index dbbf72f1b5..f0effc973c 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -1,5 +1,6 @@ import datetime import faulthandler +import locale import os import platform import random @@ -392,7 +393,10 @@ class Regrtest: "%s-endian" % sys.byteorder) print("== ", "hash algorithm:", sys.hash_info.algorithm, "64bit" if sys.maxsize > 2**32 else "32bit") - print("== ", os.getcwd()) + print("== cwd:", os.getcwd()) + print("== encodings: locale=%s, FS=%s" + % (locale.getpreferredencoding(False), + sys.getfilesystemencoding())) print("Testing with flags:", sys.flags) if self.ns.randomize: -- cgit v1.2.1 From 66bb1f875a7615c255128fb1e2fd6e9e50e4cefa Mon Sep 17 00:00:00 2001 From: "Eric V. Smith" Date: Fri, 9 Sep 2016 21:56:20 -0400 Subject: Issue 27948: Allow backslashes in the literal string portion of f-strings, but not in the expressions. Also, require expressions to begin and end with literal curly braces. --- Lib/test/libregrtest/save_env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/test/libregrtest') diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index eefbc14ad2..96ad3af8df 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -280,6 +280,6 @@ class saved_test_environment: print(f"Warning -- {name} was modified by {self.testname}", file=sys.stderr, flush=True) if self.verbose > 1: - print(f" Before: {original}""\n"f" After: {current} ", + print(f" Before: {original}\n After: {current} ", file=sys.stderr, flush=True) return False -- cgit v1.2.1