Esempio n. 1
0
class TestAllData:

    DATA = {
        id: ['zero', 'one', 'two'],
        int: [0, 1, 2],
        bool: [
            AllData(),
            AllData(Boolean(False)),
            AllData(Boolean(False), Boolean(True))
        ],
        bytes: [
            b'\xAB\x00', b'\xAB\x03\x83\x01\x00',
            b'\xAB\x06\x83\x01\x00\x83\x01\x0F'
        ],
    }

    @fixture
    def none(self):
        return AllData()

    @mark.parametrize("data, byte_stream",
                      zip(DATA[bool], DATA[bytes]),
                      ids=DATA[id])
    def test_bytes(self, data, byte_stream):
        assert bytes(data) == byte_stream

    @mark.parametrize("data, number", zip(DATA[bool], DATA[int]), ids=DATA[id])
    def test_number_of_entries(self, data, number):
        assert data.number_of_data_set_entries == number

    @staticmethod
    def test_raw_value(none):
        assert none.raw_value is None

    @staticmethod
    def test_value(none):
        assert none.value is None

    @staticmethod
    def test_tag():
        assert AllData(Boolean(False)).tag == 'AllData'

    @staticmethod
    def test_error_type():
        assert raises(TypeError, AllData, 1)

    @staticmethod
    def test_get_item():
        true = Boolean(True)
        all_data = AllData(Boolean(False), true)
        assert all_data[1] == true
Esempio n. 2
0
def test_decode_below():
    with raises(ValueError):
        Boolean(b'')
Esempio n. 3
0
def test_decode_above():
    with raises(ValueError):
        Boolean(b'\x00\x00')
Esempio n. 4
0
def test_bytes():
    assert bytes(Boolean(False)) == b'\x83\x01\x00'
Esempio n. 5
0
def test_encode_decode():
    with raises(TypeError):
        Boolean(1)
Esempio n. 6
0
    'goose_identifier':
    'ASD',
    'goose_timestamp':
    time(),
    'status_number':
    1,
    'sequence_number':
    0,
    'test':
    True,
    'configuration_revision':
    13,
    'needs_commissioning':
    True,
    # ALL DATA
    'all_data': (Boolean(True), VisibleString('Content'), DoublePrecision(1.2),
                 SinglePrecision(3.4), Signed(-5), Unsigned(6),
                 Timestamp(705762855.123456789,
                           Quality(False, False, True, 13)))
}

publisher = Publisher(**data)

goose = bytes(publisher)
nic.send(goose)

for index, goose in enumerate(publisher):
    nic.send(bytes(goose))
    if index == 0xF:
        break
Esempio n. 7
0
def test_none_empty():
    with raises(TypeError):
        Boolean()
Esempio n. 8
0
def test_byte_false_value():
    assert Boolean(b'\x00').value is False
Esempio n. 9
0
def test_false_value():
    assert Boolean(False).value is False
Esempio n. 10
0
def test_byte_true_max_value():
    assert Boolean(b'\xFF').value is True
Esempio n. 11
0
def test_byte_false_raw_value():
    assert Boolean(b'\x00').raw_value == b'\x00'
Esempio n. 12
0
def test_byte_true_max_raw_value():
    assert Boolean(b'\xFF').raw_value == b'\xFF'
Esempio n. 13
0
def test_byte_true_min_value():
    assert Boolean(b'\x01').value is True
Esempio n. 14
0
def test_byte_true_min_raw_value():
    assert Boolean(b'\x01').raw_value == b'\x01'
Esempio n. 15
0
 def test_tag():
     assert AllData(Boolean(False)).tag == 'AllData'
Esempio n. 16
0
def test_false_raw_value(true):
    assert Boolean(False).raw_value == b'\x00'
Esempio n. 17
0
 def test_get_item():
     true = Boolean(True)
     all_data = AllData(Boolean(False), true)
     assert all_data[1] == true
Esempio n. 18
0
def true():
    return Boolean(True)
Esempio n. 19
0
 def all_data(self):
     return AllData(Boolean(True))
Esempio n. 20
0
def test_none():
    with raises(TypeError):
        Boolean(None)