forked from zigpy/zigpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
129 lines (100 loc) · 2.6 KB
/
conftest.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""Common fixtures."""
import logging
from unittest.mock import patch
import pytest
import zigpy.application
from zigpy.config import CONF_DATABASE, CONF_DEVICE, CONF_DEVICE_PATH
import zigpy.state as app_state
import zigpy.types as t
import zigpy.zdo.types as zdo_t
from .async_mock import MagicMock
NCP_IEEE = t.EUI64.convert("aa:11:22:bb:33:44:be:ef")
class FailOnBadFormattingHandler(logging.Handler):
def emit(self, record):
try:
record.msg % record.args
except Exception as e:
pytest.fail(
f"Failed to format log message {record.msg!r} with {record.args!r}: {e}"
)
@pytest.fixture(autouse=True)
def raise_on_bad_log_formatting():
handler = FailOnBadFormattingHandler()
root = logging.getLogger()
root.addHandler(handler)
try:
yield
finally:
root.removeHandler(handler)
class App(zigpy.application.ControllerApplication):
async def request(
self,
device,
profile,
cluster,
src_ep,
dst_ep,
sequence,
data,
expect_reply=True,
use_ieee=False,
):
pass
async def connect(self):
pass
async def disconnect(self):
pass
async def start_network(self):
pass
async def force_remove(self, dev):
pass
async def add_endpoint(self, descriptor):
pass
async def permit_ncp(self, time_s=60):
pass
async def broadcast(
self,
profile,
cluster,
src_ep,
dst_ep,
grpid,
radius,
sequence,
data,
broadcast_address,
):
pass
async def mrequest(
self,
group_id,
profile,
cluster,
src_ep,
sequence,
data,
*,
hops=0,
non_member_radius=3,
):
pass
async def permit_with_key(self, node, code, time_s=60):
pass
async def write_network_info(self, *, network_info, node_info):
pass
async def load_network_info(self, *, load_devices=False):
pass
@pytest.fixture
def app_mock():
"""ConntrollerApplication Mock."""
config = App.SCHEMA(
{CONF_DATABASE: None, CONF_DEVICE: {CONF_DEVICE_PATH: "/dev/null"}}
)
app = App(config)
# Accessing the property fails when the mock's `spec_set` is being created
with patch.object(app, "devices"):
app_mock = MagicMock(spec_set=app)
app_mock.state.node_info = app_state.NodeInfo(
t.NWK(0x0000), ieee=NCP_IEEE, logical_type=zdo_t.LogicalType.Coordinator
)
return app_mock