diff --git a/spacepackets/util.py b/spacepackets/util.py index 3c3e46d..6c73db2 100644 --- a/spacepackets/util.py +++ b/spacepackets/util.py @@ -337,7 +337,7 @@ def from_int(byte_len: int, val: int) -> UnsignedByteField: return ByteFieldU32(val) elif byte_len == 8: return ByteFieldU64(val) - raise ValueError("invalid byte length") + raise ValueError(f"invalid byte length {byte_len}") @staticmethod def from_bytes(byte_len: int, stream: bytes) -> UnsignedByteField: @@ -352,7 +352,7 @@ def from_bytes(byte_len: int, stream: bytes) -> UnsignedByteField: return ByteFieldU32.from_u32_bytes(stream) elif byte_len == 8: return ByteFieldU64.from_u64_bytes(stream) - raise ValueError("invalid byte length") + raise ValueError(f"invalid byte length {byte_len}") if __name__ == "__main__": diff --git a/tests/test_countdown.py b/tests/test_countdown.py index 6f09eb6..983637c 100644 --- a/tests/test_countdown.py +++ b/tests/test_countdown.py @@ -1,7 +1,7 @@ import time from datetime import timedelta from unittest import TestCase -from spacepackets.util import Countdown +from spacepackets.countdown import Countdown class CountdownTest(TestCase): diff --git a/tests/test_util.py b/tests/test_util.py index 1f310df..0c5740f 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -85,6 +85,14 @@ def test_byte_field_u64_invalid_unpack(self): with self.assertRaises(ValueError): ByteFieldU64.from_u64_bytes(bytes([1, 2, 3, 4, 5])) + def test_byte_field_generator_invalid_unpack(self): + with self.assertRaises(ValueError): + ByteFieldGenerator.from_bytes(3, bytes([1, 2, 3, 4])) + + def test_byte_field_generator_invalid_unpack_2(self): + with self.assertRaises(ValueError): + ByteFieldGenerator.from_int(3, 25) + def test_two_byte_field_gen(self): two_byte_test = ByteFieldGenerator.from_int(byte_len=2, val=0x1842) self.assertEqual(ByteFieldU16(0x1842), two_byte_test)