Beispiel #1
0
 def test_error_messages(self):
     def raise_value_error(signum, handler):
         raise ValueError("Got signal %d" % signum)
     signal.signal = raise_value_error
     _StopSignalMonitor().__enter__()
     assert_equal(len(self.logger.messages), 2)
     self._verify_warning(self.logger.messages[0], 'INT',
                          'Got signal %d' % signal.SIGINT)
     self._verify_warning(self.logger.messages[1], 'TERM',
                          'Got signal %d' % signal.SIGTERM)
 def test_illegal_argument_exception(self):
     from java.lang import IllegalArgumentException
     def raise_iae_for_sigint(signum, handler):
         if signum == signal.SIGINT:
             raise IllegalArgumentException('xxx')
     signal.signal = raise_iae_for_sigint
     _StopSignalMonitor().start()
     assert_equal(len(self.logger.messages), 1)
     self._verify_warning(self.logger.messages[0], 'INT',
                          'java.lang.IllegalArgumentException: xxx')
 def test_error_messages(self):
     def raise_value_error(signum, handler):
         raise ValueError("Got signal %d" % signum)
     signal.signal = raise_value_error
     _StopSignalMonitor().start()
     assert_equal(len(self.logger.messages), 2)
     self._verify_warning(self.logger.messages[0], 'INT',
                          'Got signal %d' % signal.SIGINT)
     self._verify_warning(self.logger.messages[1], 'TERM',
                          'Got signal %d' % signal.SIGTERM)
Beispiel #4
0
 def test_illegal_argument_exception(self):
     from java.lang import IllegalArgumentException
     def raise_iae_for_sigint(signum, handler):
         if signum == signal.SIGINT:
             raise IllegalArgumentException('xxx')
     signal.signal = raise_iae_for_sigint
     _StopSignalMonitor().start()
     assert_equal(len(self.logger.messages), 1)
     self._verify_warning(self.logger.messages[0], 'INT',
                          'java.lang.IllegalArgumentException: xxx')
 def test_restore_when_failure(self):
     try:
         with _StopSignalMonitor() as monitor:
             assert_equal(self.get_int(), monitor)
             assert_equal(self.get_term(), monitor)
             raise ZeroDivisionError
     except ZeroDivisionError:
         pass
     else:
         raise AssertionError
     assert_equal(self.get_int(), self.orig_int)
     assert_equal(self.get_term(), self.orig_term)
Beispiel #6
0
 def test_restore_when_failure(self):
     try:
         with _StopSignalMonitor() as monitor:
             assert_equal(self.get_int(), monitor)
             assert_equal(self.get_term(), monitor)
             raise ZeroDivisionError
     except ZeroDivisionError:
         pass
     else:
         raise AssertionError
     assert_signal_handler_equal(signal.SIGINT, self.orig_int)
     assert_signal_handler_equal(signal.SIGTERM, self.orig_term)
Beispiel #7
0
 def test_registered_outside_python(self):
     """
     If a signal isn't registered within Python, signal.getsignal() returns None.
     This tests to make sure _StopSignalMonitor.__exit__ can handle that.
     """
     with _StopSignalMonitor() as monitor:
         assert_equal(self.get_int(), monitor)
         assert_equal(self.get_term(), monitor)
         monitor._orig_sigint = None
         monitor._orig_sigterm = None
     assert_equal(self.get_int(), signal.SIG_DFL)
     assert_equal(self.get_term(), signal.SIG_DFL)
 def test_registered_outside_python(self):
     """
     If a signal isn't registered within Python, signal.getsignal() returns None.
     This tests to make sure _StopSignalMonitor.__exit__ can handle that.
     """
     with _StopSignalMonitor() as monitor:
         assert_equal(self.get_int(), monitor)
         assert_equal(self.get_term(), monitor)
         monitor._orig_sigint = None
         monitor._orig_sigterm = None
     assert_equal(self.get_int(), signal.SIG_DFL)
     assert_equal(self.get_term(), signal.SIG_DFL)
 def test_restore_when_no_failures(self):
     with _StopSignalMonitor() as monitor:
         assert_equal(self.get_int(), monitor)
         assert_equal(self.get_term(), monitor)
     assert_equal(self.get_int(), self.orig_int)
     assert_equal(self.get_term(), self.orig_term)
 def test_failure_but_no_warning_when_not_in_main_thread(self):
     t = Thread(target=_StopSignalMonitor().start)
     t.start()
     t.join()
     assert_equal(len(self.logger.messages), 0)
Beispiel #11
0
 def test_restore_when_no_failures(self):
     with _StopSignalMonitor() as monitor:
         assert_equal(self.get_int(), monitor)
         assert_equal(self.get_term(), monitor)
     assert_signal_handler_equal(signal.SIGINT, self.orig_int)
     assert_signal_handler_equal(signal.SIGTERM, self.orig_term)
Beispiel #12
0
 def test_failure_but_no_warning_when_not_in_main_thread(self):
     t = Thread(target=_StopSignalMonitor().__enter__)
     t.start()
     t.join()
     assert_equal(len(self.logger.messages), 0)
Beispiel #13
0
 def test_restore_when_no_failures(self):
     with _StopSignalMonitor() as monitor:
         assert_equal(self.get_int(), monitor)
         assert_equal(self.get_term(), monitor)
     assert_equal(self.get_int(), self.orig_int)
     assert_equal(self.get_term(), self.orig_term)