mirror of https://github.com/python/cpython
compare with difflib not diff(1) (GH-5450)
This commit is contained in:
parent
8c9bb72e8b
commit
1e17d4aaff
|
@ -12,6 +12,7 @@ from .support import driver, driver_no_print_statement
|
||||||
from test.support import verbose
|
from test.support import verbose
|
||||||
|
|
||||||
# Python imports
|
# Python imports
|
||||||
|
import difflib
|
||||||
import importlib
|
import importlib
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
|
@ -429,8 +430,8 @@ class TestParserIdempotency(support.TestCase):
|
||||||
except ParseError as err:
|
except ParseError as err:
|
||||||
self.fail('ParseError on file %s (%s)' % (filepath, err))
|
self.fail('ParseError on file %s (%s)' % (filepath, err))
|
||||||
new = str(tree)
|
new = str(tree)
|
||||||
x = diff(filepath, new, encoding=encoding)
|
if new != source:
|
||||||
if x:
|
print(diff_texts(source, new, filepath))
|
||||||
self.fail("Idempotency failed: %s" % filepath)
|
self.fail("Idempotency failed: %s" % filepath)
|
||||||
|
|
||||||
def test_extended_unpacking(self):
|
def test_extended_unpacking(self):
|
||||||
|
@ -480,17 +481,12 @@ class TestGeneratorExpressions(GrammarTest):
|
||||||
self.validate("set(x for x in [],)")
|
self.validate("set(x for x in [],)")
|
||||||
|
|
||||||
|
|
||||||
def diff(fn, result, encoding='utf-8'):
|
def diff_texts(a, b, filename):
|
||||||
try:
|
a = a.splitlines()
|
||||||
with open('@', 'w', encoding=encoding, newline='\n') as f:
|
b = b.splitlines()
|
||||||
f.write(str(result))
|
return difflib.unified_diff(a, b, filename, filename,
|
||||||
fn = fn.replace('"', '\\"')
|
"(original)", "(reserialized)",
|
||||||
return subprocess.call(['diff', '-u', fn, '@'], stdout=(subprocess.DEVNULL if verbose < 1 else None))
|
lineterm="")
|
||||||
finally:
|
|
||||||
try:
|
|
||||||
os.remove("@")
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue