]> granicus.if.org Git - graphviz/commitdiff
add a test of user shapes
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 14 Feb 2021 17:43:25 +0000 (09:43 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 20 Feb 2021 23:51:09 +0000 (15:51 -0800)
rtest/test_regression.py
rtest/usershape.dot [new file with mode: 0644]
rtest/usershape.svg [new file with mode: 0644]

index e60fde08b65d02f4be9169202c671b3e4c1f9b9c..9f5c8f6cbf745a574496f306254cc60eba3083a6 100644 (file)
@@ -749,3 +749,20 @@ def test_package_version():
 
       # run the test
       subprocess.check_call([exe])
+
+def test_user_shapes():
+    '''
+    Graphviz should understand how to embed a custom SVG image as a node’s shape
+    '''
+
+    # find our collocated test case
+    input = Path(__file__).parent / 'usershape.dot'
+    assert input.exists(), 'unexpectedly missing test case'
+
+    # ask Graphviz to translate this to SVG
+    output = subprocess.check_output(['dot', '-Tsvg', input],
+      cwd=os.path.dirname(__file__), universal_newlines=True)
+
+    # the external SVG should have been parsed and is now referenced
+    assert '<image xlink:href="usershape.svg" width="62px" height="44px" ' in \
+      output
diff --git a/rtest/usershape.dot b/rtest/usershape.dot
new file mode 100644 (file)
index 0000000..a6b9cfa
--- /dev/null
@@ -0,0 +1,3 @@
+graph {
+  a[image="usershape.svg"];
+}
diff --git a/rtest/usershape.svg b/rtest/usershape.svg
new file mode 100644 (file)
index 0000000..0fb2fec
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version
+ -->
+<!-- Title: G Pages: 1 -->
+<svg width="62pt" height="44pt"
+ viewBox="0.00 0.00 62.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
+<title>G</title>
+<polygon fill="white" stroke="transparent" points="-4,4 -4,-40 58,-40 58,4 -4,4"/>
+<!-- a -->
+<g id="node1" class="node">
+<title>a</title>
+<polygon fill="none" stroke="black" points="27,-36 0,-9 54,-9 27,-36"/>
+</g>
+</g>
+</svg>