- Re-enable lib2to3's test_parser.py tests, though with an expected failure

(see issue 13125).
This commit is contained in:
Barry Warsaw 2011-10-07 15:14:53 -04:00
parent dd07732af5
commit cb9c5ba736
3 changed files with 20 additions and 10 deletions

View File

@ -14,6 +14,7 @@ from .support import driver, test_dir
# Python imports # Python imports
import os import os
import unittest
# Local imports # Local imports
from lib2to3.pgen2 import tokenize from lib2to3.pgen2 import tokenize
@ -157,6 +158,8 @@ class TestParserIdempotency(support.TestCase):
"""A cut-down version of pytree_idempotency.py.""" """A cut-down version of pytree_idempotency.py."""
# Issue 13125
@unittest.expectedFailure
def test_all_project_files(self): def test_all_project_files(self):
for filepath in support.all_project_files(): for filepath in support.all_project_files():
with open(filepath, "rb") as fp: with open(filepath, "rb") as fp:
@ -165,8 +168,11 @@ class TestParserIdempotency(support.TestCase):
"can't detect encoding for %s" % filepath) "can't detect encoding for %s" % filepath)
with open(filepath, "r") as fp: with open(filepath, "r") as fp:
source = fp.read() source = fp.read()
source = source.decode(encoding) try:
tree = driver.parse_string(source) tree = driver.parse_string(source)
except ParseError as err:
print('ParseError on file', filepath, err)
continue
new = str(tree) new = str(tree)
if encoding: if encoding:
new = new.encode(encoding) new = new.encode(encoding)
@ -212,14 +218,14 @@ class TestLiterals(GrammarTest):
self.validate(s) self.validate(s)
def diff(fn, result, encoding): def diff(fn, result):
f = open("@", "w")
try:
f.write(result.encode(encoding))
finally:
f.close()
try: try:
with open('@', 'w') as f:
f.write(str(result))
fn = fn.replace('"', '\\"') fn = fn.replace('"', '\\"')
return os.system('diff -u "%s" @' % fn) return os.system('diff -u "%s" @' % fn)
finally: finally:
os.remove("@") try:
os.remove("@")
except OSError:
pass

View File

@ -1,6 +1,7 @@
# Skipping test_parser and test_all_fixers # Skipping test_parser and test_all_fixers
# because of running # because of running
from lib2to3.tests import (test_fixers, test_pytree, test_util, test_refactor, from lib2to3.tests import (test_fixers, test_pytree, test_util, test_refactor,
test_parser,
test_main as test_main_) test_main as test_main_)
import unittest import unittest
from test.support import run_unittest from test.support import run_unittest
@ -8,7 +9,7 @@ from test.support import run_unittest
def suite(): def suite():
tests = unittest.TestSuite() tests = unittest.TestSuite()
loader = unittest.TestLoader() 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_): test_main_):
tests.addTests(loader.loadTestsFromModule(m)) tests.addTests(loader.loadTestsFromModule(m))
return tests return tests

View File

@ -1382,6 +1382,9 @@ Extension Modules
Tests 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 #12656: Add tests for IPv6 and Unix sockets to test_asyncore.
- Issue #6484: Add unit tests for mailcap module (patch by Gregory Nofi) - Issue #6484: Add unit tests for mailcap module (patch by Gregory Nofi)