From bea30d3f3e7eabecb428c57d0bd2da9875c65f78 Mon Sep 17 00:00:00 2001 From: Erwin Janssen Date: Mon, 10 Oct 2016 23:44:24 +0200 Subject: [PATCH] Python script to generate a graph for every shape The start of a regression test with Python. This script generates a gv output for every available shape, the most basic output type. --- .gitignore | 1 + tests/regression_tests/shapes/shapes.py | 105 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tests/regression_tests/shapes/shapes.py diff --git a/.gitignore b/.gitignore index cff4c79c7..b27b6674a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 000000000..f6beb2c17 --- /dev/null +++ b/tests/regression_tests/shapes/shapes.py @@ -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 ' + # 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 '