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

Skip to content

Commit d311374

Browse files
committed
Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
Patch by Mikhail Novikov.
1 parent 2201ecb commit d311374

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
@@ -665,6 +665,7 @@ Stefan Norberg
665665
Tim Northover
666666
Joe Norton
667667
Neal Norwitz
668+
Mikhail Novikov
668669
Michal Nowikowski
669670
Steffen Daode Nurpmeso
670671
Nigel O'Brian

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ Core and Builtins
127127
Library
128128
-------
129129

130+
- Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
131+
Patch by Mikhail Novikov.
132+
130133
- Issue #13447: Add a test file to host regression tests for bugs in the
131134
scripts found in the Tools directory.
132135

0 commit comments

Comments
 (0)