[Python-checkins] cpython: - Re-enable lib2to3's test_parser.py tests, though with an expected failure

barry.warsaw python-checkins at python.org
Fri Oct 7 21:27:06 CEST 2011


http://hg.python.org/cpython/rev/914d3f035887
changeset:   72803:914d3f035887
parent:      72795:16118ea2192b
user:        Barry Warsaw <barry at python.org>
date:        Fri Oct 07 15:14:53 2011 -0400
summary:
  - Re-enable lib2to3's test_parser.py tests, though with an expected failure
  (see issue 13125).

files:
  Lib/lib2to3/tests/test_parser.py |  24 ++++++++++++-------
  Lib/test/test_lib2to3.py         |   3 +-
  Misc/NEWS                        |   3 ++
  3 files changed, 20 insertions(+), 10 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
@@ -14,6 +14,7 @@
 
 # Python imports
 import os
+import unittest
 
 # Local imports
 from lib2to3.pgen2 import tokenize
@@ -157,6 +158,8 @@
 
     """A cut-down version of pytree_idempotency.py."""
 
+    # Issue 13125
+    @unittest.expectedFailure
     def test_all_project_files(self):
         for filepath in support.all_project_files():
             with open(filepath, "rb") as fp:
@@ -165,8 +168,11 @@
                             "can't detect encoding for %s" % filepath)
             with open(filepath, "r") as fp:
                 source = fp.read()
-                source = source.decode(encoding)
-            tree = driver.parse_string(source)
+            try:
+                tree = driver.parse_string(source)
+            except ParseError as err:
+                print('ParseError on file', filepath, err)
+                continue
             new = str(tree)
             if encoding:
                 new = new.encode(encoding)
@@ -212,14 +218,14 @@
         self.validate(s)
 
 
-def diff(fn, result, encoding):
-    f = open("@", "w")
+def diff(fn, result):
     try:
-        f.write(result.encode(encoding))
-    finally:
-        f.close()
-    try:
+        with open('@', 'w') as f:
+            f.write(str(result))
         fn = fn.replace('"', '\\"')
         return os.system('diff -u "%s" @' % fn)
     finally:
-        os.remove("@")
+        try:
+            os.remove("@")
+        except OSError:
+            pass
diff --git a/Lib/test/test_lib2to3.py b/Lib/test/test_lib2to3.py
--- a/Lib/test/test_lib2to3.py
+++ b/Lib/test/test_lib2to3.py
@@ -1,6 +1,7 @@
 # Skipping test_parser and test_all_fixers
 # because of running
 from lib2to3.tests import (test_fixers, test_pytree, test_util, test_refactor,
+                           test_parser,
                            test_main as test_main_)
 import unittest
 from test.support import run_unittest
@@ -8,7 +9,7 @@
 def suite():
     tests = unittest.TestSuite()
     loader = unittest.TestLoader()
-    for m in (test_fixers, test_pytree,test_util, test_refactor,
+    for m in (test_fixers, test_pytree,test_util, test_refactor, test_parser,
               test_main_):
         tests.addTests(loader.loadTestsFromModule(m))
     return tests
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1382,6 +1382,9 @@
 Tests
 -----
 
+- Re-enable lib2to3's test_parser.py tests, though with an expected failure
+  (see issue 13125).
+
 - Issue #12656: Add tests for IPv6 and Unix sockets to test_asyncore.
 
 - Issue #6484: Add unit tests for mailcap module (patch by Gregory Nofi)

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


More information about the Python-checkins mailing list