summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-04-25 19:02:46 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-04-25 19:02:46 (GMT)
commit5c322ece9601da2a4113f489d44762abffe6b8cd (patch)
tree2718070eecc6d3101673bf5bd673f3a3d2ec382c /Lib/unittest/test
parentadbcf1f4a804b1a1497fd33ee2c4c28d264197aa (diff)
downloadcpython-5c322ece9601da2a4113f489d44762abffe6b8cd.zip
cpython-5c322ece9601da2a4113f489d44762abffe6b8cd.tar.gz
cpython-5c322ece9601da2a4113f489d44762abffe6b8cd.tar.bz2
Adding unittest.removeHandler function / decorator for removing the signal.SIGINT signal handler. With tests and docs.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/test_break.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_break.py b/Lib/unittest/test/test_break.py
index cc3e282..5600011 100644
--- a/Lib/unittest/test/test_break.py
+++ b/Lib/unittest/test/test_break.py
@@ -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)