示例#1
0
async def test_run(watch_mock, utils_mock, server_mock):
    mock = AsyncMock()
    mock.no_server, mock.watch, mock.log_stdin = True, False, False

    await main.run(mock)
    await asyncio.sleep(0.1)

    utils_mock.stdin_to_log.assert_not_called()

    mock.log_stdin = True
    await main.run(mock)
    await asyncio.sleep(0.1)
    utils_mock.generate_ssl_context.assert_not_called()
    utils_mock.stdin_to_log.assert_called_once()
    utils_mock.reset_mock()

    watch_mock.assert_not_called()
    server_mock.assert_not_called()

    mock.watch = True
    await main.run(mock)
    await asyncio.sleep(0.1)
    utils_mock.stdin_to_log.assert_called_once()
    watch_mock.assert_called_once()

    mock.log_stdin = False
    await main.run(mock)
    await asyncio.sleep(0.1)
    utils_mock.stdin_to_log.assert_called_once()
    utils_mock.reset_mock()
    watch_mock.reset_mock()

    mock.no_server = False
    mock.listen = "example.org", 2773
    mock.token = None
    utils_mock.generate_ssl_context = MagicMock()
    await main.run(mock)
    await asyncio.sleep(0.1)
    utils_mock.stdin_to_log.assert_not_called()
    server_mock.assert_called_once_with(
        *mock.listen,
        utils_mock.generate_ssl_context.return_value,
        None,
    )

    mock.log_stdin = True
    await main.run(mock)
    await asyncio.sleep(0.1)
    utils_mock.stdin_to_log.assert_called_once()

    mock.cert = False
    server_mock.reset_mock()
    await main.run(mock)
    await asyncio.sleep(0.1)
    server_mock.assert_called_once_with(*mock.listen, None, None)