コード例 #1
0
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)
コード例 #2
0
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
コード例 #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()
コード例 #4
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')})
    app_task = AppTask(MagicMock(), loop)
    app_task._start_process = MagicMock()
    app_task.stop_process = MagicMock()

    app_task._app = MagicMock()
    await app_task._run()
    app_task._app.src_reload.assert_called_once_with()
    app_task._session.close()
コード例 #5
0
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),
    ]
コード例 #6
0
async def test_reload_server_running(loop, test_client):
    app = Application()
    app['websockets'] = [None]
    app.src_reload = MagicMock()
    cli = await test_client(app)
    config = MagicMock()
    config.main_port = cli.server.port

    app_task = AppTask(config, loop)
    app_task._app = app
    await app_task._src_reload_when_live(2)
    app.src_reload.assert_called_once_with()
    app_task._session.close()
コード例 #7
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()
コード例 #8
0
async def test_reload_server_running(loop, aiohttp_client, mocker):
    app = Application()
    app['websockets'] = [None]
    mock_src_reload = mocker.patch('aiohttp_devtools.runserver.watch.src_reload', return_value=create_future())
    cli = await aiohttp_client(app)
    config = MagicMock()
    config.main_port = cli.server.port

    app_task = AppTask(config, loop)
    app_task._app = app
    await app_task._src_reload_when_live(2)
    mock_src_reload.assert_called_once_with(app)
    await app_task._session.close()
コード例 #9
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_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()
コード例 #10
0
async def test_single_file_change(loop, mocker):
    mocker.patch('aiohttp_devtools.runserver.watch.awatch',
                 side_effect=create_awatch_mock())
    mocked_start_main_app = mocker.patch(
        'aiohttp_devtools.runserver.watch.start_main_app')
    mocked_start_main_app.side_effect = fake_start_main_app
    mock_src_reload = mocker.patch(
        'aiohttp_devtools.runserver.watch.src_reload',
        return_value=create_future())

    app_task = AppTask(MagicMock(), loop)
    app_task._app = MagicMock()
    await app_task._run()
    mock_src_reload.assert_called_once_with(app_task._app, '/path/to/file')
    assert mocked_start_main_app.call_count == 1
    await app_task._session.close()
コード例 #11
0
async def test_python_no_server(event_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)
    start_mock = mocker.patch.object(app_task, "_start_dev_server", autospec=True)
    stop_mock = mocker.patch.object(app_task, "_stop_dev_server", autospec=True)
    mocker.patch.object(app_task, "_run", partial(app_task._run, live_checks=2))
    app = Application()
    app['static_path'] = '/path/to/'
    app.src_reload = MagicMock()
    mock_ws = MagicMock()
    f: asyncio.Future[int] = asyncio.Future()
    f.set_result(1)
    mock_ws.send_str = MagicMock(return_value=f)
    app['websockets'] = [(mock_ws, '/')]
    await app_task.start(app)
    assert app_task._task is not None
    await app_task._task
    assert config.src_reload.called is False
    assert start_mock.called
    assert stop_mock.called
    assert app_task._session is not None
    await app_task._session.close()
コード例 #12
0
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()
コード例 #13
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')})
    mocked_start_main_app = mocker.patch(
        'aiohttp_devtools.runserver.watch.start_main_app')
    mocked_start_main_app.side_effect = fake_start_main_app
    mock_src_reload = mocker.patch(
        'aiohttp_devtools.runserver.watch.src_reload',
        return_value=create_future())

    config = MagicMock()
    config.main_port = 8000
    app_task = AppTask(config, loop)
    app_task._app = MagicMock()
    await app_task._run()
    assert mock_src_reload.call_count == 0
    assert mocked_start_main_app.call_count == 2
    await app_task._session.close()
コード例 #14
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()
コード例 #15
0
async def test_multiple_file_change(event_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())
    start_mock = mocker.patch.object(app_task, "_start_dev_server", autospec=True)
    mocker.patch.object(app_task, "_stop_dev_server", autospec=True)

    app = MagicMock()
    await app_task.start(app)
    assert app_task._task is not None
    await app_task._task
    mock_src_reload.assert_called_once_with(app)
    assert start_mock.call_count == 1
    assert app_task._session is not None
    await app_task._session.close()