def test_runner_stop_dont_raise_runtime_error(cancel_all_tasks_mock): cancel_all_tasks_mock.side_effect = RuntimeError("faiô!") runner = LoaferRunner() with does_not_raise(): runner.loop.stop() runner.stop()
def test_runner_stop_with_callback(loop_mock): callback = mock.Mock() runner = LoaferRunner(on_stop_callback=callback) runner.stop() assert callback.called
def test_runner_start_and_stop(): runner = LoaferRunner(loop=mock.Mock()) runner.stop = mock.Mock() runner.start(run_forever=False) assert runner.loop.run_forever.called assert runner.stop.called assert runner.loop.close.called
def test_runner_stop_dont_raise_cancelled_error(): async def some_coro(): raise asyncio.CancelledError() runner = LoaferRunner() loop = runner.loop task = loop.create_task(some_coro()) assert task.done() is False assert task.cancelled() is False runner.stop() assert task.done() is True assert task.cancelled() is True with pytest.raises(asyncio.CancelledError): task.exception()
def test_runner_start_and_stop(loop_mock): runner = LoaferRunner() runner.stop = mock.Mock() runner.start() assert runner.stop.called assert loop_mock.return_value.run_forever.called assert loop_mock.return_value.close.called
def test_runner_stop_with_callback(): callback = mock.Mock() runner = LoaferRunner(loop=mock.Mock(), on_stop_callback=callback) runner.stop() assert runner.loop.stop.called assert callback.called
def test_runner_stop(): runner = LoaferRunner(loop=mock.Mock()) runner.stop() assert runner.loop.stop.called
def test_runner_start_run_until_complete(): runner = LoaferRunner(loop=mock.Mock()) runner.stop = mock.Mock() runner.start(run_forever=False) assert runner.loop.run_until_complete.called assert runner.stop.called