1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
"""tests that examples provided with Graphviz compile correctly"""
import os
import platform
import subprocess
import sys
from pathlib import Path
import pytest
sys.path.append(os.path.dirname(__file__))
from gvtest import ( # pylint: disable=wrong-import-position
is_static_build,
run,
run_c,
run_raw,
which,
)
@pytest.mark.parametrize(
"src", ["demo.c", "dot.c", "example.c", "neatopack.c", "simple.c"]
)
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_compile_example(src):
"""try to compile the example"""
# construct an absolute path to the example
filepath = Path(__file__).parent.resolve() / ".." / "dot.demo" / src
libs = ["cgraph", "gvc"]
# run the example
args = ["-Kneato"] if src in ["demo.c", "dot.c"] else []
if platform.system() == "Windows":
cflags = ["-DGVDLL"]
else:
cflags = None
_, _ = run_c(filepath, args, "graph {a -- b}", cflags=cflags, link=libs)
@pytest.mark.parametrize(
"src",
[
"addrings",
"attr",
"bbox",
"bipart",
"chkedges",
"clustg",
"collapse",
"cycle",
"deghist",
"delmulti",
"depath",
"flatten",
"group",
"indent",
"path",
"scale",
"span",
"treetoclust",
"addranks",
"anon",
"bb",
"chkclusters",
"cliptree",
"col",
"color",
"dechain",
"deledges",
"delnodes",
"dijkstra",
"get-layers-list",
"knbhd",
"maxdeg",
"rotate",
"scalexy",
"topon",
],
)
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_gvpr_example(src):
"""check GVPR can parse the given example"""
# construct a relative path to the example because gvpr on Windows does not
# support absolute paths (#1780)
path = Path("cmd/gvpr/lib") / src
wd = Path(__file__).parent.parent.resolve()
# run GVPR with the given script
run_raw(["gvpr", "-f", path], stdin=subprocess.DEVNULL, cwd=wd)
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_gvpr_clustg():
"""check cmd/gvpr/lib/clustg works"""
# construct a relative path to clustg because gvpr on Windows does not
# support absolute paths (#1780)
path = Path("cmd/gvpr/lib/clustg")
wd = Path(__file__).parent.parent.resolve()
# some sample input
input = "digraph { N1; N2; N1 -> N2; N3; }"
# run GVPR on this input
output = run(["gvpr", "-f", path], input=input, cwd=wd)
assert (
output.strip() == 'strict digraph "clust%1" {\n'
"\tnode [_cnt=0];\n"
"\tedge [_cnt=0];\n"
"\tN1 -> N2\t[_cnt=1];\n"
"\tN3;\n"
"}"
), "unexpected output"
|