Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2740fd

Browse filesBrowse files
committed
Ensure test_fig_sigint_override cleans up global state.
1 parent a3f1635 commit f2740fd
Copy full SHA for f2740fd

File tree

Expand file treeCollapse file tree

1 file changed

+19
-17
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-17
lines changed

‎lib/matplotlib/tests/test_backend_qt.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt.py
+19-17Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,31 @@ def custom_handler(signum, frame):
214214

215215
signal.signal(signal.SIGINT, custom_handler)
216216

217-
# mainloop() sets SIGINT, starts Qt event loop (which triggers timer and
218-
# exits) and then mainloop() resets SIGINT
219-
matplotlib.backends.backend_qt._BackendQT.mainloop()
217+
try:
218+
# mainloop() sets SIGINT, starts Qt event loop (which triggers timer
219+
# and exits) and then mainloop() resets SIGINT
220+
matplotlib.backends.backend_qt._BackendQT.mainloop()
220221

221-
# Assert: signal handler during loop execution is changed
222-
# (can't test equality with func)
223-
assert event_loop_handler != custom_handler
222+
# Assert: signal handler during loop execution is changed
223+
# (can't test equality with func)
224+
assert event_loop_handler != custom_handler
224225

225-
# Assert: current signal handler is the same as the one we set before
226-
assert signal.getsignal(signal.SIGINT) == custom_handler
226+
# Assert: current signal handler is the same as the one we set before
227+
assert signal.getsignal(signal.SIGINT) == custom_handler
227228

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

233-
_BackendQT5.mainloop()
234+
_BackendQT5.mainloop()
234235

235-
assert event_loop_handler == custom_handler
236-
assert signal.getsignal(signal.SIGINT) == custom_handler
236+
assert event_loop_handler == custom_handler
237+
assert signal.getsignal(signal.SIGINT) == custom_handler
237238

238-
# Reset SIGINT handler to what it was before the test
239-
signal.signal(signal.SIGINT, original_handler)
239+
finally:
240+
# Reset SIGINT handler to what it was before the test
241+
signal.signal(signal.SIGINT, original_handler)
240242

241243

242244
@pytest.mark.parametrize(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.