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)
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)
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, ()))
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())
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.
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)