예제 #1
0
def test_send_receive_with_none_context():
    """
    Test attempting to start a TCP server using context values, with no context
    set. Verify expected ValueError is raised.
    """
    with path.TemporaryDirectory() as runpath:
        client = TCPClient(name='client',
                           host=context('server', '{{host}}'),
                           port=context('server', '{{port}}'),
                           runpath=runpath)
    with pytest.raises(ValueError):
        client.start()
예제 #2
0
def http_server():
    """Start and yield an HTTP server driver."""
    with path.TemporaryDirectory() as runpath:
        server = http.HTTPServer(
            name="http_server",
            host="localhost",
            port=0,
            runpath=runpath,
        )

        with server:
            yield server
예제 #3
0
def tcp_client(tcp_server):
    """Start and yield a TCP client driver."""
    with path.TemporaryDirectory() as runpath:
        client = TCPClient(
            name="client",
            host=tcp_server.host,
            port=tcp_server.port,
            runpath=runpath,
        )

        with client:
            yield client
예제 #4
0
def http_client(http_server):
    """Start and yield an HTTP client."""
    with path.TemporaryDirectory() as runpath:
        client = http.HTTPClient(
            name="http_client",
            host=http_server.host,
            port=http_server.port,
            timeout=10,
            runpath=runpath,
        )

        with client:
            yield client
예제 #5
0
def test_tempdir():
    """
    Test the TemporaryDirectory context manager.

    On python 3 this is just tempfile.TemporaryDirectory so it's not very
    interesting, but for python 2 we use our home baked backport, so it should
    have a test!
    """
    with path.TemporaryDirectory() as tmpdir:
        assert os.path.isdir(tmpdir)

    # Path no longer exists outside of context mgr.
    assert not os.path.exists(tmpdir)
예제 #6
0
def tcp_server():
    """Start and yield a TCP server driver."""
    with path.TemporaryDirectory() as runpath:
        env = Environment()
        server = TCPServer(
            name="server",
            host="localhost",
            port=0,
            runpath=runpath,
        )
        env.add(server)

        with server:
            yield server
예제 #7
0
def test_send_receive_with_context(tcp_server):
    """
    Test starting a TCP client with the host/port information extracted from the
    server via context values.
    """
    with path.TemporaryDirectory() as runpath:
        client = TCPClient(name='context_client',
                           host=context('server', '{{host}}'),
                           port=context('server', '{{port}}'),
                           runpath=runpath)
        tcp_server.context.add(client)

        with client:
            assert client.host
            assert client.port
            send_receive_message(tcp_server, client)
예제 #8
0
def runpath_module():
    with path.TemporaryDirectory() as runpath:
        yield runpath
예제 #9
0
def runpath_class():
    with path.TemporaryDirectory() as runpath:
        yield runpath