Exemple #1
0
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()
Exemple #2
0
def test_runner_stop_with_callback(loop_mock):
    callback = mock.Mock()
    runner = LoaferRunner(on_stop_callback=callback)

    runner.stop()

    assert callback.called
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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()
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
def test_runner_stop():
    runner = LoaferRunner(loop=mock.Mock())
    runner.stop()
    assert runner.loop.stop.called
Exemple #9
0
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