Skip to content

Commit 318e511

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

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ def test_plotting():
138138
finally:
139139
shutil.rmtree(tdir, ignore_errors=True)
140140

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

0 commit comments

Comments
 (0)