@@ -52,6 +52,7 @@ def _get_testable_interactive_backends():
5252_test_script = """\
5353 import importlib
5454import importlib.util
55+ import io
5556import sys
5657from unittest import TestCase
5758
@@ -107,17 +108,34 @@ def check_alt_backend(alt_backend):
107108# Trigger quitting upon draw.
108109fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
109110
111+ result = io.BytesIO()
112+ fig.savefig(result, format='png')
113+
110114plt.show()
115+
116+ # Ensure that the window is really closed.
117+ plt.pause(0.5)
118+
119+ # Test that saving works after interactive window is closed, but the figure is
120+ # not deleted.
121+ result_after = io.BytesIO()
122+ fig.savefig(result_after, format='png')
123+
124+ if not backend.startswith('qt5') and sys.platform == 'darwin':
125+ # FIXME: This should be enabled everywhere once Qt5 is fixed on macOS to
126+ # not resize incorrectly.
127+ assert_equal(result.getvalue(), result_after.getvalue())
111128"""
112129_test_timeout = 10 # Empirically, 1s is not enough on Travis.
113130
114131
115132@pytest .mark .parametrize ("backend" , _get_testable_interactive_backends ())
116133@pytest .mark .flaky (reruns = 3 )
117134def test_interactive_backend (backend ):
118- proc = subprocess .run ([sys .executable , "-c" , _test_script ],
119- env = {** os .environ , "MPLBACKEND" : backend },
120- timeout = _test_timeout )
135+ proc = subprocess .run (
136+ [sys .executable , "-c" , _test_script ],
137+ env = {** os .environ , "MPLBACKEND" : backend , "SOURCE_DATE_EPOCH" : "0" },
138+ timeout = _test_timeout )
121139 if proc .returncode :
122140 pytest .fail ("The subprocess returned with non-zero exit status "
123141 f"{ proc .returncode } ." )
@@ -129,7 +147,8 @@ def test_interactive_backend(backend):
129147def test_webagg ():
130148 pytest .importorskip ("tornado" )
131149 proc = subprocess .Popen ([sys .executable , "-c" , _test_script ],
132- env = {** os .environ , "MPLBACKEND" : "webagg" })
150+ env = {** os .environ , "MPLBACKEND" : "webagg" ,
151+ "SOURCE_DATE_EPOCH" : "0" })
133152 url = "http://{}:{}" .format (
134153 mpl .rcParams ["webagg.address" ], mpl .rcParams ["webagg.port" ])
135154 timeout = time .perf_counter () + _test_timeout
0 commit comments