bpo-33718: Update regrtest from master (GH-7325) · python/cpython@137e803

@@ -8,7 +8,6 @@

88

import sys

99

import sysconfig

1010

import tempfile

11-

import textwrap

1211

import time

1312

import unittest

1413

from test.libregrtest.cmdline import _parse_args

@@ -18,6 +17,7 @@

1817

INTERRUPTED, CHILD_ERROR,

1918

PROGRESS_MIN_TIME, format_test_result)

2019

from test.libregrtest.setup import setup_tests

20+

from test.libregrtest.utils import removepy, count, format_duration, printlist

2121

from test import support

2222

try:

2323

import gc

@@ -41,16 +41,6 @@

4141

TEMPDIR = os.path.abspath(TEMPDIR)

4242434344-

def format_duration(seconds):

45-

if seconds < 1.0:

46-

return '%.0f ms' % (seconds * 1e3)

47-

if seconds < 60.0:

48-

return '%.0f sec' % seconds

49-50-

minutes, seconds = divmod(seconds, 60.0)

51-

return '%.0f min %.0f sec' % (minutes, seconds)

52-53-5444

class Regrtest:

5545

"""Execute a test suite.

5646

@@ -133,8 +123,9 @@ def display_progress(self, test_index, test):

133123134124

# "[ 51/405/1] test_tcl passed"

135125

line = f"{test_index:{self.test_count_width}}{self.test_count}"

136-

if self.bad and not self.ns.pgo:

137-

line = f"{line}/{len(self.bad)}"

126+

fails = len(self.bad) + len(self.environment_changed)

127+

if fails and not self.ns.pgo:

128+

line = f"{line}/{fails}"

138129

line = f"[{line}] {test}"

139130140131

# add the system load prefix: "load avg: 1.80 "

@@ -281,7 +272,6 @@ def rerun_failed_tests(self):

281272

self.ns.verbose = True

282273

self.ns.failfast = False

283274

self.ns.verbose3 = False

284-

self.ns.match_tests = None

285275286276

print()

287277

print("Re-running failed tests in verbose mode")

@@ -312,7 +302,7 @@ def display_result(self):

312302

return

313303314304

print()

315-

print("== Tests result ==")

305+

print("== Tests result: %s ==" % self.get_tests_result())

316306317307

if self.interrupted:

318308

print()

@@ -323,11 +313,6 @@ def display_result(self):

323313

print(count(len(omitted), "test"), "omitted:")

324314

printlist(omitted)

325315326-

if self.rerun:

327-

print()

328-

print(count(len(self.rerun), "test"), "re-run tests:")

329-

printlist(self.rerun)

330-331316

if self.good and not self.ns.quiet:

332317

print()

333318

if (not self.bad

@@ -360,6 +345,11 @@ def display_result(self):

360345

print(count(len(self.skipped), "test"), "skipped:")

361346

printlist(self.skipped)

362347348+

if self.rerun:

349+

print()

350+

print("%s:" % count(len(self.rerun), "re-run test"))

351+

printlist(self.rerun)

352+363353

def run_tests_sequential(self):

364354

if self.ns.trace:

365355

import trace

@@ -444,6 +434,21 @@ def display_header(self):

444434

% (locale.getpreferredencoding(False),

445435

sys.getfilesystemencoding()))

446436437+

def get_tests_result(self):

438+

result = []

439+

if self.bad:

440+

result.append("FAILURE")

441+

elif self.ns.fail_env_changed and self.environment_changed:

442+

result.append("ENV CHANGED")

443+444+

if self.interrupted:

445+

result.append("INTERRUPTED")

446+447+

if not result:

448+

result.append("SUCCESS")

449+450+

return ', '.join(result)

451+447452

def run_tests(self):

448453

# For a partial run, we do not need to clutter the output.

449454

if (self.ns.header

@@ -485,16 +490,7 @@ def finalize(self):

485490

print()

486491

duration = time.monotonic() - self.start_time

487492

print("Total duration: %s" % format_duration(duration))

488-489-

if self.bad:

490-

result = "FAILURE"

491-

elif self.interrupted:

492-

result = "INTERRUPTED"

493-

elif self.ns.fail_env_changed and self.environment_changed:

494-

result = "ENV CHANGED"

495-

else:

496-

result = "SUCCESS"

497-

print("Tests result: %s" % result)

493+

print("Tests result: %s" % self.get_tests_result())

498494499495

if self.ns.runleaks:

500496

os.system("leaks %d" % os.getpid())

@@ -561,37 +557,6 @@ def _main(self, tests, kwargs):

561557

sys.exit(0)

562558563559564-

def removepy(names):

565-

if not names:

566-

return

567-

for idx, name in enumerate(names):

568-

basename, ext = os.path.splitext(name)

569-

if ext == '.py':

570-

names[idx] = basename

571-572-573-

def count(n, word):

574-

if n == 1:

575-

return "%d %s" % (n, word)

576-

else:

577-

return "%d %ss" % (n, word)

578-579-580-

def printlist(x, width=70, indent=4, file=None):

581-

"""Print the elements of iterable x to stdout.

582-583-

Optional arg width (default 70) is the maximum line length.

584-

Optional arg indent (default 4) is the number of blanks with which to

585-

begin each line.

586-

"""

587-588-

blanks = ' ' * indent

589-

# Print the sorted list: 'x' may be a '--random' list or a set()

590-

print(textwrap.fill(' '.join(str(elt) for elt in sorted(x)), width,

591-

initial_indent=blanks, subsequent_indent=blanks),

592-

file=file)

593-594-595560

def main(tests=None, **kwargs):

596561

"""Run the Python suite."""

597562

Regrtest().main(tests=tests, **kwargs)