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_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()
def test_recv_invalid_addr_msg_structure(): ctx = Context() pull = ctx.socket(PULL) push = ctx.socket(PUSH) pull.bind('inproc://foo') push.connect('inproc://foo') push.send_multipart([b'foo', b'', b'', b'']) with pytest.raises(IOError): pull.recv_addr_msg()
def test_decoding_unknown_type(): ctx = Context() pull = ctx.socket(PULL) push = ctx.socket(PUSH) pull.bind('inproc://foo') push.connect('inproc://foo') push.send(cbor2.dumps(cbor2.CBORTag(4000, None))) 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_hwm_attr(): ctx = Context() sock = ctx.socket(PULL) sock.hwm = 10 assert sock.hwm == 10