<commit_before># -*- encoding: utf-8 -*-
from __future__ import print_function, unicode_literals, division

from enocean.protocol.packet import Packet, RadioPacket
from enocean.protocol.constants import PACKET, RORG


def test_packet_assembly():
    PACKET_CONTENT_1 = bytearray([
        0x55,
        0x00, 0x0A, 0x00, 0x01,
        0x80,
        0xA5, 0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0x00,
        0x18
    ])
    PACKET_CONTENT_2 = bytearray([
        0x55,
        0x00, 0x0A, 0x07, 0x01,
        0xEB,
        0xA5, 0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0x00,
        0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
        0xE4
    ])
    PACKET_CONTENT_3 = bytearray([
        0x55,
        0x00, 0x0A, 0x07, 0x01,
        0xEB,
        0xA5, 0x32, 0x20, 0x89, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0x00,
        0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
        0x43
    ])

    # manually assemble packet
    p = Packet(PACKET.RADIO)
    p.rorg = RORG.BS4
    sender_bytes = [(0xdeadbeef >> i & 0xff) for i in (24, 16, 8, 0)]
    data = [0, 0, 0, 0]
    p.data = [p.rorg] + data + sender_bytes + [0]

    # test content
    packet_serialized = p.build()
    assert len(packet_serialized) == len(PACKET_CONTENT_1)
    for i in range(len(packet_serialized)):
        assert packet_serialized[i] == PACKET_CONTENT_1[i]

    # set optional data
    sub_tel_num = 3
    destination = [255, 255, 255, 255]    # broadcast
    dbm = 0xff
    security = 0
    p.optional = [sub_tel_num] + destination + [dbm] + [security]

    # test content
    packet_serialized = p.build()
    assert len(packet_serialized) == len(PACKET_CONTENT_2)
    for i in range(len(packet_serialized)):
        assert packet_serialized[i] == PACKET_CONTENT_2[i]

    # update data based on EEP
    p.select_eep(0x20, 0x01)
    prop = {
        'CV': 50,
        'TMP': 21.5,
        'ES': 'true',
    }
    p.set_eep(prop)

    # test content
    packet_serialized = p.build()
    assert len(packet_serialized) == len(PACKET_CONTENT_3)
    for i in range(len(packet_serialized)):
        assert packet_serialized[i] == PACKET_CONTENT_3[i]
    assert p.rorg_func == 0x20
    assert p.rorg_type == 0x01<commit_msg>Simplify tests.<commit_after># -*- encoding: utf-8 -*-
from __future__ import print_function, unicode_literals, division

from enocean.protocol.packet import Packet, RadioPacket
from enocean.protocol.constants import PACKET, RORG


def test_packet_assembly():
    PACKET_CONTENT_1 = bytearray([
        0x55,
        0x00, 0x0A, 0x00, 0x01,
        0x80,
        0xA5, 0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0x00,
        0x18
    ])
    PACKET_CONTENT_2 = bytearray([
        0x55,
        0x00, 0x0A, 0x07, 0x01,
        0xEB,
        0xA5, 0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0x00,
        0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
        0xE4
    ])
    PACKET_CONTENT_3 = bytearray([
        0x55,
        0x00, 0x0A, 0x07, 0x01,
        0xEB,
        0xA5, 0x32, 0x20, 0x89, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0x00,
        0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
        0x43
    ])

    # manually assemble packet
    p = Packet(PACKET.RADIO)
    p.rorg = RORG.BS4
    sender_bytes = [(0xdeadbeef >> i & 0xff) for i in (24, 16, 8, 0)]
    data = [0, 0, 0, 0]
    p.data = [p.rorg] + data + sender_bytes + [0]

    # test content
    packet_serialized = p.build()
    assert len(packet_serialized) == len(PACKET_CONTENT_1)
    assert list(packet_serialized) == list(PACKET_CONTENT_1)

    # set optional data
    sub_tel_num = 3
    destination = [255, 255, 255, 255]    # broadcast
    dbm = 0xff
    security = 0
    p.optional = [sub_tel_num] + destination + [dbm] + [security]

    # test content
    packet_serialized = p.build()
    assert len(packet_serialized) == len(PACKET_CONTENT_2)
    assert list(packet_serialized) == list(PACKET_CONTENT_2)

    # update data based on EEP
    p.select_eep(0x20, 0x01)
    prop = {
        'CV': 50,
        'TMP': 21.5,
        'ES': 'true',
    }
    p.set_eep(prop)

    # test content
    packet_serialized = p.build()
    assert len(packet_serialized) == len(PACKET_CONTENT_3)
    assert list(packet_serialized) == list(PACKET_CONTENT_3)
    assert p.rorg_func == 0x20
    assert p.rorg_type == 0x01
{'fraction_non_alphanumeric': 0.1168770453482936, 'fraction_numerical': 0.09163160355306219, 'mean_word_length': 2.5688073394495414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1981156', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1724, 'n_words': 394}