]> granicus.if.org Git - graphviz/commitdiff
Generate one pytest case for each shape/output_type combination
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Mon, 20 Apr 2020 21:03:01 +0000 (23:03 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 22 Apr 2020 04:33:41 +0000 (06:33 +0200)
tests/regression_tests/shapes/test_shapes.py

index 33e1fe64ddedaeb045afceb0c72b9a854772928f..a93ac36d875a2c5562fde5e6a99b3e429b6a1fc0 100644 (file)
-import subprocess
-import os
-import sys
-
-def test_shapes():
-    python_version = sys.version_info[0]
-    os.chdir(os.path.dirname(os.path.realpath(__file__)))
-    result = subprocess.Popen(['python' + str(python_version), './shapes.py'])
-    text = result.communicate()[0]
-    print(text)
-    assert result.returncode == 0
+import pytest
+
+from subprocess import Popen, PIPE
+import os.path, sys
+
+# Import helper function to compare graphs from tests/regressions_tests
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
+from regression_test_helpers import compare_graphs
+
+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',
+    'svg',
+    'xdot'
+]
+
+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)
+
+class Test_File():
+    @pytest.mark.parametrize(
+        'shape,output_type', [(shape, output_type) for shape in shapes for output_type in output_types]
+    )
+    def test_shape(self, shape, output_type):
+        os.chdir(os.path.dirname(os.path.realpath(__file__)))
+        generate_shape_graph(shape, output_type)
+        assert compare_graphs(shape, output_type)