]> granicus.if.org Git - graphviz/commitdiff
tests: rewrite 'Popen;communicate' code to use 'check_output'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 7 Dec 2021 01:30:04 +0000 (17:30 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 12 Dec 2021 01:28:52 +0000 (17:28 -0800)
When this testing code was first written, it looks like it was overlooked that
`check_output` supports the `input` parameter from Python 3.4 onwards. With
this, the relevant code can be written more concisely.

rtest/test_examples.py
rtest/test_regression.py

index 9f98900437dbed8bce2da406948a13d5c3e3ae65..ef2b7439ddef973785b288b8a15e1552e302d88c 100644 (file)
@@ -92,11 +92,8 @@ def test_gvpr_clustg():
   input = "digraph { N1; N2; N1 -> N2; N3; }"
 
   # run GVPR on this input
-  p = subprocess.Popen(["gvpr", "-f", path], stdin=subprocess.PIPE,
-    stdout=subprocess.PIPE, cwd=wd, universal_newlines=True)
-  output, _ = p.communicate(input)
-
-  assert p.returncode == 0, "GVPR exited with non-zero status"
+  output = subprocess.check_output(["gvpr", "-f", path], input=input, cwd=wd,
+    universal_newlines=True)
 
   assert output.strip() == 'strict digraph "clust%1" {\n' \
                            '\tnode [_cnt=0];\n' \
index 2749de983affd26817c4ede0fe6d61156e13277a..f20240f2c17095883ffbe8ad29dfbfd45a6e6586 100644 (file)
@@ -266,16 +266,12 @@ def test_517():
     '}'
 
   # translate it to GXL
-  p = subprocess.Popen(["gv2gxl"], stdin=subprocess.PIPE,
-    stdout=subprocess.PIPE, universal_newlines=True)
-  gxl, _ = p.communicate(input)
-  assert p.returncode == 0
+  gxl = subprocess.check_output(["gv2gxl"], input=input,
+    universal_newlines=True)
 
   # translate this back to Dot
-  p = subprocess.Popen(["gxl2gv"], stdin=subprocess.PIPE,
-    stdout=subprocess.PIPE, universal_newlines=True)
-  dot_output, _ = p.communicate(gxl)
-  assert p.returncode == 0
+  dot_output = subprocess.check_output(["gxl2gv"], input=gxl,
+    universal_newlines=True)
 
   # the result should have both expected labels somewhere
   assert \
@@ -349,11 +345,7 @@ def test_1276():
         '}'
 
   # process this to GML
-  p = subprocess.Popen(["gv2gml"], stdin=subprocess.PIPE,
-                       stdout=subprocess.PIPE, universal_newlines=True)
-  gml, _ = p.communicate(src)
-
-  assert p.returncode == 0, "gv2gml failed"
+  gml = subprocess.check_output(["gv2gml"], input=src, universal_newlines=True)
 
   # the unescaped label should not appear in the output
   assert '""Label""' not in gml, "quotes not escaped in label"
@@ -737,11 +729,11 @@ def test_1876():
   input = "graph { a }"
 
   # process this with fdp
-  p = subprocess.Popen(["fdp"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-    universal_newlines=True)
-  output, _ = p.communicate(input)
-
-  assert p.returncode == 0, "fdp failed to process trivial graph"
+  try:
+    output = subprocess.check_output(["fdp"], input=input,
+      universal_newlines=True)
+  except subprocess.CalledProcessError as e:
+    raise RuntimeError("fdp failed to process trivial graph") from e
 
   # we should not see any internal names like "%3"
   assert "%" not in output, "internal name in fdp output"
@@ -928,9 +920,8 @@ def test_1907():
   input = "digraph { A -> B -> C }"
 
   # generate an SVG from this input with twopi
-  p = subprocess.Popen(["twopi", "-Tsvg"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+  output = subprocess.check_output(["twopi", "-Tsvg"], input=input,
     universal_newlines=True)
-  output, _ = p.communicate(input)
 
   assert "<title>A&#45;&gt;B</title>" in output, \
     "element title not found in SVG"
@@ -947,11 +938,8 @@ def test_1909():
   graph = Path(__file__).parent / "1909.dot"
 
   # run GVPR with the given input
-  p = subprocess.Popen(["gvpr", "-c", "-f", prog, graph],
-    stdout=subprocess.PIPE, universal_newlines=True)
-  output, _ = p.communicate()
-
-  assert p.returncode == 0, "gvpr failed to process graph"
+  output = subprocess.check_output(["gvpr", "-c", "-f", prog, graph],
+    universal_newlines=True)
 
   # we should have produced this graph without names like "%2" in it
   assert output == "// begin\n" \