Skip to content

Commit

Permalink
test(plot): check also matplotlib show=True
Browse files Browse the repository at this point in the history
  • Loading branch information
ankostis committed Oct 5, 2019
1 parent 782d9b9 commit f17fc6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion graphkit/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def plot_graph(graph, filename=None, show=False, steps=None,
call :func:`network.supported_plot_formats()` for more.
:param boolean show:
If it evaluates to true, opens the diagram in a matplotlib window.
If it equals ``-1``, it plots but does not open the Window.
:param steps:
a list of nodes & instructions to overlay on the diagram
:param inputs:
Expand Down Expand Up @@ -616,6 +617,7 @@ def get_node_name(a):
sio = io.BytesIO(png)
img = mpimg.imread(sio)
plt.imshow(img, aspect="equal")
plt.show()
if show != -1:
plt.show()

return g
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
extras_require={
'plot': ['pydot', 'matplotlib']
},
tests_require=['numpy'],
tests_require=[
"numpy",
"pydot", # to test plot
"matplotlib" # to test plot
],
license='Apache-2.0',
keywords=['graph', 'computation graph', 'DAG', 'directed acyclical graph'],
classifiers=[
Expand Down
11 changes: 11 additions & 0 deletions test/test_graphkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pickle
import os.path as osp
import shutil
import sys
import tempfile


Expand Down Expand Up @@ -138,6 +139,16 @@ def test_plotting():
finally:
shutil.rmtree(tdir, ignore_errors=True)

## Don't open matplotlib window.
#
if sys.version_info < (3, 5):
# On PY< 3.5 it fails with:
# nose.proxy.TclError: no display name and no $DISPLAY environment variable
# eg https://travis-ci.org/ankostis/graphkit/jobs/593957996
import matplotlib
matplotlib.use("Agg")
pipeline.plot(show=-1)

try:
pipeline.plot('bad.format')
assert False, "Should had failed writting arbitrary file format!"
Expand Down

0 comments on commit f17fc6d

Please sign in to comment.