Example #1
0
def test_decode_invalid_packet_checksum():

    encoded = Packet.data(
        checksum_mode=ChecksumMode.Disabled,
        transfer_mode=TransferMode.AckLastFragmentOnly,
        fragment_amount=1,
        fragment_number=0,
        message_id=1,
        payload_data=b'dummy',
    )

    encoded._checksum = 12345

    with pytest.raises(ValueError):
        Packet.from_bytes(bytes(encoded))
Example #2
0
def test_encode_decode_sync_checksum_mode_disabled():

    encoded = Packet.sync(checksum_mode=ChecksumMode.Disabled, )

    encoded_bytes = bytes(encoded)

    decoded = Packet.from_bytes(encoded_bytes)
    decoded_bytes = decoded.as_bytes

    assert encoded_bytes == decoded_bytes
Example #3
0
def test_encode_decode_data_ack_last_fragment_only():

    encoded = Packet.data(
        checksum_mode=ChecksumMode.Disabled,
        transfer_mode=TransferMode.AckLastFragmentOnly,
        fragment_amount=1,
        fragment_number=0,
        message_id=1,
        payload_data=b'dummy',
    )

    encoded_bytes = bytes(encoded)

    decoded = Packet.from_bytes(encoded_bytes)
    decoded_bytes = decoded.as_bytes

    assert encoded_bytes == decoded_bytes
Example #4
0
def test_encode_decode_data():

    encoded = Packet.data(
        checksum_mode=ChecksumMode.Disabled,
        transfer_mode=TransferMode.AckEveryPacket,
        fragment_amount=10,
        fragment_number=5,
        message_id=12345,
        payload_data=b'dummy',
    )

    encoded_bytes = bytes(encoded)

    decoded = Packet.from_bytes(encoded_bytes)
    decoded_bytes = decoded.as_bytes

    assert encoded_bytes == decoded_bytes
Example #5
0
def test_decode_invalid_packet_protocol_version():

    with pytest.raises(ValueError):
        Packet.from_bytes(b'000000000000')
Example #6
0
def test_decode_invalid_data_length():

    with pytest.raises(ValueError):
        Packet.from_bytes(b'dummy')