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()
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()