Skip to content

Commit

Permalink
some minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Jan 23, 2024
1 parent afdaedf commit 58e44a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spacepackets/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_countdown.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 58e44a5

Please sign in to comment.