def test_stop_process_clean(mocker):
    mock_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill')
    mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    app_task = AppTask(MagicMock(), MagicMock())
    app_task._process = MagicMock()
    app_task._process.is_alive = MagicMock(return_value=True)
    app_task._process.pid = 321
    app_task._process.exitcode = 123
    app_task._stop_dev_server()
    assert mock_kill.called_once_with(321, 2)
def test_stop_process_dead(smart_caplog, mocker):
    mock_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill')
    mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    app_task = AppTask(MagicMock(), MagicMock())
    app_task._process = MagicMock()
    app_task._process.is_alive = MagicMock(return_value=False)
    app_task._process.exitcode = 123
    app_task._stop_dev_server()
    assert 'server process already dead, exit code: 123' in smart_caplog
    assert mock_kill.called is False
Beispiel #3
0
async def test_stop_process_dirty(mocker):
    mock_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill')
    mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    app_task = AppTask(MagicMock())
    process_mock = MagicMock()
    app_task._process = process_mock
    process_mock.is_alive = MagicMock(return_value=True)
    process_mock.pid = 321
    process_mock.exitcode = None
    app_task._stop_dev_server()
    assert mock_kill.call_args_list == [call(321, 2)]
    assert process_mock.kill.called_once()
def test_stop_process_dirty(mocker):
    mock_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill')
    mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    app_task = AppTask(MagicMock(), MagicMock())
    app_task._process = MagicMock()
    app_task._process.is_alive = MagicMock(return_value=True)
    app_task._process.pid = 321
    app_task._process.exitcode = None
    app_task._stop_dev_server()
    assert mock_kill.call_args_list == [
        call(321, 2),
        call(321, 9),
    ]
Beispiel #5
0
async def test_multiple_file_change(loop, mocker):
    mocked_awatch = mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    mocked_awatch.side_effect = create_awatch_mock({('x', '/path/to/file'), ('x', '/path/to/file2')})
    mock_src_reload = mocker.patch('aiohttp_devtools.runserver.watch.src_reload', return_value=create_future())
    app_task = AppTask(MagicMock(), loop)
    app_task._start_dev_server = MagicMock()
    app_task._stop_dev_server = MagicMock()

    app_task._app = MagicMock()
    await app_task._run()
    mock_src_reload.assert_called_once_with(app_task._app)
    assert app_task._start_dev_server.call_count == 1
    await app_task._session.close()
async def test_python_no_server(loop, mocker):
    mocked_awatch = mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    mocked_awatch.side_effect = create_awatch_mock({('x', '/path/to/file.py')})

    config = MagicMock()
    config.main_port = 8000
    app_task = AppTask(config, loop)
    app_task._start_dev_server = MagicMock()
    app_task._stop_dev_server = MagicMock()
    app_task._app = MagicMock()
    await app_task._run()
    assert app_task._app.src_reload.called is False
    assert app_task._start_dev_server.called
    assert app_task._stop_dev_server.called
    await app_task._session.close()
async def test_single_file_change(loop, mocker):
    mocked_awatch = mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    mocked_awatch.side_effect = create_awatch_mock()
    mock_src_reload = mocker.patch('aiohttp_devtools.runserver.watch.src_reload', return_value=create_future())

    app_task = AppTask(MagicMock())
    app_task._start_dev_server = MagicMock()
    app_task._stop_dev_server = MagicMock()
    app = MagicMock()
    await app_task.start(app)
    d = {'static_path': '/path/to/'}
    app_task._app.__getitem__.side_effect = d.__getitem__
    await app_task._task
    mock_src_reload.assert_called_once_with(app, '/path/to/file')
    assert app_task._start_dev_server.call_count == 1
    assert app_task._stop_dev_server.called is False
    await app_task._session.close()
Beispiel #8
0
async def test_python_no_server(loop, mocker):
    mocked_awatch = mocker.patch('aiohttp_devtools.runserver.watch.awatch')
    mocked_awatch.side_effect = create_awatch_mock({('x', '/path/to/file.py')})

    config = MagicMock()
    config.main_port = 8000
    app_task = AppTask(config, loop)
    app_task._start_dev_server = MagicMock()
    app_task._stop_dev_server = MagicMock()
    app = Application()
    app.src_reload = MagicMock()
    mock_ws = MagicMock()
    f = asyncio.Future()
    f.set_result(1)
    mock_ws.send_str = MagicMock(return_value=f)
    app['websockets'] = [(mock_ws, '/')]
    app_task._app = app
    await app_task._run(2)
    assert app_task._app.src_reload.called is False
    assert app_task._start_dev_server.called
    assert app_task._stop_dev_server.called
    await app_task._session.close()