예제 #1
0
    def test__add_callback_cancelled_handle(self):
        h = events.Handle(lambda: False, ())
        h.cancel()

        self.loop._add_callback(h)
        self.assertFalse(self.loop._scheduled)
        self.assertFalse(self.loop._ready)
예제 #2
0
 def test_handle_signal_cancelled_handler(self):
     h = events.Handle(unittest.mock.Mock(), ())
     h.cancel()
     self.loop._signal_handlers[signal.NSIG + 1] = h
     self.loop.remove_signal_handler = unittest.mock.Mock()
     self.loop._handle_signal(signal.NSIG + 1, ())
     self.loop.remove_signal_handler.assert_called_with(signal.NSIG + 1)
예제 #3
0
    def test_run_once_in_executor_handle(self):
        def cb():
            pass

        self.assertRaises(AssertionError, self.loop.run_in_executor, None,
                          events.Handle(cb, ()), ('', ))
        self.assertRaises(AssertionError, self.loop.run_in_executor, None,
                          events.TimerHandle(10, cb, ()))
예제 #4
0
    def test_run_once_in_executor_cancelled(self):
        def cb():
            pass

        h = events.Handle(cb, ())
        h.cancel()

        f = self.loop.run_in_executor(None, h)
        self.assertIsInstance(f, futures.Future)
        self.assertTrue(f.done())
        self.assertIsNone(f.result())
예제 #5
0
    def test_run_once_in_executor_plain(self):
        def cb():
            pass

        h = events.Handle(cb, ())
        f = futures.Future(loop=self.loop)
        executor = unittest.mock.Mock()
        executor.submit.return_value = f

        self.loop.set_default_executor(executor)

        res = self.loop.run_in_executor(None, h)
        self.assertIs(f, res)

        executor = unittest.mock.Mock()
        executor.submit.return_value = f
        res = self.loop.run_in_executor(executor, h)
        self.assertIs(f, res)
        self.assertTrue(executor.submit.called)

        f.cancel()  # Don't complain about abandoned Future.
예제 #6
0
    def test__add_callback_handle(self):
        h = events.Handle(lambda: False, ())

        self.loop._add_callback(h)
        self.assertFalse(self.loop._scheduled)
        self.assertIn(h, self.loop._ready)