From 54e21f51b63a4081510f9b0dbfa68431301ceefc Mon Sep 17 00:00:00 2001 From: Aiudadadadf Date: Mon, 23 Feb 2026 18:35:20 +0100 Subject: [PATCH] tests: add tests for hexdump and hexload including ValueError on invalid hex --- tests/test_utils.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index d3b5eba..a791d13 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,7 +4,7 @@ import decorator -from mocket.utils import get_mocketize +from mocket.utils import get_mocketize, hexdump, hexload def mock_decorator(func: Callable[[], None]) -> None: @@ -29,3 +29,27 @@ def test_get_mocketize_without_kwsyntax(self, dec: NonCallableMock) -> None: dec.call_args_list[0].assert_compare_to((mock_decorator,), {"kwsyntax": True}) # Second time without kwsyntax, which succeeds dec.call_args_list[1].assert_compare_to((mock_decorator,)) + + +class HexdumpTestCase(TestCase): + def test_hexdump_converts_bytes_to_spaced_hex(self) -> None: + assert hexdump(b"Hi") == "48 69" + + def test_hexdump_empty_bytes(self) -> None: + assert hexdump(b"") == "" + + def test_hexdump_roundtrip_with_hexload(self) -> None: + data = b"bar foobar foo" + assert hexload(hexdump(data)) == data + + +class HexloadTestCase(TestCase): + def test_hexload_converts_spaced_hex_to_bytes(self) -> None: + assert hexload("48 69") == b"Hi" + + def test_hexload_empty_string(self) -> None: + assert hexload("") == b"" + + def test_hexload_invalid_hex_raises_value_error(self) -> None: + with self.assertRaises(ValueError): + hexload("ZZ ZZ")