Skip to content

Commit f17fc6d

Browse files
committed
test(plot): check also matplotlib show=True
1 parent 782d9b9 commit f17fc6d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

graphkit/network.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ def plot_graph(graph, filename=None, show=False, steps=None,
496496
call :func:`network.supported_plot_formats()` for more.
497497
:param boolean show:
498498
If it evaluates to true, opens the diagram in a matplotlib window.
499+
If it equals ``-1``, it plots but does not open the Window.
499500
:param steps:
500501
a list of nodes & instructions to overlay on the diagram
501502
:param inputs:
@@ -616,6 +617,7 @@ def get_node_name(a):
616617
sio = io.BytesIO(png)
617618
img = mpimg.imread(sio)
618619
plt.imshow(img, aspect="equal")
619-
plt.show()
620+
if show != -1:
621+
plt.show()
620622

621623
return g

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
extras_require={
3636
'plot': ['pydot', 'matplotlib']
3737
},
38-
tests_require=['numpy'],
38+
tests_require=[
39+
"numpy",
40+
"pydot", # to test plot
41+
"matplotlib" # to test plot
42+
],
3943
license='Apache-2.0',
4044
keywords=['graph', 'computation graph', 'DAG', 'directed acyclical graph'],
4145
classifiers=[

test/test_graphkit.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pickle
66
import os.path as osp
77
import shutil
8+
import sys
89
import tempfile
910

1011

@@ -138,6 +139,16 @@ def test_plotting():
138139
finally:
139140
shutil.rmtree(tdir, ignore_errors=True)
140141

142+
## Don't open matplotlib window.
143+
#
144+
if sys.version_info < (3, 5):
145+
# On PY< 3.5 it fails with:
146+
# nose.proxy.TclError: no display name and no $DISPLAY environment variable
147+
# eg https://travis-ci.org/ankostis/graphkit/jobs/593957996
148+
import matplotlib
149+
matplotlib.use("Agg")
150+
pipeline.plot(show=-1)
151+
141152
try:
142153
pipeline.plot('bad.format')
143154
assert False, "Should had failed writting arbitrary file format!"

0 commit comments

Comments
 (0)