Ejemplo n.º 1
0
async def test_exit_does_nothing_if_already_exited(mocker):
    ui = TUI()
    ui._app_terminated = True
    mocker.patch.object(ui, '_terminate_jobs', AsyncMock())
    ui._exit()
    assert ui._terminate_jobs.call_args_list == []
    assert ui._app_terminated is True
Ejemplo n.º 2
0
async def test_exit_calls_terminate_jobs(mocker):
    ui = TUI()
    mocker.patch.object(type(ui._app), 'is_running',
                        PropertyMock(return_value=True))
    mocker.patch.object(type(ui._app), 'is_done',
                        PropertyMock(return_value=False))
    mocker.patch.object(type(ui._app), 'exit', Mock())
    mocker.patch.object(ui, '_update_jobs_container', Mock())
    ui._exit()
    await asyncio.sleep(0)
    await asyncio.sleep(0)
    assert ui._app_terminated is True
    assert ui._app.exit.call_args_list == [call()]
    assert ui._update_jobs_container.call_args_list == [call()]
Ejemplo n.º 3
0
async def test_exit_waits_for_application_to_run(mocker, event_loop):
    ui = TUI()
    mocker.patch.object(ui, '_terminate_jobs', AsyncMock())
    mocker.patch.object(type(ui._app), 'is_running',
                        PropertyMock(return_value=False))
    mocker.patch.object(type(ui._app), 'is_done',
                        PropertyMock(return_value=False))
    # If asycnio.call_soon() is still mocked when the test is finished, pytest
    # just hangs. pytest.mark.asyncio seems to depend on it.
    with patch.object(event_loop, 'call_soon'):
        ui._exit()
        assert event_loop.call_soon.call_args_list == [call(ui._exit)]
    assert ui._terminate_jobs.call_args_list == []
    assert ui._app_terminated is False
Ejemplo n.º 4
0
async def test_exit_handles_exception_from_terminate_jobs(mocker):
    ui = TUI()
    mocker.patch.object(type(ui._app), 'is_running',
                        PropertyMock(return_value=True))
    mocker.patch.object(type(ui._app), 'is_done',
                        PropertyMock(return_value=False))
    mocker.patch.object(type(ui._app), 'exit', Mock())
    mocker.patch.object(ui, '_update_jobs_container', Mock())
    mocker.patch.object(ui, '_terminate_jobs',
                        AsyncMock(side_effect=RuntimeError('foo!')))
    ui._exit()
    await asyncio.sleep(0)
    await asyncio.sleep(0)
    await asyncio.sleep(0)
    assert ui._app_terminated is True
    assert ui._app.exit.call_args_list == [call()]
    assert str(ui._exception) == 'foo!'
    assert isinstance(ui._exception, RuntimeError)
    assert ui._update_jobs_container.call_args_list == [call()]