Skip to content

Commit

Permalink
refact(plot.TC): avoid writting multiple temp-files
Browse files Browse the repository at this point in the history
  • Loading branch information
ankostis committed Oct 5, 2019
1 parent 3fe0b40 commit 1471551
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions test/test_graphkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,35 @@ def test_plotting():
inputs = {'a': 1, 'b1': 2}
solution=pipeline(inputs)

# ...not working on my PC ...
forbidden_formats = ".dia .hpgl .mif .mp .pcl .pic .vtx .xlib".split()

## Generate all formats
# (not needing to save files)
#
# ...these are not working on my PC, or travis.
forbidden_formats = ".dia .hpgl .mif .mp .pcl .pic .vtx .xlib".split()
prev_dot = None
for ext in network.supported_plot_formats():
if ext in forbidden_formats:
continue

dot = pipeline.plot(inputs=inputs, solution=solution, outputs=['asked', 'b1'])
assert dot
assert dot != prev_dot
prev_dot = dot

dot = pipeline.plot()
assert dot
assert dot != prev_dot
prev_dot = dot

## Try saving one file.
#
tdir = tempfile.mkdtemp()
counter = 0
fpath = osp.join(tdir, "workflow.png")
try:
for ext in network.supported_plot_formats():
if ext in forbidden_formats:
continue

counter += 1
fpath = osp.join(tdir, "workflow-%i%s" % (counter, ext))
pipeline.plot(fpath, inputs=inputs, solution=solution, outputs=['asked', 'b1'])
assert osp.exists(fpath)

counter += 1
fpath = osp.join(tdir, "workflow-%i%s" % (counter, ext))
pipeline.plot(fpath)
assert osp.exists(fpath)
dot = pipeline.plot(fpath, inputs=inputs, solution=solution, outputs=['asked', 'b1'])
assert osp.exists(fpath)
assert dot
finally:
shutil.rmtree(tdir, ignore_errors=True)

Expand Down

0 comments on commit 1471551

Please sign in to comment.