From: Magnus Jacobsson Date: Mon, 20 Apr 2020 21:03:01 +0000 (+0200) Subject: Generate one pytest case for each shape/output_type combination X-Git-Tag: 2.44.1~76^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa08caabf656be32176c69211793e8c66c49ceb6;p=graphviz Generate one pytest case for each shape/output_type combination --- diff --git a/tests/regression_tests/shapes/test_shapes.py b/tests/regression_tests/shapes/test_shapes.py index 33e1fe64d..a93ac36d8 100644 --- a/tests/regression_tests/shapes/test_shapes.py +++ b/tests/regression_tests/shapes/test_shapes.py @@ -1,11 +1,117 @@ -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 ' + # 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 '