Skip to content

Commit

Permalink
tests: add functional test for pygraphviz
Browse files Browse the repository at this point in the history
Add a functional test for `pygraphviz` that tries to use different
`graphviz` programs and output formats, in order to ensure that
`graphviz` programs and plugins are properly collected.

This complements the existing test that ensures that `pygraphviz.AGraph`
resolves the bundled copies of `graphviz` programs, but does not
test their actual use.
  • Loading branch information
rokm committed Jan 6, 2025
1 parent f5d77ef commit 470af79
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,48 @@ def test_pygraphviz_bundled_programs(pyi_builder):
""")


@importorskip("pygraphviz")
def test_pygraphviz_functional(pyi_builder, tmp_path):
# Functional test for pygraphviz that tries to use different programs and output formats to ensure that graphviz
# programs and plugins are properly collected.
pyi_builder.test_source("""
import sys
import os
import pygraphviz as pgv
output_dir = sys.argv[1] if len(sys.argv) >= 2 else '.'
print("Setting up graph...")
G = pgv.AGraph(strict=False, directed=True)
# Set default node attributes
G.graph_attr["label"] = "Name of graph"
G.node_attr["shape"] = "circle"
G.edge_attr["color"] = "red"
G.add_node("a")
G.add_edge("b", "c") # add edge (and the nodes)
print("Dumping graph to string...")
s = G.string()
print(s)
print("Test layout with default program (= neato)")
G.layout()
print("Test layout with 'dot' program")
G.layout(prog="dot")
print("Writing previously positioned graph to PNG file...")
G.draw(os.path.join(output_dir, "file.png"))
print("Using 'circo' to position, writing PS file...")
G.draw(os.path.join(output_dir, "file.ps"), prog="circo")
print("Done!")
""", app_args=[str(tmp_path)])


@importorskip("pypsexec")
def test_pypsexec(pyi_builder):
pyi_builder.test_source("""
Expand Down

0 comments on commit 470af79

Please sign in to comment.