[Python-checkins] cpython (3.2): Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.

antoine.pitrou python-checkins at python.org
Mon Feb 27 20:00:47 CET 2012


http://hg.python.org/cpython/rev/2fd68efac05a
changeset:   75320:2fd68efac05a
branch:      3.2
parent:      75317:b4321f93e3f2
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Mon Feb 27 19:55:36 2012 +0100
summary:
  Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
Patch by Mikhail Novikov.

files:
  Lib/lib2to3/tests/test_parser.py |  13 ++++++++++---
  Misc/ACKS                        |   1 +
  Misc/NEWS                        |   3 +++
  3 files changed, 14 insertions(+), 3 deletions(-)


diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -11,10 +11,14 @@
 # Testing imports
 from . import support
 from .support import driver, test_dir
+from test.support import verbose
 
 # Python imports
 import os
+import sys
 import unittest
+import warnings
+import subprocess
 
 # Local imports
 from lib2to3.pgen2 import tokenize
@@ -171,10 +175,12 @@
             try:
                 tree = driver.parse_string(source)
             except ParseError as err:
-                print('ParseError on file', filepath, err)
+                if verbose > 0:
+                    warnings.warn('ParseError on file %s (%s)' % (filepath, err))
                 continue
             new = str(tree)
-            if diff(filepath, new):
+            x = diff(filepath, new)
+            if x:
                 self.fail("Idempotency failed: %s" % filepath)
 
     def test_extended_unpacking(self):
@@ -183,6 +189,7 @@
         driver.parse_string("(z, *y, w) = m\n")
         driver.parse_string("for *z, m in d: pass\n")
 
+
 class TestLiterals(GrammarTest):
 
     def validate(self, s):
@@ -221,7 +228,7 @@
         with open('@', 'w') as f:
             f.write(str(result))
         fn = fn.replace('"', '\\"')
-        return os.system('diff -u "%s" @' % fn)
+        return subprocess.call(['diff', '-u', fn, '@'], stdout=(subprocess.DEVNULL if verbose < 1 else None))
     finally:
         try:
             os.remove("@")
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -665,6 +665,7 @@
 Tim Northover
 Joe Norton
 Neal Norwitz
+Mikhail Novikov
 Michal Nowikowski
 Steffen Daode Nurpmeso
 Nigel O'Brian
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -127,6 +127,9 @@
 Library
 -------
 
+- Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
+  Patch by Mikhail Novikov.
+
 - Issue #13447: Add a test file to host regression tests for bugs in the
   scripts found in the Tools directory.
 

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


More information about the Python-checkins mailing list