def setUp(self): import zmq self.cout = zchan.ChannelOut(zmq.PUSH, "ipc:///tmp/test_channel_in") self.cin = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_channel_in") self.cout.bind() self.cin.connect()
def test_proxy_not_connected(self): cin = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_channel_socket_in") cout = zchan.ChannelOut(zmq.PUB, "ipc:///tmp/test_channel_socket_out") chan = zchan.Channel(cin, cout) with self.assertRaises(excs.NotConnected): chan.proxy()
def setUp(self): self.cin = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_channel_socket_in") self.cout = zchan.ChannelOut(zmq.PUB, "ipc:///tmp/test_channel_socket_out") self.cin.bind() self.cout.bind()
def test_auto_register_socket(self): chan = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_bind_twice_in") chan.bind() pollr = zchan.Poller() exit_condition = ProcessEvent() # set condition to immediately exit event loop exit_condition.set() self.assertEqual(len(pollr.sockets), 0) chan.poll(pollr, exit_condition) self.assertEqual(len(pollr.sockets), 1)
def test_polling(self): chan = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_bind_twice_in") chan.bind() pollr = zchan.Poller() exit_condition = ProcessEvent() def send_something(): chan = zchan.ChannelOut(zmq.PUSH, "ipc:///tmp/test_bind_twice_in") chan.connect() chan.send(b"something", sync=False) send_something() # set condition to immediately exit event loop self.assertEqual(len(pollr.sockets), 0) chan.poll(pollr, exit_condition) self.assertEqual(len(pollr.sockets), 1)
def test_send_without_connecting(self): chan = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_i_dont_exist") with self.assertRaises(excs.NotConnected): chan.receive() chan.close()
def test_connect_twice(self): chan = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_connect_twice_in") chan.connect() with self.assertRaises(excs.AlreadyConnected): chan.connect() chan.close()
def test_poll_not_connected(self): chan = zchan.ChannelIn(zmq.PULL, "ipc:///tmp/test_bind_twice_in") with self.assertRaises(excs.NotConnected): pollr = zchan.Poller() exit_condition = ProcessEvent() chan.poll(pollr, exit_condition)