Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
Improve rendering with graphviz in tests
Browse files Browse the repository at this point in the history
Render png as they are easier to compare (img diff software)
Check exit code of calling graphviz to see if it didn't segfault.
  • Loading branch information
prmtl committed Oct 23, 2018
1 parent bd6fd3c commit d3340ba
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/test_rendering_dot_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
("my_regressions", MY_REGRESSION_TESTS_DIR),
)

DEFAULT_FORMAT = "png"


def list_dots(path):
searchpath = os.path.join(path, "*.dot")
Expand Down Expand Up @@ -57,7 +59,7 @@ def pytest_generate_tests(metafunc):

def _render_with_graphviz(filename):
p = subprocess.Popen(
(DOT_BINARY_PATH, "-Tjpe"),
(DOT_BINARY_PATH, "-T{}".format(DEFAULT_FORMAT)),
cwd=os.path.dirname(filename),
stdin=open(filename, "rt"),
stderr=subprocess.PIPE,
Expand All @@ -77,8 +79,8 @@ def _render_with_graphviz(filename):
if stdout_output:
stdout_output = NULL_SEP.join(stdout_output)

# this returns a status code we should check
p.wait()
ret = p.wait()
assert ret == 0, "graphviz quit with error"

return sha256(stdout_output).hexdigest()

Expand All @@ -87,8 +89,8 @@ def _render_with_pydot(filename):
g = pydot.graph_from_dot_file(filename)
if not isinstance(g, list):
g = [g]
jpe_data = NULL_SEP.join([_g.create(format="jpe") for _g in g])
return sha256(jpe_data).hexdigest()
image_data = NULL_SEP.join([_g.create(format=DEFAULT_FORMAT) for _g in g])
return sha256(image_data).hexdigest()


def test_render_and_compare_dot_files(filepath):
Expand All @@ -113,8 +115,8 @@ def test_graph_with_shapefiles():
#
g = pydot.graph_from_dot_data(graph_data)
g.set_shape_files(pngs)
jpe_data = g.create(format="jpe")
hexdigest = sha256(jpe_data).hexdigest()
image_data = g.create(format=DEFAULT_FORMAT)
hexdigest = sha256(image_data).hexdigest()
hexdigest_original = _render_with_graphviz(dot_file)

assert hexdigest == hexdigest_original

0 comments on commit d3340ba

Please sign in to comment.