]> granicus.if.org Git - graphviz/commitdiff
add a test case for scale precision issue
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 7 Dec 2021 16:06:15 +0000 (08:06 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 11 Dec 2021 20:29:32 +0000 (12:29 -0800)
rtest/1855.dot [new file with mode: 0644]
rtest/test_regression.py

diff --git a/rtest/1855.dot b/rtest/1855.dot
new file mode 100644 (file)
index 0000000..cda66eb
--- /dev/null
@@ -0,0 +1,71 @@
+digraph {\r
+graph[size="10.0624,6.11863",ratio=fill];\r
+overlap=false;\r
+splines=true;\r
+node[fontname="Helvetica"];\r
+edge[fontname="Helvetica"];\r
+2->1[color=black];\r
+3->1[color=black];\r
+4->1[color=black];\r
+5->1[color=black];\r
+6->1[color=black];\r
+7->1[color=black];\r
+8->1[color=black];\r
+9->1[color=black];\r
+10->1[color=black];\r
+11->1[color=black];\r
+12->1[color=black];\r
+13->1[color=black];\r
+14->1[color=black];\r
+15->1[color=black];\r
+16->1[color=black];\r
+17->1[color=black];\r
+18->1[color=black];\r
+19->1[color=black];\r
+20->1[color=black];\r
+21->1[color=black];\r
+22->1[color=black];\r
+23->1[color=black];\r
+24->1[color=black];\r
+25->1[color=black];\r
+26->1[color=black];\r
+27->1[color=black];\r
+28->1[color=black];\r
+29->1[color=black];\r
+30->1[color=black];\r
+31->1[color=black];\r
+32->1[color=black];\r
+1[label=""];\r
+2[label=""];\r
+3[label=""];\r
+4[label=""];\r
+5[label=""];\r
+6[label=""];\r
+7[label=""];\r
+8[label=""];\r
+9[label=""];\r
+10[label=""];\r
+11[label=""];\r
+12[label=""];\r
+13[label=""];\r
+14[label=""];\r
+15[label=""];\r
+16[label=""];\r
+17[label=""];\r
+18[label=""];\r
+19[label=""];\r
+20[label=""];\r
+21[label=""];\r
+22[label=""];\r
+23[label=""];\r
+24[label=""];\r
+25[label=""];\r
+26[label=""];\r
+27[label=""];\r
+28[label=""];\r
+29[label=""];\r
+30[label=""];\r
+31[label=""];\r
+32[label="",style=filled,color=pink];\r
+1[style=filled,color=black,fillcolor=lightcyan2];\r
+}\r
index 3440da6939bbf6480d4920132a5636d0d2de954f..f8abf5d010248fb67fbcdca9e78fe2332777fd9c 100644 (file)
@@ -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<x>\d+(\.\d*)?) (?P<y>\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):