Пример #1
0
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
Пример #2
0
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
Пример #3
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), ),
    ]