Ejemplo n.º 1
0
def test_msg():
    data = list(b'asdf' * x for x in range(256))
    byte_data_gen = msg_to_bytes(data)
    total_len = next(byte_data_gen)
    mv = memoryview(b''.join(byte_data_gen))
    recreated_data = list(msg_from_bytes(mv))
    assert data == recreated_data
Ejemplo n.º 2
0
def test_memoryview_wrapper():
    data = list(b'asdf' * x for x in range(256))
    byte_data_gen = msg_to_bytes(data)
    total_len = next(byte_data_gen)
    bytes = b''.join(byte_data_gen)
    mv = memoryview(bytes)
    assert getrefcount(bytes) == 1 + 1 + 1
    assert getrefcount(mv) == 1 + 1
    recreated_data = list(msg_from_bytes(mv))
    assert getrefcount(bytes) == 1 + 1 + 1
    del mv
    del recreated_data
    assert getrefcount(bytes) == 1 + 1
Ejemplo n.º 3
0
def test_error_when_storing_msgs():
    class Protocol(MessageProtocol):
        def process_msg(self, msg):
            self.msg = msg

    class Protocol2(MessageProtocol):
        def process_msg(self, msg):
            self.msg = [m.tobytes() for m in msg]

    x = Protocol()
    data = b''.join(msg_to_bytes([b'asdf', b'asdf', b'asdf']))
    with pytest.raises(Exception):
        x.data_received(data)

    x = Protocol2()
    x.data_received(data)