From: Matthew Fernandez Date: Thu, 13 May 2021 02:28:30 +0000 (-0700) Subject: replace use of diff in test_reference with difflib X-Git-Tag: 2.47.2~4^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc27f0ef2a4153c5dd61aa0544e82aa8282b6203;p=graphviz replace use of diff in test_reference with difflib This is a step towards removing diff as a test dependency, so Windows users do not need to install it. Related to #2069. --- diff --git a/tests/reference/test_reference.py b/tests/reference/test_reference.py index 26c5bdd95..860e37765 100644 --- a/tests/reference/test_reference.py +++ b/tests/reference/test_reference.py @@ -1,5 +1,7 @@ +import difflib from pathlib import Path import subprocess +import sys import tempfile import pytest @@ -133,4 +135,13 @@ def test_reference(src: str, format: str, reference: str): if output.suffix == ".png": subprocess.check_call(["diffimg", ref, output]) else: - subprocess.check_call(["diff", "--unified", ref, output]) + fail = False + with open(ref, 'rt') as a: + with open(output, 'rt') as b: + for line in difflib.unified_diff(a.read(), b.read(), + fromfile=str(ref), + tofile=str(output)): + sys.stderr.write(f"{line}\n") + fail = True + if fail: + raise RuntimeError(f"diff {ref} {output} failed")