예제 #1
0
def test_is_duplicate_data():

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

    assert not packet.is_duplicate
예제 #2
0
def test_message_type_data():

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

    assert packet.message_type is MessageType.Data
예제 #3
0
def test_message_id_and_data_length_data():

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

    assert packet.message_id == 12345
    assert packet.message_data_length == 5
예제 #4
0
def test_transfer_mode_data_none():

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

    assert packet.transfer_mode is TransferMode.AckNone
    assert not packet.is_ack_needed
예제 #5
0
def test_transfer_mode_data_last_fragment_only_when_ack_not_needed():

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

    assert packet.transfer_mode is TransferMode.AckLastFragmentOnly
    assert not packet.is_ack_needed
예제 #6
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))
예제 #7
0
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, )
예제 #8
0
def test_fragment_data_multiple_last():

    packet = Packet.data(
        checksum_mode=ChecksumMode.Disabled,
        transfer_mode=TransferMode.AckEveryPacket,
        fragment_amount=10,
        fragment_number=9,
        message_id=1,
        payload_data=b'dummy',
    )

    assert packet.fragment_amount == 10
    assert packet.fragment_number == 9

    assert not packet.is_single
    assert packet.is_last
예제 #9
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
예제 #10
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
예제 #11
0
def test_is_duplicate_ack_true():

    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,
        is_duplicate=True,
    )

    assert packet.is_duplicate
예제 #12
0
def test_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.is_ack
    assert packet.type == 'ack'

    assert not packet.is_sync
    assert not packet.is_data
예제 #13
0
def test_fragment_ack_single():

    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.fragment_amount == 1
    assert packet.fragment_number == 0

    assert packet.is_single
    assert packet.is_last