def test_pycode_event(mocker, caplog, loop): mock_process = mocker.patch('aiohttp_devtools.runserver.watch.Process') mock_os_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill') app = MagicMock() config = MagicMock() eh = PyCodeEventHandler(app, config, loop) eh._change_dt = datetime(2017, 1, 1) eh.dispatch(Event(src_path='foo.py')) assert mock_process.call_count == 2 assert mock_os_kill.call_count == 1 assert 'adev.server.dft INFO: Starting dev server at' in caplog assert 'adev.server.dft INFO: Restarting dev server at' in caplog
def test_pycode_event_dead_process(mocker, loop): mock_process = mocker.patch('aiohttp_devtools.runserver.watch.Process') process = MagicMock() process.is_alive = MagicMock(return_value=False) mock_process.return_value = process mock_os_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill') app = MagicMock() config = MagicMock() eh = PyCodeEventHandler(app, config, loop) eh._change_dt = datetime(2017, 1, 1) eh.dispatch(Event(src_path='foo.py')) assert mock_process.call_count == 2 assert mock_os_kill.call_count == 0
def test_pycode_event_process_not_ending(mocker, loop): mock_process = mocker.patch('aiohttp_devtools.runserver.watch.Process') process = MagicMock() process.pid = 123 process.exitcode = None mock_process.return_value = process mock_os_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill') app = MagicMock() config = MagicMock() eh = PyCodeEventHandler(app, config, loop) eh._change_dt = datetime(2017, 1, 1) eh.dispatch(Event(src_path='foo.py')) assert mock_process.call_count == 2 assert mock_os_kill.call_args_list == [ ((123, signal.SIGINT), ), ((123, signal.SIGKILL), ), ]
def test_pycode(mocker, caplog, loop): mock_process = mocker.patch('aiohttp_devtools.runserver.watch.Process') mock_os_kill = mocker.patch('aiohttp_devtools.runserver.watch.os.kill') app = MagicMock() config = MagicMock() PyCodeEventHandler(app, config, loop) mock_process.assert_called_once_with(target=serve_main_app, args=(config, )) assert mock_os_kill.call_count == 0 assert 'adev.server.dft INFO: Starting dev server at' in caplog assert 'adev.server.dft INFO: Restarting dev server at' not in caplog
async def test_pycode_src_reload_when_live_timeout(caplog, loop, mocker, unused_port): caplog.set_level(10) mock_process = mocker.patch('aiohttp_devtools.runserver.watch.Process') process = MagicMock() process.pid = 123 process.exitcode = None mock_process.return_value = process app = MagicMock() app.loop = loop config = MagicMock() config.main_port = unused_port() eh = PyCodeEventHandler(app, config, loop) r = await eh.src_reload_when_live(2) assert r is None assert 'adev.server.dft DEBUG: try 1 | OSError 111 app not running' in caplog assert app.src_reload.call_count == 0
async def test_pycode_src_reload_when_live_no_webs(caplog, loop, mocker, test_client): caplog.set_level(10) mock_process = mocker.patch('aiohttp_devtools.runserver.watch.Process') process = MagicMock() process.pid = 123 process.exitcode = None mock_process.return_value = process app = Application() app['websockets'] = [] app.src_reload = MagicMock() cli = await test_client(app) config = MagicMock() config.main_port = cli.server.port eh = PyCodeEventHandler(app, config, loop) r = await eh.src_reload_when_live(2) assert r is None assert not app.src_reload.called