Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a87327

Browse files
committed
TST: Smoke test saving with interactive backends.
We've had a report with Tk, and I think with WebAgg previously, so at least do a simple test that it works.
1 parent c2e5011 commit 9a87327

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def _get_testable_interactive_backends():
6161
_test_script = """\
6262
import importlib
6363
import importlib.util
64+
import io
6465
import json
6566
import sys
6667
from unittest import TestCase
@@ -120,7 +121,20 @@ def check_alt_backend(alt_backend):
120121
fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
121122
fig.canvas.mpl_connect("close_event", print)
122123
124+
result = io.BytesIO()
125+
fig.savefig(result, format='png')
126+
123127
plt.show()
128+
129+
# Ensure that the window is really closed.
130+
plt.pause(0.5)
131+
132+
# Test that saving works after interactive window is closed, but the figure is
133+
# not deleted.
134+
result_after = io.BytesIO()
135+
fig.savefig(result_after, format='png')
136+
137+
assert_equal(result.getvalue(), result_after.getvalue())
124138
"""
125139
_test_timeout = 10 # Empirically, 1s is not enough on Travis.
126140

@@ -134,7 +148,8 @@ def test_interactive_backend(backend, toolbar):
134148
proc = subprocess.run(
135149
[sys.executable, "-c", _test_script,
136150
json.dumps({"toolbar": toolbar})],
137-
env={**os.environ, "MPLBACKEND": backend}, timeout=_test_timeout,
151+
env={**os.environ, "MPLBACKEND": backend, "SOURCE_DATE_EPOCH": "0"},
152+
timeout=_test_timeout,
138153
stdout=subprocess.PIPE, universal_newlines=True)
139154
if proc.returncode:
140155
pytest.fail("The subprocess returned with non-zero exit status "
@@ -148,7 +163,8 @@ def test_interactive_backend(backend, toolbar):
148163
def test_webagg():
149164
pytest.importorskip("tornado")
150165
proc = subprocess.Popen([sys.executable, "-c", _test_script],
151-
env={**os.environ, "MPLBACKEND": "webagg"})
166+
env={**os.environ, "MPLBACKEND": "webagg",
167+
"SOURCE_DATE_EPOCH": "0"})
152168
url = "http://{}:{}".format(
153169
mpl.rcParams["webagg.address"], mpl.rcParams["webagg.port"])
154170
timeout = time.perf_counter() + _test_timeout

0 commit comments

Comments
 (0)