def regular_date(self): return GooseTimestamp(1.1, Quality(raw_value=b'\x00'))
'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 print(f'{(time_ns() - now) / 1000}us')
def test_decode_accuracy_unspecified(self): assert Quality(time_accuracy=0x1F).time_accuracy == 'Unspecified'
class TestTimestamp: test_data = { id: ['min', 'extreme', 'generic'], 'attr': [(0.0, Quality(raw_value=b'\x00')), (1598487698.4095, Quality(raw_value=b'\xF8')), (1598487698.0, Quality())], bytes: [ b'\x00\x00\x00\x00\x00\x00\x00\x00', b'\x5F\x46\xFC\x92\x00\x0F\xFF\xF8', b'\x5F\x46\xFC\x92\x00\x00\x00\x20' ], } @mark.parametrize("attr, byte", zip(test_data['attr'], test_data[bytes]), ids=test_data[id]) def test_encode_attr(self, attr, byte): timestamp, quality = attr assert Timestamp(timestamp, quality).raw_value == byte @mark.parametrize("attr, byte", zip(test_data['attr'], test_data[bytes]), ids=test_data[id]) def test_decode_timestamp(self, attr, byte): assert Timestamp(byte).value == attr[0] @mark.parametrize("attr, byte", zip(test_data['attr'], test_data[bytes]), ids=test_data[id]) def test_decode_leap(self, attr, byte): assert Timestamp(byte).leap_seconds_known == attr[1].leap_seconds_known @mark.parametrize("attr, byte", zip(test_data['attr'], test_data[bytes]), ids=test_data[id]) def test_decode_fail(self, attr, byte): assert Timestamp(byte).clock_failure == attr[1].clock_failure @mark.parametrize("attr, byte", zip(test_data['attr'], test_data[bytes]), ids=test_data[id]) def test_decode_sync(self, attr, byte): assert Timestamp( byte).clock_not_synchronized == attr[1].clock_not_synchronized @mark.parametrize("attr, byte", zip(test_data['attr'], test_data[bytes]), ids=test_data[id]) def test_decode_accuracy(self, attr, byte): assert Timestamp(byte).time_accuracy == attr[1].time_accuracy # === EXCEPTIONS === def test_encode_type(self): assert raises(TypeError, Timestamp, 123) def test_encode_missing_quality(self): assert raises(TypeError, Timestamp, 123.123) def test_decode_length(self): assert raises(ValueError, Timestamp, b'')
def test_decode_accuracy(self, attr, byte): assert Quality(raw_value=byte).time_accuracy == attr[3]
def test_decode_sync(self, attr, byte): assert Quality(raw_value=byte).clock_not_synchronized == attr[2]
def test_decode_fail(self, attr, byte): assert Quality(raw_value=byte).clock_failure == attr[1]
def test_decode_leap(self, attr, byte): assert Quality(raw_value=byte).leap_seconds_known == attr[0]
def test_encode_attr(self, attr, byte): leap_second, clock_fail, clock_not_sync, accuracy = attr assert bytes(Quality(leap_second, clock_fail, clock_not_sync, accuracy)) == byte