def test_invalid_ack(): data = Packet.data( checksum_mode=ChecksumMode.Disabled, transfer_mode=TransferMode.AckEveryPacket, fragment_amount=1, fragment_number=0, message_id=1, payload_data=b'dummy', ) packet = Packet.ack(base_packet=data, ) with pytest.raises(ValueError): Packet.ack(base_packet=packet, )
def test_message_type_ack(): data = Packet.data( checksum_mode=ChecksumMode.Disabled, transfer_mode=TransferMode.AckEveryPacket, fragment_amount=1, fragment_number=0, message_id=1, payload_data=b'dummy', ) packet = Packet.ack(base_packet=data, ) assert packet.message_type is MessageType.Ack
def test_is_duplicate_ack_false(): data = Packet.data( checksum_mode=ChecksumMode.Disabled, transfer_mode=TransferMode.AckEveryPacket, fragment_amount=1, fragment_number=0, message_id=1, payload_data=b'dummy', ) packet = Packet.ack(base_packet=data, ) assert not packet.is_duplicate
def test_message_id_and_data_length_ack(): data = Packet.data( checksum_mode=ChecksumMode.Disabled, transfer_mode=TransferMode.AckEveryPacket, fragment_amount=1, fragment_number=0, message_id=12345, payload_data=b'dummy', ) packet = Packet.ack(base_packet=data, ) assert packet.message_id == 12345 assert packet.message_data_length == 0
def test_fragment_ack_multiple_last(): data = Packet.data( checksum_mode=ChecksumMode.Disabled, transfer_mode=TransferMode.AckEveryPacket, fragment_amount=10, fragment_number=9, message_id=1, payload_data=b'dummy', ) packet = Packet.ack(base_packet=data, ) assert packet.fragment_amount == 10 assert packet.fragment_number == 9 assert not packet.is_single assert packet.is_last
def test_encode_decode_ack(): data = Packet.data( checksum_mode=ChecksumMode.Disabled, transfer_mode=TransferMode.AckEveryPacket, fragment_amount=10, fragment_number=5, message_id=12345, payload_data=b'dummy', ) encoded = Packet.ack(base_packet=data, ) encoded_bytes = bytes(encoded) decoded = Packet.from_bytes(encoded_bytes) decoded_bytes = decoded.as_bytes assert encoded_bytes == decoded_bytes