Esempio n. 1
0
async def test_uds_server(event_loop, tmpdir_factory):
    path = str(tmpdir_factory.mktemp("uds") / "my_uds")

    # Not availble on windows
    if compat.platform == "win32":
        with pytest.raises(ValueError):
            await start_console_server(path=path, banner="test")
        return

    server = await start_console_server(path=path, banner="test")

    stream = io.StringIO()
    print_server(server, "test console", file=stream)
    expected = f"The test console is being served on {path}\n"
    assert stream.getvalue() == expected

    address = server.sockets[0].getsockname()
    reader, writer = await asyncio.open_unix_connection(address)
    assert (await reader.readline()) == b"test\n"
    writer.write(b"1+1\n")
    assert (await reader.readline()) == b">>> 2\n"
    writer.write_eof()
    assert (await reader.readline()) == b">>> \n"
    writer.close()
    if compat.PY37:
        await writer.wait_closed()
    server.close()
    await server.wait_closed()
Esempio n. 2
0
def main(args=None):
    host, port, serve_cli = parse_args(args)
    if serve_cli:
        cli_host, cli_port = serve_cli
        coro = start_interactive_server(make_cli, cli_host, cli_port)
        server = asyncio.get_event_loop().run_until_complete(coro)
        print_server(server, 'command line interface')
    else:
        asyncio.async(make_cli().interact())
    return echo.run(host, port)
Esempio n. 3
0
async def test_server(event_loop):
    server = await start_console_server(host="127.0.0.1", port=0, banner="test")
    address = server.sockets[0].getsockname()

    stream = io.StringIO()
    print_server(server, "test console", file=stream)
    expected = f"The test console is being served on 127.0.0.1:{address[1]}\n"
    assert stream.getvalue() == expected

    reader, writer = await asyncio.open_connection(*address)
    assert (await reader.readline()) == b"test\n"
    writer.write(b"1+1\n")
    assert (await reader.readline()) == b">>> 2\n"
    writer.write_eof()
    assert (await reader.readline()) == b">>> \n"
    writer.close()
    if compat.PY37:
        await writer.wait_closed()
    server.close()
    await server.wait_closed()
Esempio n. 4
0
def test_uds_server(event_loop, tmpdir):
    path = str(tmpdir / "test.uds")
    server = yield from start_console_server(path=path, banner='test')

    stream = io.StringIO()
    print_server(server, "test console", file=stream)
    expected = "The test console is being served on {}\n"
    assert stream.getvalue() == expected.format(path)

    address = server.sockets[0].getsockname()
    reader, writer = yield from asyncio.open_unix_connection(address)
    assert (yield from reader.readline()) == b'test\n'
    writer.write(b'1+1\n')
    assert (yield from reader.readline()) == b'>>> 2\n'
    writer.write_eof()
    assert (yield from reader.readline()) == b'>>> \n'
    writer.close()
    if compat.PY37:
        yield from writer.wait_closed()
    server.close()
    yield from server.wait_closed()
Esempio n. 5
0
def test_server(event_loop):
    server = yield from start_console_server(host="127.0.0.1",
                                             port=0,
                                             banner='test')
    address = server.sockets[0].getsockname()

    stream = io.StringIO()
    print_server(server, "test console", file=stream)
    expected = "The test console is being served on 127.0.0.1:{}\n"
    assert stream.getvalue() == expected.format(address[1])

    reader, writer = yield from asyncio.open_connection(*address)
    assert (yield from reader.readline()) == b'test\n'
    writer.write(b'1+1\n')
    assert (yield from reader.readline()) == b'>>> 2\n'
    writer.write_eof()
    assert (yield from reader.readline()) == b'>>> \n'
    writer.close()
    if compat.PY37:
        yield from writer.wait_closed()
    server.close()
    yield from server.wait_closed()