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))
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
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
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
def test_decode_invalid_packet_protocol_version(): with pytest.raises(ValueError): Packet.from_bytes(b'000000000000')
def test_decode_invalid_data_length(): with pytest.raises(ValueError): Packet.from_bytes(b'dummy')