]> granicus.if.org Git - graphviz/commitdiff
Python script to generate a graph for every shape
authorErwin Janssen <erwinjanssen@outlook.com>
Mon, 10 Oct 2016 21:44:24 +0000 (23:44 +0200)
committerErwin Janssen <erwinjanssen@outlook.com>
Thu, 27 Oct 2016 22:56:31 +0000 (00:56 +0200)
The start of a regression test with Python. This script generates a gv
output for every available shape, the most basic output type.

.gitignore
tests/regression_tests/shapes/shapes.py [new file with mode: 0644]

index cff4c79c7a67ed24ca77882cd51d5e54fb73d277..b27b6674a32303b6c2b75aa8a7d516c13d146ed1 100644 (file)
@@ -201,6 +201,7 @@ rtest/ndata
 rtest/nhtml
 tests/**/*.log
 tests/**/*.trs
+tests/**/output/**
 
 ## Binaries
 tests/unit_tests/lib/common/command_line
diff --git a/tests/regression_tests/shapes/shapes.py b/tests/regression_tests/shapes/shapes.py
new file mode 100644 (file)
index 0000000..f6beb2c
--- /dev/null
@@ -0,0 +1,105 @@
+from subprocess import Popen, PIPE
+import os.path
+
+shapes = [
+    'box',
+    'polygon',
+    'ellipse',
+    'oval',
+    'circle',
+    'point',
+    'egg',
+    'triangle',
+    'none',
+    'plaintext',
+    'plain',
+    'diamond',
+    'trapezium',
+    'parallelogram',
+    'house',
+    'pentagon',
+    'hexagon',
+    'septagon',
+    'octagon',
+    'note',
+    'tab',
+    'folder',
+    'box3d',
+    'component',
+    'cylinder',
+    'rect',
+    'rectangle',
+    'square',
+    'star',
+    'doublecircle',
+    'doubleoctagon',
+    'tripleoctagon',
+    'invtriangle',
+    'invtrapezium',
+    'invhouse',
+    'underline',
+    'Mdiamond',
+    'Msquare',
+    'Mcircle',
+    # biological circuit shapes
+    # gene expression symbols
+    'promoter',
+    'cds',
+    'terminator',
+    'utr',
+    'insulator',
+    'ribosite',
+    'rnastab',
+    'proteasesite',
+    'proteinstab',
+    # dna construction symbols
+    'primersite',
+    'restrictionsite',
+    'fivepoverhang',
+    'threepoverhang',
+    'noverhang',
+    'assembly',
+    'signature',
+    'rpromoter',
+    'larrow',
+    'rarrow',
+    'lpromoter'
+]
+
+output_types = [
+    'gv'
+]
+
+def generate_shape_graph(shape, output_type):
+    if not os.path.exists('output'):
+        os.makedirs('output')
+
+    output_file = 'output/' + shape + '.' + output_type
+    process = Popen(['dot', '-T' + output_type, '-o', output_file], stdin=PIPE)
+
+    input_graph = 'graph G { a [label="" shape=' + shape + '] }'
+    process.communicate(input = input_graph.encode('utf_8'))
+
+    if process.wait() != 0:
+        print('An error occurred while generating: ' + output_file)
+        exit(1)
+
+    if output_type == 'svg':
+        # Remove the number in 'Generated by graphviz version <number>'
+        # to able to compare the output to the reference. This version
+        # number is different for every Graphviz compilation.
+        file = open(output_file, 'r')
+        lines = file.readlines()
+        file.close()
+
+        file = open(output_file, 'w')
+        for line in lines:
+            if '<!-- Generated by graphviz version ' in line:
+                file.write('<!-- Generated by graphviz version\n')
+            else:
+                file.write(line)
+
+for shape in shapes:
+    for output_type in output_types:
+        print('Generating: ' + shape + '.' + output_type)
+        generate_shape_graph(shape, output_type)