Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Attributes
unittest.test.test_break.TestBreak Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def testInstallHandler
def testRegisterResult
def testInterruptCaught
def testSecondInterrupt
def testTwoResults
def testHandlerReplacedButCalled
def testRunner
def testWeakReferences
def testRemoveResult
def testMainInstallsHandler
def testRemoveHandler
def testRemoveHandlerAsDecorator

Public Attributes

 exit
 verbosity
 failfast
 catchbreak
 testRunner
 test
 result

Private Attributes

 _default_handler

Detailed Description

Definition at line 15 of file test_break.py.


Member Function Documentation

Definition at line 17 of file test_break.py.

00017 
00018     def setUp(self):
00019         self._default_handler = signal.getsignal(signal.SIGINT)

Definition at line 20 of file test_break.py.

00020 
00021     def tearDown(self):
00022         signal.signal(signal.SIGINT, self._default_handler)
00023         unittest.signals._results = weakref.WeakKeyDictionary()
00024         unittest.signals._interrupt_handler = None
00025 

Definition at line 123 of file test_break.py.

00123 
00124     def testHandlerReplacedButCalled(self):
00125         # If our handler has been replaced (is no longer installed) but is
00126         # called by the *new* handler, then it isn't safe to delay the
00127         # SIGINT and we should immediately delegate to the default handler
00128         unittest.installHandler()
00129 
00130         handler = signal.getsignal(signal.SIGINT)
00131         def new_handler(frame, signum):
00132             handler(frame, signum)
00133         signal.signal(signal.SIGINT, new_handler)
00134 
00135         try:
00136             pid = os.getpid()
00137             os.kill(pid, signal.SIGINT)
00138         except KeyboardInterrupt:
00139             pass
00140         else:
00141             self.fail("replaced but delegated handler doesn't raise interrupt")

Here is the call graph for this function:

Definition at line 26 of file test_break.py.

00026 
00027     def testInstallHandler(self):
00028         default_handler = signal.getsignal(signal.SIGINT)
00029         unittest.installHandler()
00030         self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)
00031 
00032         try:
00033             pid = os.getpid()
00034             os.kill(pid, signal.SIGINT)
00035         except KeyboardInterrupt:
00036             self.fail("KeyboardInterrupt not handled")
00037 
00038         self.assertTrue(unittest.signals._interrupt_handler.called)

Here is the call graph for this function:

Definition at line 52 of file test_break.py.

00052 
00053     def testInterruptCaught(self):
00054         default_handler = signal.getsignal(signal.SIGINT)
00055 
00056         result = unittest.TestResult()
00057         unittest.installHandler()
00058         unittest.registerResult(result)
00059 
00060         self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)
00061 
00062         def test(result):
00063             pid = os.getpid()
00064             os.kill(pid, signal.SIGINT)
00065             result.breakCaught = True
00066             self.assertTrue(result.shouldStop)
00067 
00068         try:
00069             test(result)
00070         except KeyboardInterrupt:
00071             self.fail("KeyboardInterrupt not handled")
00072         self.assertTrue(result.breakCaught)
00073 

Here is the call graph for this function:

Definition at line 181 of file test_break.py.

00181 
00182     def testMainInstallsHandler(self):
00183         failfast = object()
00184         test = object()
00185         verbosity = object()
00186         result = object()
00187         default_handler = signal.getsignal(signal.SIGINT)
00188 
00189         class FakeRunner(object):
00190             initArgs = []
00191             runArgs = []
00192             def __init__(self, *args, **kwargs):
00193                 self.initArgs.append((args, kwargs))
00194             def run(self, test):
00195                 self.runArgs.append(test)
00196                 return result
00197 
00198         class Program(unittest.TestProgram):
00199             def __init__(self, catchbreak):
00200                 self.exit = False
00201                 self.verbosity = verbosity
00202                 self.failfast = failfast
00203                 self.catchbreak = catchbreak
00204                 self.testRunner = FakeRunner
00205                 self.test = test
00206                 self.result = None
00207 
00208         p = Program(False)
00209         p.runTests()
00210 
00211         self.assertEqual(FakeRunner.initArgs, [((), {'buffer': None,
00212                                                      'verbosity': verbosity,
00213                                                      'failfast': failfast,
00214                                                      'warnings': None})])
00215         self.assertEqual(FakeRunner.runArgs, [test])
00216         self.assertEqual(p.result, result)
00217 
00218         self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
00219 
00220         FakeRunner.initArgs = []
00221         FakeRunner.runArgs = []
00222         p = Program(True)
00223         p.runTests()
00224 
00225         self.assertEqual(FakeRunner.initArgs, [((), {'buffer': None,
00226                                                      'verbosity': verbosity,
00227                                                      'failfast': failfast,
00228                                                      'warnings': None})])
00229         self.assertEqual(FakeRunner.runArgs, [test])
00230         self.assertEqual(p.result, result)
00231 
00232         self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)

