Ejemplo n.º 1
0
    def test_signals_as_iterable_of_numbers_or_names(self):
        cm = catch_signals(signals=(x for x in (SIG1, SIG2)))
        self.assertEqual(cm._signals, tuple([SIG1, SIG2]))

        cm = catch_signals(signals=[SIG1.name, SIG2.name])
        self.assertEqual(cm._signals, tuple([SIG1, SIG2]))

        cm = catch_signals(signals=[SIG1.value, SIG2.value])
        self.assertEqual(cm._signals, tuple([SIG1, SIG2]))

        cm = catch_signals(signals=[SIG1.value, SIG2.name])
        self.assertEqual(cm._signals, tuple([SIG1, SIG2]))
Ejemplo n.º 2
0
 def test_special_sigint_message(self):
     with self.assertLogs('wrapitup') as logcm:
         with catch_signals(signals=[SIGINT]):
             self.suicide(KILLINT)
     self.assertEqual(len(logcm.output), 2)
     self.assertRegex(
         logcm.output[0],
         r'INFO:wrapitup:Process \d+ now listening for shut down signals: SIGINT'
     )
     self.assertRegex(
         logcm.output[1],
         (r'WARNING:wrapitup:Commencing shut down. \(Signal [A-Z1-9]{6,7},'
          r' process \d+.\). Press Ctrl\+C again to exit immediately.'))
Ejemplo n.º 3
0
 def test_default_shutdown_signals(self):
     old_handlers = self.get_handlers()
     with catch_signals():
         new_handlers = self.get_handlers()
     reset_handlers = self.get_handlers()
     # Known: len(old_handlers) == len(new_handlers) == signal.NSIG
     diff = []
     for signum in range(signal.NSIG):
         if old_handlers[signum] != new_handlers[signum]:
             diff.append(signum)
     self.assertCountEqual(diff, EXPECTED_DEFAULT_SIGNALS)
     # Just so we know the test didn't pollute the environment:
     self.assertEqual(old_handlers, reset_handlers)
Ejemplo n.º 4
0
 def test_windows_unsupported_signals(self):
     with self.assertRaisesRegex(ValueError, "Windows.*SIGTERM"):
         with catch_signals(signals=[signal.SIGTERM]):
             self.fail(
                 "should have ValueErrored before now")  # pragma: no cover
Ejemplo n.º 5
0
 def test_signals_list_empty(self):
     with self.assertRaisesRegex(ValueError, 'No signals selected'):
         with catch_signals(signals=[]):
             pass  # pragma: no coverage
Ejemplo n.º 6
0
 def catch_signals(self, callback=None):
     return catch_signals(signals=(SIG1, SIG2), callback=callback)