mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Adding unittest.removeHandler function / decorator for removing the signal.SIGINT signal handler. With tests and docs.
This commit is contained in:
parent
adbcf1f4a8
commit
5c322ece96
4 changed files with 67 additions and 4 deletions
|
@ -229,3 +229,24 @@ class TestBreak(unittest.TestCase):
|
|||
self.assertEqual(p.result, result)
|
||||
|
||||
self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)
|
||||
|
||||
def testRemoveHandler(self):
|
||||
default_handler = signal.getsignal(signal.SIGINT)
|
||||
unittest.installHandler()
|
||||
unittest.removeHandler()
|
||||
self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
|
||||
|
||||
# check that calling removeHandler multiple times has no ill-effect
|
||||
unittest.removeHandler()
|
||||
self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
|
||||
|
||||
def testRemoveHandlerAsDecorator(self):
|
||||
default_handler = signal.getsignal(signal.SIGINT)
|
||||
unittest.installHandler()
|
||||
|
||||
@unittest.removeHandler
|
||||
def test():
|
||||
self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
|
||||
|
||||
test()
|
||||
self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue