mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Closes issue 15505. unittest.installHandler and non-callable signal handlers.
This commit is contained in:
parent
45c4375ea7
commit
6debd76939
3 changed files with 50 additions and 1 deletions
|
@ -13,9 +13,12 @@ import unittest
|
|||
@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
|
||||
"if threads have been used")
|
||||
class TestBreak(unittest.TestCase):
|
||||
int_handler = None
|
||||
|
||||
def setUp(self):
|
||||
self._default_handler = signal.getsignal(signal.SIGINT)
|
||||
if self.int_handler is not None:
|
||||
signal.signal(signal.SIGINT, self.int_handler)
|
||||
|
||||
def tearDown(self):
|
||||
signal.signal(signal.SIGINT, self._default_handler)
|
||||
|
@ -72,6 +75,10 @@ class TestBreak(unittest.TestCase):
|
|||
|
||||
|
||||
def testSecondInterrupt(self):
|
||||
# Can't use skipIf decorator because the signal handler may have
|
||||
# been changed after defining this method.
|
||||
if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
|
||||
self.skipTest("test requires SIGINT to not be ignored")
|
||||
result = unittest.TestResult()
|
||||
unittest.installHandler()
|
||||
unittest.registerResult(result)
|
||||
|
@ -121,6 +128,10 @@ class TestBreak(unittest.TestCase):
|
|||
|
||||
|
||||
def testHandlerReplacedButCalled(self):
|
||||
# Can't use skipIf decorator because the signal handler may have
|
||||
# been changed after defining this method.
|
||||
if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
|
||||
self.skipTest("test requires SIGINT to not be ignored")
|
||||
# If our handler has been replaced (is no longer installed) but is
|
||||
# called by the *new* handler, then it isn't safe to delay the
|
||||
# SIGINT and we should immediately delegate to the default handler
|
||||
|
@ -250,3 +261,24 @@ class TestBreak(unittest.TestCase):
|
|||
|
||||
test()
|
||||
self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill")
|
||||
@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows")
|
||||
@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
|
||||
"if threads have been used")
|
||||
class TestBreakDefaultIntHandler(TestBreak):
|
||||
int_handler = signal.default_int_handler
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill")
|
||||
@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows")
|
||||
@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
|
||||
"if threads have been used")
|
||||
class TestBreakSignalIgnored(TestBreak):
|
||||
int_handler = signal.SIG_IGN
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill")
|
||||
@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows")
|
||||
@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
|
||||
"if threads have been used")
|
||||
class TestBreakSignalDefault(TestBreak):
|
||||
int_handler = signal.SIG_DFL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue