Beispiel #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()
Beispiel #2
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
Beispiel #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
Beispiel #4
0
def test_runner_prepare_stop(loop_mock):
    loop_mock.return_value.is_running.return_value = True
    runner = LoaferRunner()

    runner.prepare_stop()

    loop_mock.return_value.stop.assert_called_once_with()
Beispiel #5
0
def test_runner_stop_with_callback(loop_mock):
    callback = mock.Mock()
    runner = LoaferRunner(on_stop_callback=callback)

    runner.stop()

    assert callback.called
Beispiel #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
Beispiel #7
0
def test_runner_prepare_stop_already_stopped(get_loop_mock):
    loop = mock.Mock(is_running=mock.Mock(return_value=False))
    get_loop_mock.return_value = loop
    runner = LoaferRunner()

    runner.prepare_stop()

    loop.is_running.assert_called_once_with()
    assert loop.stop.called is False
Beispiel #8
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()
Beispiel #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
Beispiel #10
0
def test_runner_prepare_stop():
    runner = LoaferRunner(loop=mock.Mock())
    runner.prepare_stop()
    runner.loop.stop.assert_called_once_with()
Beispiel #11
0
def test_runner_start_with_debug():
    loop = mock.Mock()
    runner = LoaferRunner(loop=loop)
    runner.start(debug=True)
    assert loop.set_debug.called_once_with(enabled=True)
Beispiel #12
0
def test_runner_start():
    runner = LoaferRunner(loop=mock.Mock())
    runner.start()
    assert runner.loop.run_forever.called
Beispiel #13
0
def test_runner_start_with_debug(loop_mock):
    runner = LoaferRunner()

    runner.start(debug=True)

    loop_mock.return_value.set_debug.assert_called_once_with(enabled=True)
Beispiel #14
0
def test_runner_with_cancelled_error():
    runner = LoaferRunner(loop=mock.Mock())
    runner.loop.run_forever.side_effect = CancelledError
    runner.start()
    assert runner.loop.run_forever.called
    assert runner.loop.close.called
Beispiel #15
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
Beispiel #16
0
def test_runner_start_with_debug():
    loop = mock.Mock()
    runner = LoaferRunner(loop=loop)
    runner.start(debug=True)
    loop.set_debug.assert_called_once_with(enabled=True)
Beispiel #17
0
def test_runner_prepare_stop():
    runner = LoaferRunner(loop=mock.Mock())
    runner.prepare_stop()
    runner.loop.stop.assert_called_once_with()
Beispiel #18
0
def test_runner_prepare_stop_already_stopped():
    loop = mock.Mock(is_running=mock.Mock(return_value=False))
    runner = LoaferRunner(loop=loop)
    runner.prepare_stop()
    loop.is_running.assert_called_once_with()
    assert loop.stop.called is False
Beispiel #19
0
def test_runner_start(loop_mock):
    runner = LoaferRunner()

    runner.start()

    assert loop_mock.return_value.run_forever.called
Beispiel #20
0
def test_runner_stop():
    runner = LoaferRunner(loop=mock.Mock())
    runner.stop()
    assert runner.loop.stop.called