def test_bridge_np_int16(tempdir): import numpy as np client, server = setup_client_server(tempdir) ldtype = np.dtype('<u2') bdtype = np.dtype('>u2') server.add_channel('npl', gr.NpChannel((2, 2), ldtype)) server.add_channel('npb', gr.NpChannel((2, 2), bdtype)) start_bridge(client, server) assert set(server._channels.keys()) == {'npl', 'npb'} assert set(client._channels.keys()) == {'npl', 'npb'} assert server._channels['npl'].dtype == client._channels['npl'].dtype assert server._channels['npb'].dtype == client._channels['npb'].dtype server._channels['npl'].value = np.array((1, 0x100), ldtype) server.send() client.recv() assert (server._channels['npl'].value == [1, 0x100]).all() assert (client._channels['npl'].value == [1, 0x100]).all() server._channels['npl'].value = np.array((0x100, 1), ldtype) server.send() client.recv() assert (server._channels['npl'].value == [0x100, 1]).all() assert (client._channels['npl'].value == [0x100, 1]).all() server._channels['npb'].value = np.array((1, 0x100), bdtype) server.send() client.recv() assert (server._channels['npb'].value == [1, 0x100]).all() assert (client._channels['npb'].value == [1, 0x100]).all() server._channels['npb'].value = np.array((0x100, 1), bdtype) server.send() client.recv() assert (server._channels['npb'].value == [0x100, 1]).all() assert (client._channels['npb'].value == [0x100, 1]).all()
def test_bridge_server_noclient_clean(tempdir): import numpy as np server = gr.Bridge(tempdir) server.listen() server.add_channel('np', gr.NpChannel((2, 2), int)) assert list(server._channels.keys()) == ['np'] assert os.path.exists(os.path.join(tempdir, 'sock')) assert os.path.exists(os.path.join(tempdir, 'np')) server.close('disconnect') assert not os.path.exists(os.path.join(tempdir, 'sock')) assert not os.path.exists(os.path.join(tempdir, 'np'))
def test_bridge_clean(tempdir): import numpy as np client, server = setup_client_server(tempdir) server.add_channel('np', gr.NpChannel((2, 2), int)) start_bridge(client, server) assert list(server._channels.keys()) == ['np'] assert list(client._channels.keys()) == ['np'] assert os.path.exists(os.path.join(tempdir, 'sock')) assert os.path.exists(os.path.join(tempdir, 'np')) client.close() server.close() assert not os.path.exists(os.path.join(tempdir, 'sock')) assert not os.path.exists(os.path.join(tempdir, 'np'))
def test_bridge_server_clean(tempdir): import numpy as np client, server = setup_client_server(tempdir) server.add_channel('np', gr.NpChannel((2, 2), int)) start_bridge(client, server) assert list(server._channels.keys()) == ['np'] assert list(client._channels.keys()) == ['np'] assert os.path.exists(os.path.join(tempdir, 'sock')) assert os.path.exists(os.path.join(tempdir, 'np')) server.close('disconnect') try: client.recv() except gr.Bridge.Closed as e: assert str(e) == 'disconnect' assert not os.path.exists(os.path.join(tempdir, 'sock')) assert not os.path.exists(os.path.join(tempdir, 'np'))
def test_bridge_np(tempdir): import numpy as np client, server = setup_client_server(tempdir) server.add_channel('np', gr.NpChannel((2, 2), int)) start_bridge(client, server) assert list(server._channels.keys()) == ['np'] assert list(client._channels.keys()) == ['np'] server._channels['np'].value = np.zeros((2, 2), int) server.send() client.recv() assert (server._channels['np'].value == np.zeros((2, 2))).all() assert (client._channels['np'].value == np.zeros((2, 2))).all() server._channels['np'].value = np.ones((2, 2), int) server.send() client.recv() assert (server._channels['np'].value == np.ones((2, 2))).all() assert (client._channels['np'].value == np.ones((2, 2))).all()