Esempio n. 1
0
def test_connection():
    """Connection Class Properties."""
    con = pyebus.Connection()
    assert con.host == "127.0.0.1"
    assert con.port == 8888
    assert con.autoconnect == False

    con = pyebus.Connection(host="foo", port=4444, autoconnect=True, timeout=5)
    assert con.host == "foo"
    assert con.port == 4444
    assert con.autoconnect == True

    assert repr(con), "Connection(host='foo', port=4444, autoconnect=True, timeout=5)"
Esempio n. 2
0
def test_stop():
    """Stop Server."""
    server = pyebus.DummyServer(port=UNUSED_PORT)
    con = pyebus.Connection(port=server.port, autoconnect=True)

    async def test():
        await con.async_write("stop")

    run(test, server=server)
Esempio n. 3
0
def test_notconnected():
    """Not Connected."""
    con = pyebus.Connection(port=UNUSED_PORT)

    async def test():
        with pytest.raises(ConnectionError):
            await con.async_write("state")

    run(test)
Esempio n. 4
0
def test_shutdown():
    """Shutdown."""
    server = pyebus.DummyServer(port=UNUSED_PORT)
    con = pyebus.Connection(port=server.port, autoconnect=True)

    async def test():
        with pytest.raises(pyebus.Shutdown):
            await con.async_write("dummyshutdown")
            await con.async_readresp()

    run(test, server=server)
Esempio n. 5
0
def test_command_error():
    """CommandError."""
    server = pyebus.DummyServer(port=UNUSED_PORT)
    con = pyebus.Connection(port=server.port, autoconnect=True)

    async def test():
        with pytest.raises(pyebus.CommandError):
            await con.async_write("unknown")
            await con.async_readresp()

    run(test, server=server)
Esempio n. 6
0
def test_connect_fails():
    """Connection failed."""
    con = pyebus.Connection(port=UNUSED_PORT)

    async def test():
        assert con.is_connected() == False
        with pytest.raises(ConnectionRefusedError):
            await con.async_connect()
        assert con.is_connected() == False

    run(test)
Esempio n. 7
0
def test_trailing():
    """trailing."""
    server = pyebus.DummyServer(port=UNUSED_PORT)
    con = pyebus.Connection(port=server.port, autoconnect=True)

    async def test():
        with pytest.raises(pyebus.CommandError):
            await con.async_write("dummytrailing")
            await con.async_readresp()

    run(test, server=server)
Esempio n. 8
0
def test_connect():
    """Connection succeed."""
    server = pyebus.DummyServer(port=UNUSED_PORT)
    con = pyebus.Connection(port=server.port, timeout=None)

    async def test():
        assert con.is_connected() == False
        await con.async_connect()
        assert con.is_connected() == True
        await con.async_disconnect()
        assert con.is_connected() == False
        await con.async_disconnect()
        assert con.is_connected() == False

    run(test, server=server)