forked from mindflayer/python-mocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
55 lines (39 loc) · 1.8 KB
/
test_utils.py
File metadata and controls
55 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import Callable
from unittest import TestCase
from unittest.mock import NonCallableMock, patch
import decorator
from mocket.utils import get_mocketize, hexdump, hexload
def mock_decorator(func: Callable[[], None]) -> None:
return func()
class GetMocketizeTestCase(TestCase):
@patch.object(decorator, "decorator")
def test_get_mocketize_with_kwsyntax(self, dec: NonCallableMock) -> None:
get_mocketize(mock_decorator)
dec.assert_called_once_with(mock_decorator, kwsyntax=True)
@patch.object(decorator, "decorator")
def test_get_mocketize_without_kwsyntax(self, dec: NonCallableMock) -> None:
dec.side_effect = [
TypeError("kwsyntax is not supported in this version of decorator"),
mock_decorator,
]
get_mocketize(mock_decorator)
# First time called with kwsyntax=True, which failed with TypeError
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")