def test_send_disconnected(patch_connection, writer, events, run): ''' Nothing happens when sending after disconnecting ''' conn = Connection("host", "port", events, "UTF-8", True) run(conn.connect()) run(conn.disconnect()) conn.send("test") assert not writer.used
def test_connect_already_connected(patch_connection, writer, events, run): ''' Does not trigger CLIENT_CONNECT multiple times ''' conn = Connection("host", "port", events, "UTF-8", True) run(conn.connect()) run(conn.connect()) assert not writer.closed assert events.triggered("CLIENT_CONNECT")
def test_connect(patch_connection, writer, events, run): ''' Connection.Connect opens a writer, triggers CLIENT_CONNECT ''' conn = Connection("host", "port", events, "UTF-8", True) run(conn.connect()) assert conn.connected assert not writer.closed assert events.triggered("CLIENT_CONNECT")
def test_read_disconnected(patch_connection, reader, events, run): ''' Nothing happens when reading after disconnecting ''' conn = Connection("host", "port", events, "UTF-8", True) run(conn.connect()) run(conn.disconnect()) value = run(conn.read()) assert not value assert not reader.used
def test_disconnect(writer, patch_connection, events, run): ''' Connection.disconnect closes writer, triggers CLIENT_DISCONNECT ''' conn = Connection("host", "port", events, "UTF-8", True) run(conn.connect()) run(conn.disconnect()) assert not conn.connected assert writer.closed assert conn.writer is None assert events.triggered("CLIENT_CONNECT") assert events.triggered("CLIENT_DISCONNECT")
def conn(patch_connection, events, run): ''' Generic connection that is ready to read/send ''' conn = Connection("host", "port", events, "UTF-8", True) run(conn.connect()) assert conn.connected return conn