def test_recv_unexpected_data(): ctx = Context() pull = ctx.socket(PULL, protocol=Protocol(recv={'FOO': NoData})) push = ctx.socket(PUSH, protocol=Protocol(send={'FOO': int})) pull.bind('inproc://foo') push.connect('inproc://foo') push.send_msg('FOO', 1) with pytest.raises(IOError): pull.recv_msg() push.close() pull.close()
def test_recv_bad_data_from_msg(): ctx = Context() pull = ctx.socket(PULL, protocol=Protocol(recv={'FOO': int})) push = ctx.socket(PUSH, protocol=Protocol(send={'FOO': str})) pull.bind('inproc://foo') push.connect('inproc://foo') push.send_msg('FOO', 'bar') with pytest.raises(IOError): pull.recv_msg() push.close() pull.close()
def test_subscribe(): ctx = Context() pub = ctx.socket(PUB, protocol=Protocol(send={'FOO': int})) sub = ctx.socket(SUB, protocol=Protocol(recv={'FOO': int})) pub.bind('inproc://foo') sub.connect('inproc://foo') sub.subscribe('') pub.send_msg('FOO', 1) assert sub.recv_msg() == ('FOO', 1) sub.unsubscribe('') pub.send_msg('FOO', 2) assert not sub.poll(0.5) sub.close() pub.close()
def test_encoding_unknown_type(): protocol = Protocol(recv={'FOO': Exception}) ctx = Context() pull = ctx.socket(PULL, protocol=protocol) push = ctx.socket(PUSH, protocol=reversed(protocol)) pull.bind('inproc://foo') push.connect('inproc://foo') with pytest.raises(IOError): push.send_msg('FOO', NotImplementedError()) push.close() pull.close()
def test_send_bad_data_for_msg(): protocol = Protocol(recv={'FOO': int}) ctx = Context() pull = ctx.socket(PULL, protocol=protocol) push = ctx.socket(PUSH, protocol=reversed(protocol)) pull.bind('inproc://foo') push.connect('inproc://foo') with pytest.raises(IOError): push.send_msg('FOO', 'bar') push.close() pull.close()
def test_timedelta_roundtrip(): protocol = Protocol(recv={'FOO': dt.timedelta}) ctx = Context() pull = ctx.socket(PULL, protocol=protocol) push = ctx.socket(PUSH, protocol=reversed(protocol)) pull.bind('inproc://foo') push.connect('inproc://foo') delta = dt.timedelta(minutes=5) push.send_msg('FOO', delta) assert pull.recv_msg() == ('FOO', delta) push.close() pull.close()
def test_ipaddress_roundtrip(): protocol = Protocol(recv={'FOO': Any(ip.IPv4Address, ip.IPv6Address)}) ctx = Context() pull = ctx.socket(PULL, protocol=protocol) push = ctx.socket(PUSH, protocol=reversed(protocol)) pull.bind('inproc://foo') push.connect('inproc://foo') address4 = ip.IPv4Address('192.168.0.1') address6 = ip.IPv6Address('::1') push.send_msg('FOO', address4) assert pull.recv_msg() == ('FOO', address4) push.send_msg('FOO', address6) assert pull.recv_msg() == ('FOO', address6) push.close() pull.close()