"""
os.chdir(Path(__file__).resolve().parent)
- result = subprocess.Popen([sys.executable, "rtest.py"],
- stderr=subprocess.PIPE, universal_newlines=True)
- text = result.communicate()[1]
+ with subprocess.Popen([sys.executable, "rtest.py"], stderr=subprocess.PIPE,
+ universal_newlines=True) as result:
+ text = result.communicate()[1]
print(text)
assert "Layout failures: 0" in text
# FIXME: re-enable when all tests pass on all platforms
# ask the VRML back end to handle a simple graph, using the above as the
# current working directory
- p = subprocess.Popen(["dot", "-Tvrml", "-o", os.devnull], cwd=t)
- p.communicate("digraph { a -> b; }")
+ with subprocess.Popen(["dot", "-Tvrml", "-o", os.devnull], cwd=t) as p:
+ p.communicate("digraph { a -> b; }")
- # Graphviz should not have caused a segfault
- assert p.returncode != -signal.SIGSEGV, "Graphviz segfaulted"
+ # Graphviz should not have caused a segfault
+ assert p.returncode != -signal.SIGSEGV, "Graphviz segfaulted"
def test_797():
"""
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz (should fail)
- p = subprocess.Popen(["dot", "-Tsvg", "-o", os.devnull, input],
- stderr=subprocess.PIPE, universal_newlines=True)
- _, output = p.communicate()
+ with subprocess.Popen(["dot", "-Tsvg", "-o", os.devnull, input],
+ stderr=subprocess.PIPE, universal_newlines=True) as p:
+ _, output = p.communicate()
- assert p.returncode != 0, "Graphviz accepted broken input"
+ assert p.returncode != 0, "Graphviz accepted broken input"
assert "syntax error in line 17 near '\\'" in output, \
'error message did not identify correct location'
assert input1.exists(), "unexpectedly missing test case"
# ask Graphviz to process it
- p = subprocess.Popen(["dot", "-Tsvg", input1], stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, universal_newlines=True)
- stdout1, stderr = p.communicate()
+ with subprocess.Popen(["dot", "-Tsvg", input1], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, universal_newlines=True) as p:
+ stdout1, stderr = p.communicate()
- assert p.returncode == 0, "failed to process a headport edge"
+ assert p.returncode == 0, "failed to process a headport edge"
assert stderr.strip() == "", "emitted an error for a legal graph"
assert input2.exists(), "unexpectedly missing test case"
# process it identically
- p = subprocess.Popen(["dot", "-Tsvg", input2], stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, universal_newlines=True)
- stdout2, stderr = p.communicate()
+ with subprocess.Popen(["dot", "-Tsvg", input2], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, universal_newlines=True) as p:
+ stdout2, stderr = p.communicate()
- assert p.returncode == 0, "failed to process a headport edge"
+ assert p.returncode == 0, "failed to process a headport edge"
assert stderr.strip() == "", "emitted an error for a legal graph"
"""
# start Graphviz
- p = subprocess.Popen(["dot", "-Tsvg", "-o", os.devnull],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- universal_newlines=True)
+ with subprocess.Popen(["dot", "-Tsvg", "-o", os.devnull],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, universal_newlines=True) as p:
- # pass it some input that uses the SVG color scheme
- _, stderr = p.communicate('graph g { colorscheme="svg"; }')
+ # pass it some input that uses the SVG color scheme
+ _, stderr = p.communicate('graph g { colorscheme="svg"; }')
- assert p.returncode == 0, "Graphviz exited with non-zero status"
+ assert p.returncode == 0, "Graphviz exited with non-zero status"
assert stderr.strip() == "", "SVG color scheme use caused warnings"
input = "1594.gvpr"
# run GVPR with our (malformed) input program
- p = subprocess.Popen(["gvpr", "-f", input], stdin=subprocess.PIPE,
- cwd=os.path.join(os.path.dirname(__file__)),
- stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
- _, stderr = p.communicate()
+ with subprocess.Popen(["gvpr", "-f", input], stdin=subprocess.PIPE,
+ cwd=os.path.join(os.path.dirname(__file__)),
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines=True) as p:
+ _, stderr = p.communicate()
- assert p.returncode != 0, "GVPR did not reject malformed program"
+ assert p.returncode != 0, "GVPR did not reject malformed program"
assert "line 3:" in stderr, \
"GVPR did not identify correct line of syntax error"
"""
# validate the file
- p = subprocess.Popen(["xmllint", "--nonet", "--noout", "--html", "--valid",
- src], stderr=subprocess.PIPE, universal_newlines=True)
- _, stderr = p.communicate()
+ with subprocess.Popen(["xmllint", "--nonet", "--noout", "--html", "--valid",
+ src], stderr=subprocess.PIPE,
+ universal_newlines=True) as p:
+ _, stderr = p.communicate()
- # expect it to succeed
- assert p.returncode == 0
+ # expect it to succeed
+ assert p.returncode == 0
assert stderr == ""
def test_1855():
assert input.exists(), "unexpectedly missing test case"
# use Circo to translate it to DOT
- p = subprocess.Popen(["dot", "-Kcirco", "-Tgv", "-o", os.devnull, input],
- stderr=subprocess.PIPE, universal_newlines=True)
- _, stderr = p.communicate()
+ with subprocess.Popen(["dot", "-Kcirco", "-Tgv", "-o", os.devnull, input],
+ stderr=subprocess.PIPE, universal_newlines=True) as p:
+ _, stderr = p.communicate()
- assert p.returncode != 0, "graph that generates overflow was accepted"
+ assert p.returncode != 0, "graph that generates overflow was accepted"
assert "area too large" in stderr, "missing/incorrect error message"
"""
run Dot with the given input and return its exit status and stderr
"""
- p = subprocess.Popen(["dot", "-Tsvg", "-o", os.devnull],
- stdin=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
- _, stderr = p.communicate(input)
- return p.returncode, stderr
+ with subprocess.Popen(["dot", "-Tsvg", "-o", os.devnull],
+ stdin=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines=True) as p:
+ _, stderr = p.communicate(input)
+ return p.returncode, stderr
# Graphviz should accept all legal values for this attribute
for align in ("left", "right", "center"):
# run edgepaint with an invalid option, `-rabbit`, that happens to have the
# same first character as valid options
args = ["edgepaint", "-rabbit"]
- p = subprocess.Popen(args, stdin=subprocess.PIPE, universal_newlines=True)
- p.communicate(input)
+ with subprocess.Popen(args, stdin=subprocess.PIPE,
+ universal_newlines=True) as p:
+ p.communicate(input)
- assert p.returncode != 0, "edgepaint incorrectly accepted '-rabbit'"
+ assert p.returncode != 0, "edgepaint incorrectly accepted '-rabbit'"
@pytest.mark.xfail(strict=not is_ndebug_defined()) # FIXME
def test_1990():
"}"
# run it through Graphviz
- p = subprocess.Popen(["dot", "-Tcanon", "-o", os.devnull],
- stdin=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
- _, stderr = p.communicate(input)
+ with subprocess.Popen(["dot", "-Tcanon", "-o", os.devnull],
+ stdin=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines=True) as p:
+ _, stderr = p.communicate(input)
- assert p.returncode != 0, "layout on subgraph was incorrectly accepted"
+ assert p.returncode != 0, "layout on subgraph was incorrectly accepted"
assert "layout attribute is invalid except on the root graph" in stderr, \
"expected warning not found"
"}"
# ensure this one does not trigger warnings
- p = subprocess.Popen(["dot", "-Tcanon", "-o", os.devnull],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- universal_newlines=True)
- stdout, stderr = p.communicate(input)
+ with subprocess.Popen(["dot", "-Tcanon", "-o", os.devnull],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, universal_newlines=True) as p:
+ stdout, stderr = p.communicate(input)
- assert p.returncode == 0, "correct layout use was rejected"
+ assert p.returncode == 0, "correct layout use was rejected"
assert stdout.strip() == "", "unexpected output"
assert "layout attribute is invalid except on the root graph" not in stderr, \