Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 049242b

Browse files
committed
Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
Patch by Mikhail Novikov.
2 parents 49ac6f4 + d311374 commit 049242b

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lib/lib2to3/tests/test_parser.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
# Testing imports
1212
from . import support
1313
from .support import driver, test_dir
14+
from test.support import verbose
1415

1516
# Python imports
1617
import os
18+
import sys
1719
import unittest
20+
import warnings
21+
import subprocess
1822

1923
# Local imports
2024
from lib2to3.pgen2 import tokenize
@@ -171,10 +175,12 @@ def test_all_project_files(self):
171175
try:
172176
tree = driver.parse_string(source)
173177
except ParseError as err:
174-
print('ParseError on file', filepath, err)
178+
if verbose > 0:
179+
warnings.warn('ParseError on file %s (%s)' % (filepath, err))
175180
continue
176181
new = str(tree)
177-
if diff(filepath, new):
182+
x = diff(filepath, new)
183+
if x:
178184
self.fail("Idempotency failed: %s" % filepath)
179185

180186
def test_extended_unpacking(self):
@@ -183,6 +189,7 @@ def test_extended_unpacking(self):
183189
driver.parse_string("(z, *y, w) = m\n")
184190
driver.parse_string("for *z, m in d: pass\n")
185191

192+
186193
class TestLiterals(GrammarTest):
187194

188195
def validate(self, s):
@@ -221,7 +228,7 @@ def diff(fn, result):
221228
with open('@', 'w') as f:
222229
f.write(str(result))
223230
fn = fn.replace('"', '\\"')
224-
return os.system('diff -u "%s" @' % fn)
231+
return subprocess.call(['diff', '-u', fn, '@'], stdout=(subprocess.DEVNULL if verbose < 1 else None))
225232
finally:
226233
try:
227234
os.remove("@")

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ Stefan Norberg
725725
Tim Northover
726726
Joe Norton
727727
Neal Norwitz
728+
Mikhail Novikov
728729
Michal Nowikowski
729730
Steffen Daode Nurpmeso
730731
Nigel O'Brian

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ Core and Builtins
508508
Library
509509
-------
510510

511+
- Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
512+
Patch by Mikhail Novikov.
513+
511514
- Issue #11841: Fix comparison bug with 'rc' versions in packaging.version.
512515
Patch by Filip Gruszczyński.
513516

0 commit comments

Comments
 (0)