Skip to content

Commit b876453

Browse files
authored
tests: add tests for hexdump and hexload including ValueError on invalid hex (#320)
1 parent 0a03523 commit b876453

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import decorator
66

7-
from mocket.utils import get_mocketize
7+
from mocket.utils import get_mocketize, hexdump, hexload
88

99

1010
def mock_decorator(func: Callable[[], None]) -> None:
@@ -29,3 +29,27 @@ def test_get_mocketize_without_kwsyntax(self, dec: NonCallableMock) -> None:
2929
dec.call_args_list[0].assert_compare_to((mock_decorator,), {"kwsyntax": True})
3030
# Second time without kwsyntax, which succeeds
3131
dec.call_args_list[1].assert_compare_to((mock_decorator,))
32+
33+
34+
class HexdumpTestCase(TestCase):
35+
def test_hexdump_converts_bytes_to_spaced_hex(self) -> None:
36+
assert hexdump(b"Hi") == "48 69"
37+
38+
def test_hexdump_empty_bytes(self) -> None:
39+
assert hexdump(b"") == ""
40+
41+
def test_hexdump_roundtrip_with_hexload(self) -> None:
42+
data = b"bar foobar foo"
43+
assert hexload(hexdump(data)) == data
44+
45+
46+
class HexloadTestCase(TestCase):
47+
def test_hexload_converts_spaced_hex_to_bytes(self) -> None:
48+
assert hexload("48 69") == b"Hi"
49+
50+
def test_hexload_empty_string(self) -> None:
51+
assert hexload("") == b""
52+
53+
def test_hexload_invalid_hex_raises_value_error(self) -> None:
54+
with self.assertRaises(ValueError):
55+
hexload("ZZ ZZ")

0 commit comments

Comments
 (0)