summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2018-01-30 17:03:12 (GMT)
committerGitHub <noreply@github.com>2018-01-30 17:03:12 (GMT)
commit1e17d4aaff5c7ca972bab437949d2bb51c5b30f7 (patch)
treedce6764ff942b2ee514812ae987be99d3fb0bd18
parent8c9bb72e8b6474ae722f7d6521cfb3cb2e26e3c5 (diff)
downloadcpython-1e17d4aaff5c7ca972bab437949d2bb51c5b30f7.zip
cpython-1e17d4aaff5c7ca972bab437949d2bb51c5b30f7.tar.gz
cpython-1e17d4aaff5c7ca972bab437949d2bb51c5b30f7.tar.bz2
compare with difflib not diff(1) (GH-5450)
-rw-r--r--Lib/lib2to3/tests/test_parser.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
index 15f5b63..0cbba26 100644
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -12,6 +12,7 @@ from .support import driver, driver_no_print_statement
from test.support import verbose
# Python imports
+import difflib
import importlib
import operator
import os
@@ -429,8 +430,8 @@ class TestParserIdempotency(support.TestCase):
except ParseError as err:
self.fail('ParseError on file %s (%s)' % (filepath, err))
new = str(tree)
- x = diff(filepath, new, encoding=encoding)
- if x:
+ if new != source:
+ print(diff_texts(source, new, filepath))
self.fail("Idempotency failed: %s" % filepath)
def test_extended_unpacking(self):
@@ -480,17 +481,12 @@ class TestGeneratorExpressions(GrammarTest):
self.validate("set(x for x in [],)")
-def diff(fn, result, encoding='utf-8'):
- try:
- with open('@', 'w', encoding=encoding, newline='\n') as f:
- f.write(str(result))
- fn = fn.replace('"', '\\"')
- return subprocess.call(['diff', '-u', fn, '@'], stdout=(subprocess.DEVNULL if verbose < 1 else None))
- finally:
- try:
- os.remove("@")
- except OSError:
- pass
+def diff_texts(a, b, filename):
+ a = a.splitlines()
+ b = b.splitlines()
+ return difflib.unified_diff(a, b, filename, filename,
+ "(original)", "(reserialized)",
+ lineterm="")
if __name__ == '__main__':