From 88b098f6ddb413bf6ea852e4328a43568c628be1 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Tue, 7 Dec 2021 08:06:15 -0800 Subject: [PATCH] add a test case for scale precision issue --- rtest/1855.dot | 71 ++++++++++++++++++++++++++++++++++++++++ rtest/test_regression.py | 38 +++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 rtest/1855.dot diff --git a/rtest/1855.dot b/rtest/1855.dot new file mode 100644 index 000000000..cda66ebfb --- /dev/null +++ b/rtest/1855.dot @@ -0,0 +1,71 @@ +digraph { +graph[size="10.0624,6.11863",ratio=fill]; +overlap=false; +splines=true; +node[fontname="Helvetica"]; +edge[fontname="Helvetica"]; +2->1[color=black]; +3->1[color=black]; +4->1[color=black]; +5->1[color=black]; +6->1[color=black]; +7->1[color=black]; +8->1[color=black]; +9->1[color=black]; +10->1[color=black]; +11->1[color=black]; +12->1[color=black]; +13->1[color=black]; +14->1[color=black]; +15->1[color=black]; +16->1[color=black]; +17->1[color=black]; +18->1[color=black]; +19->1[color=black]; +20->1[color=black]; +21->1[color=black]; +22->1[color=black]; +23->1[color=black]; +24->1[color=black]; +25->1[color=black]; +26->1[color=black]; +27->1[color=black]; +28->1[color=black]; +29->1[color=black]; +30->1[color=black]; +31->1[color=black]; +32->1[color=black]; +1[label=""]; +2[label=""]; +3[label=""]; +4[label=""]; +5[label=""]; +6[label=""]; +7[label=""]; +8[label=""]; +9[label=""]; +10[label=""]; +11[label=""]; +12[label=""]; +13[label=""]; +14[label=""]; +15[label=""]; +16[label=""]; +17[label=""]; +18[label=""]; +19[label=""]; +20[label=""]; +21[label=""]; +22[label=""]; +23[label=""]; +24[label=""]; +25[label=""]; +26[label=""]; +27[label=""]; +28[label=""]; +29[label=""]; +30[label=""]; +31[label=""]; +32[label="",style=filled,color=pink]; +1[style=filled,color=black,fillcolor=lightcyan2]; +} diff --git a/rtest/test_regression.py b/rtest/test_regression.py index 3440da693..f8abf5d01 100644 --- a/rtest/test_regression.py +++ b/rtest/test_regression.py @@ -832,6 +832,44 @@ def test_html(src: Path): assert p.returncode == 0 assert stderr == "" +@pytest.mark.xfail(strict=True) +def test_1855(): + """ + SVGs should have a scale with sufficient precision + https://gitlab.com/graphviz/graphviz/-/issues/1855 + """ + + # locate our associated test case in this directory + src = Path(__file__).parent / "1855.dot" + assert src.exists(), "unexpectedly missing test case" + + # run it through Graphviz + svg = subprocess.check_output(["dot", "-Tsvg", src], universal_newlines=True) + + # find the graph element + root = ET.fromstring(svg) + graph = root[0] + assert graph.get("class") == "graph", "could not find graph element" + + # extract its `transform` attribute + transform = graph.get("transform") + + # this should begin with a scale directive + m = re.match(r"scale\((?P\d+(\.\d*)?) (?P\d+(\.\d*))\)", transform) + assert m is not None, f"failed to find 'scale' in '{transform}'" + + x = m.group("x") + y = m.group("y") + + # the scale should be somewhere in reasonable range of what is expected + assert float(x) >= 0.32 and float(x) <= 0.34, "inaccurate x scale" + assert float(y) >= 0.32 and float(y) <= 0.34, "inaccurate y scale" + + # two digits of precision are insufficient for this example, so require a + # greater number of digits in both scale components + assert len(x) > 4, "insufficient precision in x scale" + assert len(y) > 4, "insufficient precision in y scale" + @pytest.mark.parametrize("variant", [1, 2]) @pytest.mark.skipif(shutil.which("gml2gv") is None, reason="gml2gv not available") def test_1869(variant: int): -- 2.40.0