]> granicus.if.org Git - graphviz/commitdiff
replace use of diff in test_reference with difflib
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 13 May 2021 02:28:30 +0000 (19:28 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 19 May 2021 14:42:13 +0000 (07:42 -0700)
This is a step towards removing diff as a test dependency, so Windows users do
not need to install it. Related to #2069.

tests/reference/test_reference.py

index 26c5bdd95936214380b7c3da9188b79885b6b88c..860e37765d13c050dc4dd2e58762dc856bc5b1df 100644 (file)
@@ -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")