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

Skip to content

Commit 6eab1f1

Browse files
committed
Ensure test_fig_sigint_override cleans up global state.
1 parent 4bd10a4 commit 6eab1f1

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,29 +211,31 @@ def custom_handler(signum, frame):
211211

212212
signal.signal(signal.SIGINT, custom_handler)
213213

214-
# mainloop() sets SIGINT, starts Qt event loop (which triggers timer and
215-
# exits) and then mainloop() resets SIGINT
216-
matplotlib.backends.backend_qt._BackendQT.mainloop()
214+
try:
215+
# mainloop() sets SIGINT, starts Qt event loop (which triggers timer
216+
# and exits) and then mainloop() resets SIGINT
217+
matplotlib.backends.backend_qt._BackendQT.mainloop()
217218

218-
# Assert: signal handler during loop execution is changed
219-
# (can't test equality with func)
220-
assert event_loop_handler != custom_handler
219+
# Assert: signal handler during loop execution is changed
220+
# (can't test equality with func)
221+
assert event_loop_handler != custom_handler
221222

222-
# Assert: current signal handler is the same as the one we set before
223-
assert signal.getsignal(signal.SIGINT) == custom_handler
223+
# Assert: current signal handler is the same as the one we set before
224+
assert signal.getsignal(signal.SIGINT) == custom_handler
224225

225-
# Repeat again to test that SIG_DFL and SIG_IGN will not be overridden
226-
for custom_handler in (signal.SIG_DFL, signal.SIG_IGN):
227-
qt_core.QTimer.singleShot(0, fire_signal_and_quit)
228-
signal.signal(signal.SIGINT, custom_handler)
226+
# Repeat again to test that SIG_DFL and SIG_IGN will not be overridden
227+
for custom_handler in (signal.SIG_DFL, signal.SIG_IGN):
228+
qt_core.QTimer.singleShot(0, fire_signal_and_quit)
229+
signal.signal(signal.SIGINT, custom_handler)
229230

230-
_BackendQT5.mainloop()
231+
_BackendQT5.mainloop()
231232

232-
assert event_loop_handler == custom_handler
233-
assert signal.getsignal(signal.SIGINT) == custom_handler
233+
assert event_loop_handler == custom_handler
234+
assert signal.getsignal(signal.SIGINT) == custom_handler
234235

235-
# Reset SIGINT handler to what it was before the test
236-
signal.signal(signal.SIGINT, original_handler)
236+
finally:
237+
# Reset SIGINT handler to what it was before the test
238+
signal.signal(signal.SIGINT, original_handler)
237239

238240

239241
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)