| 1 |
""" |
| 2 |
Tests of Graphviz output against expected reference output. |
| 3 |
""" |
| 4 |
|
| 5 |
import difflib |
| 6 |
import os |
| 7 |
import sys |
| 8 |
from pathlib import Path |
| 9 |
|
| 10 |
import pytest |
| 11 |
|
| 12 |
sys.path.append(os.path.join(os.path.dirname(__file__), "../../tests")) |
| 13 |
from gvtest import run, run_raw # pylint: disable=wrong-import-position |
| 14 |
|
| 15 |
|
| 16 |
@pytest.mark.xfail |
| 17 |
@pytest.mark.parametrize( |
| 18 |
"src,format,reference", |
| 19 |
( |
| 20 |
('graph G {a [label="" shape=none]}', "gv", "001.001.gv"), |
| 21 |
('graph G {a [label="" shape=none]}', "xdot", "001.002.xdot"), |
| 22 |
('graph G {a [label="" shape=none]}', "png", "001.003.png"), |
| 23 |
('graph G {a [label="" shape=none]}', "svg", "001.004.svg"), |
| 24 |
('graph G {a [label="" shape=none]}', "ps", "001.005.ps"), |
| 25 |
('graph G {a [label="" shape=none]}', "cmapx", "001.006.cmapx"), |
| 26 |
('graph G {a [label="" shape=plaintext]}', "xdot", "002.001.xdot"), |
| 27 |
('graph G {a [label="" shape=point]}', "xdot", "003.001.xdot"), |
| 28 |
('graph G {a [label="" shape=box]}', "xdot", "004.001.xdot"), |
| 29 |
('graph G {a [label="" shape=rect]}', "xdot", "005.001.xdot"), |
| 30 |
('graph G {a [label="" shape=rectangle]}', "xdot", "006.001.xdot"), |
| 31 |
('graph G {a [label="" shape=ellipse]}', "xdot", "007.001.xdot"), |
| 32 |
('graph G {a [label="" shape=circle]}', "xdot", "008.001.xdot"), |
| 33 |
('graph G {a [label="" shape=triangle]}', "xdot", "009.001.xdot"), |
| 34 |
('graph G {a [label="" shape=invtriangle]}', "xdot", "010.001.xdot"), |
| 35 |
('graph G {a [label="" shape=diamond]}', "xdot", "011.001.xdot"), |
| 36 |
('graph G {a [label="" shape=trapezium]}', "xdot", "012.001.xdot"), |
| 37 |
('graph G {a [label="" shape=invtrapezium]}', "xdot", "013.001.xdot"), |
| 38 |
('graph G {a [label="" shape=parallelogram]}', "xdot", "014.001.xdot"), |
| 39 |
('graph G {a [label="" shape=house]}', "xdot", "015.001.xdot"), |
| 40 |
('graph G {a [label="" shape=invhouse]}', "xdot", "016.001.xdot"), |
| 41 |
('graph G {a [label="" shape=pentagon]}', "xdot", "017.001.xdot"), |
| 42 |
('graph G {a [label="" shape=hexagon]}', "xdot", "018.001.xdot"), |
| 43 |
('graph G {a [label="" shape=septagon]}', "xdot", "019.001.xdot"), |
| 44 |
('graph G {a [label="" shape=octagon]}', "xdot", "020.001.xdot"), |
| 45 |
('graph G {a [label="" shape=doubleoctagon]}', "xdot", "021.001.xdot"), |
| 46 |
('graph G {a [label="" shape=doublecircle]}', "xdot", "022.001.xdot"), |
| 47 |
('graph G {a [label="" shape=tripleoctagon]}', "xdot", "023.001.xdot"), |
| 48 |
('graph G {a [label="" shape=Mdiamond]}', "xdot", "024.001.xdot"), |
| 49 |
('graph G {a [label="" shape=Msquare]}', "xdot", "025.001.xdot"), |
| 50 |
('graph G {a [label="" shape=Mcircle]}', "xdot", "026.001.xdot"), |
| 51 |
('graph G {a [label="" shape=none]}', "xdot", "027.001.xdot"), |
| 52 |
("graph G {a [label=b shape=none]}", "xdot", "028.001.xdot"), |
| 53 |
("graph G {a [shape=none]}", "xdot", "029.001.xdot"), |
| 54 |
('graph G {a [label="\\N" shape=none]}', "xdot", "030.001.xdot"), |
| 55 |
('graph G {a [label="n_of_\\G" shape=none]}', "xdot", "031.001.xdot"), |
| 56 |
('graph G {a [label="\\E\\H\\T" shape=none]}', "xdot", "032.001.xdot"), |
| 57 |
( |
| 58 |
'digraph G {node [label="" shape=none]; a->b [label="\\E"]}', |
| 59 |
"xdot", |
| 60 |
"033.001.xdot", |
| 61 |
), |
| 62 |
( |
| 63 |
'digraph G {node [label="" shape=none]; a->b [label="\\T"]}', |
| 64 |
"xdot", |
| 65 |
"034.001.xdot", |
| 66 |
), |
| 67 |
( |
| 68 |
'digraph G {node [label="" shape=none]; a->b [label="\\H"]}', |
| 69 |
"xdot", |
| 70 |
"035.001.xdot", |
| 71 |
), |
| 72 |
( |
| 73 |
'digraph G {node [label="" shape=none]; a->b [label="e_of_\\G"]}', |
| 74 |
"xdot", |
| 75 |
"036.001.xdot", |
| 76 |
), |
| 77 |
( |
| 78 |
'digraph G {node [label="" shape=none]; a->b [label="\\N"]}', |
| 79 |
"xdot", |
| 80 |
"037.001.xdot", |
| 81 |
), |
| 82 |
( |
| 83 |
'graph G {a [label="center\\naligned\\ntext" shape=none]}', |
| 84 |
"xdot", |
| 85 |
"038.001.xdot", |
| 86 |
), |
| 87 |
( |
| 88 |
'graph G {a [label="left\\laligned\\ltext" shape=none]}', |
| 89 |
"xdot", |
| 90 |
"039.001.xdot", |
| 91 |
), |
| 92 |
( |
| 93 |
'graph G {a [label="right\\raligned\\rtext" shape=none]}', |
| 94 |
"xdot", |
| 95 |
"040.001.xdot", |
| 96 |
), |
| 97 |
( |
| 98 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=none]}', |
| 99 |
"xdot", |
| 100 |
"041.001.xdot", |
| 101 |
), |
| 102 |
( |
| 103 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=""]}', |
| 104 |
"xdot", |
| 105 |
"042.001.xdot", |
| 106 |
), |
| 107 |
( |
| 108 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=normal]}', |
| 109 |
"xdot", |
| 110 |
"043.001.xdot", |
| 111 |
), |
| 112 |
( |
| 113 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=box]}', |
| 114 |
"xdot", |
| 115 |
"044.001.xdot", |
| 116 |
), |
| 117 |
( |
| 118 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=crow]}', |
| 119 |
"xdot", |
| 120 |
"045.001.xdot", |
| 121 |
), |
| 122 |
( |
| 123 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=diamond]}', |
| 124 |
"xdot", |
| 125 |
"046.001.xdot", |
| 126 |
), |
| 127 |
( |
| 128 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=dot]}', |
| 129 |
"xdot", |
| 130 |
"047.001.xdot", |
| 131 |
), |
| 132 |
( |
| 133 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=inv]}', |
| 134 |
"xdot", |
| 135 |
"048.001.xdot", |
| 136 |
), |
| 137 |
( |
| 138 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=tee]}', |
| 139 |
"xdot", |
| 140 |
"049.001.xdot", |
| 141 |
), |
| 142 |
( |
| 143 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=vee]}', |
| 144 |
"xdot", |
| 145 |
"050.001.xdot", |
| 146 |
), |
| 147 |
( |
| 148 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=lnormal]}', |
| 149 |
"xdot", |
| 150 |
"051.001.xdot", |
| 151 |
), |
| 152 |
( |
| 153 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=lbox]}', |
| 154 |
"xdot", |
| 155 |
"052.001.xdot", |
| 156 |
), |
| 157 |
( |
| 158 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=lcrow]}', |
| 159 |
"xdot", |
| 160 |
"053.001.xdot", |
| 161 |
), |
| 162 |
( |
| 163 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=ldiamond]}', |
| 164 |
"xdot", |
| 165 |
"054.001.xdot", |
| 166 |
), |
| 167 |
( |
| 168 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=ldot]}', |
| 169 |
"xdot", |
| 170 |
"055.001.xdot", |
| 171 |
), |
| 172 |
( |
| 173 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=linv]}', |
| 174 |
"xdot", |
| 175 |
"056.001.xdot", |
| 176 |
), |
| 177 |
( |
| 178 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=ltee]}', |
| 179 |
"xdot", |
| 180 |
"057.001.xdot", |
| 181 |
), |
| 182 |
( |
| 183 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=lvee]}', |
| 184 |
"xdot", |
| 185 |
"058.001.xdot", |
| 186 |
), |
| 187 |
( |
| 188 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rnormal]}', |
| 189 |
"xdot", |
| 190 |
"059.001.xdot", |
| 191 |
), |
| 192 |
( |
| 193 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rbox]}', |
| 194 |
"xdot", |
| 195 |
"060.001.xdot", |
| 196 |
), |
| 197 |
( |
| 198 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rcrow]}', |
| 199 |
"xdot", |
| 200 |
"061.001.xdot", |
| 201 |
), |
| 202 |
( |
| 203 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rdiamond]}', |
| 204 |
"xdot", |
| 205 |
"062.001.xdot", |
| 206 |
), |
| 207 |
( |
| 208 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rdot]}', |
| 209 |
"xdot", |
| 210 |
"063.001.xdot", |
| 211 |
), |
| 212 |
( |
| 213 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rinv]}', |
| 214 |
"xdot", |
| 215 |
"064.001.xdot", |
| 216 |
), |
| 217 |
( |
| 218 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rtee]}', |
| 219 |
"xdot", |
| 220 |
"065.001.xdot", |
| 221 |
), |
| 222 |
( |
| 223 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=rvee]}', |
| 224 |
"xdot", |
| 225 |
"066.001.xdot", |
| 226 |
), |
| 227 |
( |
| 228 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=onormal]}', |
| 229 |
"xdot", |
| 230 |
"067.001.xdot", |
| 231 |
), |
| 232 |
( |
| 233 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=obox]}', |
| 234 |
"xdot", |
| 235 |
"068.001.xdot", |
| 236 |
), |
| 237 |
( |
| 238 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=ocrow]}', |
| 239 |
"xdot", |
| 240 |
"069.001.xdot", |
| 241 |
), |
| 242 |
( |
| 243 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=odiamond]}', |
| 244 |
"xdot", |
| 245 |
"070.001.xdot", |
| 246 |
), |
| 247 |
( |
| 248 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=odot]}', |
| 249 |
"xdot", |
| 250 |
"071.001.xdot", |
| 251 |
), |
| 252 |
( |
| 253 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=oinv]}', |
| 254 |
"xdot", |
| 255 |
"072.001.xdot", |
| 256 |
), |
| 257 |
( |
| 258 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=otee]}', |
| 259 |
"xdot", |
| 260 |
"073.001.xdot", |
| 261 |
), |
| 262 |
( |
| 263 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=ovee]}', |
| 264 |
"xdot", |
| 265 |
"074.001.xdot", |
| 266 |
), |
| 267 |
( |
| 268 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=onormalnormal]}', |
| 269 |
"xdot", |
| 270 |
"075.001.xdot", |
| 271 |
), |
| 272 |
( |
| 273 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=oboxbox]}', |
| 274 |
"xdot", |
| 275 |
"076.001.xdot", |
| 276 |
), |
| 277 |
( |
| 278 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=ocrowcrow]}', |
| 279 |
"xdot", |
| 280 |
"077.001.xdot", |
| 281 |
), |
| 282 |
( |
| 283 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=odiamonddiamond]}', |
| 284 |
"xdot", |
| 285 |
"078.001.xdot", |
| 286 |
), |
| 287 |
( |
| 288 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=odotdot]}', |
| 289 |
"xdot", |
| 290 |
"079.001.xdot", |
| 291 |
), |
| 292 |
( |
| 293 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=oinvinv]}', |
| 294 |
"xdot", |
| 295 |
"080.001.xdot", |
| 296 |
), |
| 297 |
( |
| 298 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=oteetee]}', |
| 299 |
"xdot", |
| 300 |
"081.001.xdot", |
| 301 |
), |
| 302 |
( |
| 303 |
'digraph G {node [label="" shape=none]; a->b [arrowhead=oveevee]}', |
| 304 |
"xdot", |
| 305 |
"082.001.xdot", |
| 306 |
), |
| 307 |
( |
| 308 |
'graph G {a [label="" shape=box style=filled color=black]}', |
| 309 |
"xdot", |
| 310 |
"083.001.xdot", |
| 311 |
), |
| 312 |
( |
| 313 |
'graph G {a [label="" shape=box style=filled color=black]}', |
| 314 |
"png", |
| 315 |
"083.002.png", |
| 316 |
), |
| 317 |
( |
| 318 |
'graph G {a [label="" shape=box style=filled color=red]}', |
| 319 |
"xdot", |
| 320 |
"084.001.xdot", |
| 321 |
), |
| 322 |
( |
| 323 |
'graph G {a [label="" shape=box style=filled color=red]}', |
| 324 |
"png", |
| 325 |
"084.002.png", |
| 326 |
), |
| 327 |
( |
| 328 |
'graph G {a [label="" shape=box style=filled color=hotpink]}', |
| 329 |
"xdot", |
| 330 |
"085.001.xdot", |
| 331 |
), |
| 332 |
( |
| 333 |
'graph G {a [label="" shape=box style=filled color=hotpink]}', |
| 334 |
"png", |
| 335 |
"085.002.png", |
| 336 |
), |
| 337 |
( |
| 338 |
'graph G {a [label="" shape=box style=filled color=transparent]}', |
| 339 |
"xdot", |
| 340 |
"086.001.xdot", |
| 341 |
), |
| 342 |
( |
| 343 |
'graph G {a [label="" shape=box style=filled color=transparent]}', |
| 344 |
"png", |
| 345 |
"086.002.png", |
| 346 |
), |
| 347 |
('graph G {a [URL="" label="" shape=none]}', "cmapx", "087.001.cmapx"), |
| 348 |
('graph G {a [URL="" label="" shape=none]}', "ps", "087.002.ps"), |
| 349 |
('graph G {a [URL="" label="" shape=none]}', "svg", "087.003.svg"), |
| 350 |
('graph G {graph [URL="\\G.html"]}', "cmapx", "088.001.cmapx"), |
| 351 |
('graph G {graph [URL="\\G.html"]}', "ps", "088.002.ps"), |
| 352 |
('graph G {graph [URL="\\G.html"]}', "svg", "088.003.svg"), |
| 353 |
('graph G {a [URL="\\N.html" label="" shape=none]}', "cmapx", "089.001.cmapx"), |
| 354 |
('graph G {a [URL="\\N.html" label="" shape=none]}', "ps", "089.002.ps"), |
| 355 |
('graph G {a [URL="\\N.html" label="" shape=none]}', "svg", "089.003.svg"), |
| 356 |
( |
| 357 |
'digraph G {node [label="" shape=none]; a->b [URL="\\E.html"]}', |
| 358 |
"cmapx", |
| 359 |
"090.001.cmapx", |
| 360 |
), |
| 361 |
( |
| 362 |
'digraph G {node [label="" shape=none]; a->b [URL="\\E.html"]}', |
| 363 |
"ps", |
| 364 |
"090.002.ps", |
| 365 |
), |
| 366 |
( |
| 367 |
'digraph G {node [label="" shape=none]; a->b [URL="\\E.html"]}', |
| 368 |
"svg", |
| 369 |
"090.003.svg", |
| 370 |
), |
| 371 |
), |
| 372 |
) |
| 373 |
def test_reference(src: str, format: str, reference: str, tmp_path: Path): |
| 374 |
"""test some Graphviz input against a reference source""" |
| 375 |
|
| 376 |
# locate the reference output |
| 377 |
ref = Path(__file__).resolve().parent / "test_reference" / reference |
| 378 |
assert ref.exists() |
| 379 |
|
| 380 |
# process our input with Graphviz |
| 381 |
output = tmp_path / reference |
| 382 |
run(["dot", f"-T{format}", "-o", output], input=src) |
| 383 |
|
| 384 |
# compare against the reference output |
| 385 |
if output.suffix == ".png": |
| 386 |
run_raw(["diffimg", ref, output]) |
| 387 |
else: |
| 388 |
fail = False |
| 389 |
a = ref.read_text(encoding="utf-8") |
| 390 |
b = output.read_text(encoding="utf-8") |
| 391 |
for line in difflib.unified_diff(a, b, fromfile=str(ref), tofile=str(output)): |
| 392 |
sys.stderr.write(f"{line}\n") |
| 393 |
fail = True |
| 394 |
if fail: |
| 395 |
raise RuntimeError(f"diff {ref} {output} failed") |