Skip to content

Commit c02d5b9

Browse files
committed
Add unit tests for multicast requests and config.EnumValue
1 parent 198d995 commit c02d5b9

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

tests/test_application.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,3 +1120,19 @@ async def test_unclean_shutdown(application, mocker):
11201120

11211121
# This should also not throw
11221122
await app.shutdown()
1123+
1124+
1125+
@pytest_mark_asyncio_timeout(seconds=3)
1126+
async def test_mrequest(application, mocker):
1127+
app, znp_server = application
1128+
1129+
mocker.patch.object(app, "_send_request", new=CoroutineMock())
1130+
group = app.groups.add_group(0x1234, "test group")
1131+
1132+
await group.endpoint.on_off.on()
1133+
1134+
assert app._send_request.call_count == 1
1135+
assert app._send_request.mock_calls[0][2]["dst_addr"] == t.AddrModeAddress(
1136+
mode=t.AddrMode.Group, address=0x1234
1137+
)
1138+
assert app._send_request.mock_calls[0][2]["data"] == b"\x01\x01\x01"

tests/test_config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import enum
2+
3+
from zigpy_znp.config import EnumValue
4+
5+
6+
def test_EnumValue():
7+
class TestEnum(enum.Enum):
8+
foo = 123
9+
BAR = 456
10+
11+
assert EnumValue(TestEnum)("foo") == TestEnum.foo
12+
assert EnumValue(TestEnum)("BAR") == TestEnum.BAR
13+
14+
assert (
15+
EnumValue(TestEnum, transformer=lambda s: str(s).lower())("FOO") == TestEnum.foo
16+
)
17+
assert (
18+
EnumValue(TestEnum, transformer=lambda s: str(s).upper())("bar") == TestEnum.BAR
19+
)
20+
21+
assert EnumValue(TestEnum)(TestEnum.foo) == TestEnum.foo
22+
assert EnumValue(TestEnum)(TestEnum.BAR) == TestEnum.BAR

zigpy_znp/znp/nib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ def parse_nib(data: bytes) -> typing.Union[NIB, OldNIB]:
235235
else:
236236
raise ValueError(f"Unknown NIB format: {data!r}")
237237

238-
if remaining:
239-
raise ValueError(f"NIB was parsed but trailing bytes remain: {remaining!r}")
238+
assert not remaining
240239

241240
return nib

0 commit comments

Comments
 (0)