Merged revisions 76125 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r76125 | benjamin.peterson | 2009-11-05 15:26:55 -0600 (Thu, 05 Nov 2009) | 1 line handle newline issues better for comparing files ........
This commit is contained in:
parent
99c160b559
commit
9a570341ce
|
@ -12,6 +12,7 @@ from .support import driver, test_dir
|
||||||
|
|
||||||
# Python imports
|
# Python imports
|
||||||
import os
|
import os
|
||||||
|
import io
|
||||||
|
|
||||||
# Local imports
|
# Local imports
|
||||||
from lib2to3.pgen2 import tokenize
|
from lib2to3.pgen2 import tokenize
|
||||||
|
@ -149,15 +150,13 @@ class TestParserIdempotency(support.TestCase):
|
||||||
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:
|
||||||
encoding = tokenize.detect_encoding(fp.readline)[0]
|
encoding = tokenize.detect_encoding(fp.readline)[0]
|
||||||
fp.seek(0)
|
self.assertTrue(encoding is not None,
|
||||||
|
"can't detect encoding for %s" % filepath)
|
||||||
|
with io.open(filepath, "r", encoding=encoding) as fp:
|
||||||
source = fp.read()
|
source = fp.read()
|
||||||
if encoding:
|
|
||||||
source = source.decode(encoding)
|
|
||||||
tree = driver.parse_string(source)
|
tree = driver.parse_string(source)
|
||||||
new = unicode(tree)
|
new = unicode(tree)
|
||||||
if encoding:
|
if diff(filepath, new, encoding):
|
||||||
new = new.encode(encoding)
|
|
||||||
if diff(filepath, new):
|
|
||||||
self.fail("Idempotency failed: %s" % filepath)
|
self.fail("Idempotency failed: %s" % filepath)
|
||||||
|
|
||||||
def test_extended_unpacking(self):
|
def test_extended_unpacking(self):
|
||||||
|
@ -199,8 +198,8 @@ class TestLiterals(GrammarTest):
|
||||||
self.validate(s)
|
self.validate(s)
|
||||||
|
|
||||||
|
|
||||||
def diff(fn, result):
|
def diff(fn, result, encoding):
|
||||||
f = open("@", "wb")
|
f = io.open("@", "w", encoding=encoding)
|
||||||
try:
|
try:
|
||||||
f.write(result)
|
f.write(result)
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in New Issue