Skip to content

Commit 63f468e

Browse files
committed
add test and remove warn parameter
1 parent 42eb7c0 commit 63f468e

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def draw_if_interactive(cls):
175175
cls.trigger_manager_draw(manager)
176176

177177
@classmethod
178-
def show(cls, block=None, warn=True):
178+
def show(cls, block=None):
179179
"""Show all figures.
180180
181181
`show` blocks by calling `mainloop` if *block* is ``True``, or if it
@@ -189,11 +189,10 @@ def show(cls, block=None, warn=True):
189189
try:
190190
manager.show()
191191
except NonGuiException:
192-
if warn:
193-
import warnings
194-
warnings.warn(
195-
"matplotlib is currently using a non-GUI backend, "
196-
"so cannot show the figure")
192+
import warnings
193+
warnings.warn(
194+
"matplotlib is currently using a non-GUI backend, "
195+
"so cannot show the figure")
197196
return
198197
if cls.mainloop is None:
199198
return

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,22 @@ def psfont(*args, **kwargs):
179179
ax.text(0.5, 0.5, 'hello')
180180
with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError):
181181
fig.savefig(tmpfile, format='svg')
182+
183+
184+
def test_NonGui_warning():
185+
matplotlib.use('Agg')
186+
import matplotlib.pyplot as plt
187+
plt.plot([1, 2, 3])
188+
plt.savefig('myfig')
189+
190+
with pytest.warns(UserWarning) as rec:
191+
plt.show()
192+
assert len(rec) == 1
193+
assert 'matplotlib is currently using a non-GUI backend' \
194+
in str(rec[0].message)
195+
196+
with pytest.warns(UserWarning) as rec:
197+
plt.gcf().show()
198+
assert len(rec) == 1
199+
assert 'matplotlib is currently using a non-GUI backend' \
200+
in str(rec[0].message)

0 commit comments

Comments
 (0)