libasterix 0.36.0__tar.gz → 0.36.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libasterix
3
- Version: 0.36.0
3
+ Version: 0.36.2
4
4
  Summary: Asterix data processing library
5
5
  Author-email: Zoran Bošnjak <zoran.bosnjak@via.si>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "libasterix"
3
- version = "0.36.0"
3
+ version = "0.36.2"
4
4
  authors = [
5
5
  { name="Zoran Bošnjak", email="zoran.bosnjak@via.si" },
6
6
  ]
@@ -567,7 +567,7 @@ class Spare(ItemBase):
567
567
  def _parse(cls, bs: Bits) -> Union[ValueError, Tuple['Spare', Bits]]:
568
568
  n = cls.cv_bit_size
569
569
  if len(bs) < n:
570
- return ValueError('overflow')
570
+ return ValueError('insufficient data, spare')
571
571
  a, b = bs.split_at(n)
572
572
  return (cls(a), b)
573
573
 
@@ -576,7 +576,9 @@ class Spare(ItemBase):
576
576
  return cls._parse(bs)
577
577
 
578
578
  @classmethod
579
- def create(cls, arg: int) -> 'Spare':
579
+ def create(cls, arg: Union['Spare', int]) -> 'Spare':
580
+ if isinstance(arg, Spare):
581
+ return arg
580
582
  bs = Bits.from_uinteger(arg, cls.cv_bit_offset8, cls.cv_bit_size)
581
583
  return cls(bs)
582
584
 
@@ -660,7 +662,7 @@ class Element(Variation):
660
662
  def _parse(cls, bs: Bits) -> Union[ValueError, Tuple['Element', Bits]]:
661
663
  n = cls.cv_bit_size
662
664
  if len(bs) < n:
663
- return ValueError('overflow')
665
+ return ValueError('insufficient data, element')
664
666
  a, b = bs.split_at(n)
665
667
  return (cls(a), b)
666
668
 
@@ -779,7 +781,7 @@ class Extended(Variation):
779
781
  items1.append(items2.copy())
780
782
  items2 = []
781
783
  if len(remaining) < 1:
782
- return ValueError('overflow')
784
+ return ValueError('insufficient data, extended')
783
785
  fx, remaining = remaining.head_tail()
784
786
  if not fx:
785
787
  break
@@ -904,7 +906,7 @@ class Repetitive(Variation):
904
906
  return result
905
907
  obj, remaining = result
906
908
  if len(remaining) < 1:
907
- return ValueError('overflow')
909
+ return ValueError('insufficient data, repetitive')
908
910
  fx, remaining = remaining.head_tail()
909
911
  items.append(obj)
910
912
  if not fx:
@@ -913,7 +915,7 @@ class Repetitive(Variation):
913
915
  else:
914
916
  rbs = rbs * 8
915
917
  if len(remaining) < rbs:
916
- return ValueError('overflow')
918
+ return ValueError('insufficient data, repetitive')
917
919
  (cnt, remaining) = remaining.split_at(rbs)
918
920
  for i in range(cnt.to_uinteger()):
919
921
  result = cls.cv_variation._parse(remaining)
@@ -959,12 +961,12 @@ class Explicit(Variation):
959
961
  @classmethod
960
962
  def _parse(cls, bs: Bits) -> Union[ValueError, Tuple['Explicit', Bits]]:
961
963
  if len(bs) < 8:
962
- return ValueError('overflow')
964
+ return ValueError('insufficient data, explicit size')
963
965
  cnt = bs.take(8).to_uinteger() * 8
964
966
  if cnt == 0:
965
967
  return ValueError("Unexpected size of explicit item")
966
968
  if len(bs) < cnt:
967
- return ValueError('overflow')
969
+ return ValueError('insufficient data, explicit data')
968
970
  a, b = bs.split_at(cnt)
969
971
  return (cls(a), b)
970
972
 
@@ -1015,7 +1017,7 @@ class Fspec:
1015
1017
  return ValueError('fspec too big')
1016
1018
  # 'i' contains the last byte, which must have FX=0
1017
1019
  if (i & 0x01):
1018
- return ValueError('overflow')
1020
+ return ValueError('insufficient data, fspec')
1019
1021
  (a, b) = s.split_at(n * 8)
1020
1022
  return (cls(a), b)
1021
1023
 
@@ -1299,7 +1301,7 @@ class Record:
1299
1301
  items3: List[Tuple[str, NonSpare]] = []
1300
1302
  if len(remaining) < 8:
1301
1303
  if pm == ParsingMode.StrictParsing:
1302
- return ValueError('overflow')
1304
+ return ValueError('insufficient data, rfs')
1303
1305
  else:
1304
1306
  break
1305
1307
  a, remaining = remaining.split_at(8)
@@ -1307,7 +1309,7 @@ class Record:
1307
1309
  for j in range(n):
1308
1310
  if len(remaining) < 8:
1309
1311
  if pm == ParsingMode.StrictParsing:
1310
- return ValueError('overflow')
1312
+ return ValueError('insufficient data, rfs')
1311
1313
  else:
1312
1314
  break
1313
1315
  b, remaining = remaining.split_at(8)
@@ -1575,7 +1577,7 @@ class Expansion:
1575
1577
  if a == FspecFixed:
1576
1578
  n = b * 8
1577
1579
  if len(bs) < n:
1578
- return ValueError('overflow')
1580
+ return ValueError('insufficient data, expansion')
1579
1581
  flags_bits, remaining = bs.split_at(n)
1580
1582
  flags = list(flags_bits)
1581
1583
  elif a == FspecFx:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libasterix
3
- Version: 0.36.0
3
+ Version: 0.36.2
4
4
  Summary: Asterix data processing library
5
5
  Author-email: Zoran Bošnjak <zoran.bosnjak@via.si>
6
6
  License-Expression: MIT
@@ -7,6 +7,7 @@ from typing import *
7
7
  import pytest
8
8
 
9
9
  from . generated import *
10
+ from . import sample_records
10
11
 
11
12
 
12
13
  def test_create() -> None:
@@ -1163,6 +1164,30 @@ def test_empty() -> None:
1163
1164
  rec2 = Cat_000_1_0.cv_record.create({})
1164
1165
  assert rec2.is_empty()
1165
1166
 
1167
+ def _test_roundtrip(num_records: int) -> None:
1168
+ """For each specification and edition, create a few records,
1169
+ encode, decode, expect the same result."""
1170
+
1171
+ def check(Spec: AstCat, r: Record) -> None:
1172
+ records = list([r]*num_records)
1173
+ bs = b''.join([r.unparse().to_bytes() for r in records])
1174
+ if m_name is None:
1175
+ result = Spec.cv_uap.parse(Bits.from_bytes(bs)) # type: ignore
1176
+ else:
1177
+ result = Spec.cv_uap.parse(m_name, Bits.from_bytes(bs)) # type: ignore
1178
+ assert not isinstance(result, ValueError)
1179
+ bs2 = b''.join([r.unparse().to_bytes() for r in result])
1180
+ assert bs2 == bs
1181
+
1182
+ for lst in manifest['CATS'].values(): # type: ignore
1183
+ for Spec in lst:
1184
+ for (m_name, r1, r2) in sample_records(Spec):
1185
+ check(Spec, r1)
1186
+ check(Spec, r2)
1187
+
1188
+ def test_roundtrip() -> None:
1189
+ _test_roundtrip(5)
1190
+
1166
1191
  # python specific tests
1167
1192
 
1168
1193
 
File without changes
File without changes
File without changes