From a8f4e15f3d33084862ddd3a7d58cd00034e94f16 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Tue, 26 Dec 2017 11:53:38 +0200 Subject: [PATCH] bpo-26133: Fix typos (#5010) * Fix typos * Change warning text * Add test --- Lib/asyncio/unix_events.py | 4 ++-- Lib/test/test_asyncio/test_unix_events.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 5d6a3c09ac7..4f6beb43650 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -56,9 +56,9 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): self.remove_signal_handler(sig) else: if self._signal_handlers: - warinigs.warn(f"Closing the loop {self!r} " + warnings.warn(f"Closing the loop {self!r} " f"on interpreter shutdown " - f"stage, signal unsubsription is disabled", + f"stage, skipping signal handlers removal", ResourceWarning, source=self) self._signal_handlers.clear() diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py index 097d0ef73dc..53ed3d94ddb 100644 --- a/Lib/test/test_asyncio/test_unix_events.py +++ b/Lib/test/test_asyncio/test_unix_events.py @@ -229,6 +229,23 @@ class SelectorEventLoopSignalTests(test_utils.TestCase): self.assertEqual(len(self.loop._signal_handlers), 0) m_signal.set_wakeup_fd.assert_called_once_with(-1) + @mock.patch('asyncio.unix_events.sys') + @mock.patch('asyncio.unix_events.signal') + def test_close_on_finalizing(self, m_signal, m_sys): + m_signal.NSIG = signal.NSIG + self.loop.add_signal_handler(signal.SIGHUP, lambda: True) + + self.assertEqual(len(self.loop._signal_handlers), 1) + m_sys.is_finalizing.return_value = True + m_signal.signal.reset_mock() + + with self.assertWarnsRegex(ResourceWarning, + "skipping signal handlers removal"): + self.loop.close() + + self.assertEqual(len(self.loop._signal_handlers), 0) + self.assertFalse(m_signal.signal.called) + @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'UNIX Sockets are not supported')