]> granicus.if.org Git - graphviz/commitdiff
tests: abstract the common case for running 'gvpr'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 14 Mar 2022 02:20:55 +0000 (19:20 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 19 Mar 2022 17:26:02 +0000 (10:26 -0700)
rtest/gvtest.py
rtest/test_regression.py

index 94fef95186c601c5eb91064663fbe621d8e38852..7e6bc62924d1c8028f452d71f659e9de76d3c309 100644 (file)
@@ -4,6 +4,7 @@ import os
 from pathlib import Path
 import platform
 import shlex
+import shutil
 import subprocess
 import sys
 import sysconfig
@@ -98,6 +99,16 @@ def dot(T: str, source_file: Optional[Path] = None, source: Optional[str] = None
 
   return subprocess.check_output(args, **kwargs)
 
+def gvpr(program: Path) -> str:
+  """run a GVPR program on empty input"""
+
+  assert shutil.which("gvpr") is not None, \
+    "attempt to run GVPR without it available"
+
+  return subprocess.check_output(["gvpr", "-f", program],
+                                 stdin=subprocess.DEVNULL,
+                                 universal_newlines=True)
+
 def run_c(src: Path, args: List[str] = None, input: str = "",
           cflags: List[str] = None, link: List[str] = None
           ) -> Tuple[str, str]:
index da2e0ec1633c3091df49b420f14c9f3d04e6978c..079fe260868e6e08bef578436eb9e0fb2cb73386 100644 (file)
@@ -22,7 +22,7 @@ import xml.etree.ElementTree as ET
 import pytest
 
 sys.path.append(os.path.dirname(__file__))
-from gvtest import dot, ROOT, run_c #pylint: disable=C0413
+from gvtest import dot, gvpr, ROOT, run_c #pylint: disable=C0413
 
 def is_mingw() -> bool:
   """
@@ -628,7 +628,7 @@ def test_1780():
   clustg = Path(__file__).resolve().parent.parent / "cmd/gvpr/lib/clustg"
 
   # GVPR should not fail when given this path
-  subprocess.check_call(["gvpr", "-f", clustg], stdin=subprocess.DEVNULL)
+  gvpr(clustg)
 
 def test_1783():
   """
@@ -1446,9 +1446,7 @@ def test_2185_1():
   assert script.exists(), "missing test case"
 
   # run this with NUL input, checking output is valid UTF-8
-  _ = subprocess.check_output(["gvpr", "-f", script],
-                              stdin=subprocess.DEVNULL,
-                              universal_newlines=True)
+  gvpr(script)
 
 def test_2185_2():
   """