Here is the call graph for this function:

Definition at line 39 of file test_break.py.

00039 
00040     def testRegisterResult(self):
00041         result = unittest.TestResult()
00042         unittest.registerResult(result)
00043 
00044         for ref in unittest.signals._results:
00045             if ref is result:
00046                 break
00047             elif ref is not result:
00048                 self.fail("odd object in result set")
00049         else:
00050             self.fail("result not found")
00051 

Here is the call graph for this function:

Definition at line 233 of file test_break.py.

00233 
00234     def testRemoveHandler(self):
00235         default_handler = signal.getsignal(signal.SIGINT)
00236         unittest.installHandler()
00237         unittest.removeHandler()
00238         self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
00239 
00240         # check that calling removeHandler multiple times has no ill-effect
00241         unittest.removeHandler()
00242         self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)

Here is the call graph for this function:

Definition at line 243 of file test_break.py.

00243 
00244     def testRemoveHandlerAsDecorator(self):
00245         default_handler = signal.getsignal(signal.SIGINT)
00246         unittest.installHandler()
00247 
00248         @unittest.removeHandler
00249         def test():
00250             self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
00251 
00252         test()
00253         self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)

Here is the call graph for this function:

Definition at line 163 of file test_break.py.

00163 
00164     def testRemoveResult(self):
00165         result = unittest.TestResult()
00166         unittest.registerResult(result)
00167 
00168         unittest.installHandler()
00169         self.assertTrue(unittest.removeResult(result))
00170 
00171         # Should this raise an error instead?
00172         self.assertFalse(unittest.removeResult(unittest.TestResult()))
00173 
00174         try:
00175             pid = os.getpid()
00176             os.kill(pid, signal.SIGINT)
00177         except KeyboardInterrupt:
00178             pass
00179 
00180         self.assertFalse(result.shouldStop)

Here is the call graph for this function:

Definition at line 142 of file test_break.py.

00142 
00143     def testRunner(self):
00144         # Creating a TextTestRunner with the appropriate argument should
00145         # register the TextTestResult it creates
00146         runner = unittest.TextTestRunner(stream=io.StringIO())
00147 
00148         result = runner.run(unittest.TestSuite())
00149         self.assertIn(result, unittest.signals._results)

Here is the call graph for this function:

Definition at line 74 of file test_break.py.

00074 
00075     def testSecondInterrupt(self):
00076         result = unittest.TestResult()
00077         unittest.installHandler()
00078         unittest.registerResult(result)
00079 
00080         def test(result):
00081             pid = os.getpid()
00082             os.kill(pid, signal.SIGINT)
00083             result.breakCaught = True
00084             self.assertTrue(result.shouldStop)
00085             os.kill(pid, signal.SIGINT)
00086             self.fail("Second KeyboardInterrupt not raised")
00087 
00088         try:
00089             test(result)
00090         except KeyboardInterrupt:
00091             pass
00092         else:
00093             self.fail("Second KeyboardInterrupt not raised")
00094         self.assertTrue(result.breakCaught)
00095 

Here is the call graph for this function:

Definition at line 96 of file test_break.py.

00096 
00097     def testTwoResults(self):
00098         unittest.installHandler()
00099 
00100         result = unittest.TestResult()
00101         unittest.registerResult(result)
00102         new_handler = signal.getsignal(signal.SIGINT)
00103 
00104         result2 = unittest.TestResult()
00105         unittest.registerResult(result2)
00106         self.assertEqual(signal.getsignal(signal.SIGINT), new_handler)
00107 
00108         result3 = unittest.TestResult()
00109 
00110         def test(result):
00111             pid = os.getpid()
00112             os.kill(pid, signal.SIGINT)
00113 
00114         try:
00115             test(result)
00116         except KeyboardInterrupt:
00117             self.fail("KeyboardInterrupt not handled")
00118 
00119         self.assertTrue(result.shouldStop)
00120         self.assertTrue(result2.shouldStop)
00121         self.assertFalse(result3.shouldStop)
00122 

Here is the call graph for this function:

Definition at line 150 of file test_break.py.

00150 
00151     def testWeakReferences(self):
00152         # Calling registerResult on a result should not keep it alive
00153         result = unittest.TestResult()
00154         unittest.registerResult(result)
00155 
00156         ref = weakref.ref(result)
00157         del result
00158 
00159         # For non-reference counting implementations
00160         gc.collect();gc.collect()
00161         self.assertIsNone(ref())
00162 

Here is the call graph for this function:


Member Data Documentation

Definition at line 18 of file test_break.py.

Definition at line 202 of file test_break.py.

Definition at line 199 of file test_break.py.

Definition at line 201 of file test_break.py.

Definition at line 205 of file test_break.py.

Definition at line 204 of file test_break.py.

Definition at line 203 of file test_break.py.

Definition at line 200 of file test_break.py.


The documentation for this class was generated from the following file: