Skip to content

Commit

Permalink
Add unit tests for multicast requests and config.EnumValue
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Jul 12, 2020
1 parent 198d995 commit c02d5b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
16 changes: 16 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,3 +1120,19 @@ async def test_unclean_shutdown(application, mocker):

# This should also not throw
await app.shutdown()


@pytest_mark_asyncio_timeout(seconds=3)
async def test_mrequest(application, mocker):
app, znp_server = application

mocker.patch.object(app, "_send_request", new=CoroutineMock())
group = app.groups.add_group(0x1234, "test group")

await group.endpoint.on_off.on()

assert app._send_request.call_count == 1
assert app._send_request.mock_calls[0][2]["dst_addr"] == t.AddrModeAddress(
mode=t.AddrMode.Group, address=0x1234
)
assert app._send_request.mock_calls[0][2]["data"] == b"\x01\x01\x01"
22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import enum

from zigpy_znp.config import EnumValue


def test_EnumValue():
class TestEnum(enum.Enum):
foo = 123
BAR = 456

assert EnumValue(TestEnum)("foo") == TestEnum.foo
assert EnumValue(TestEnum)("BAR") == TestEnum.BAR

assert (
EnumValue(TestEnum, transformer=lambda s: str(s).lower())("FOO") == TestEnum.foo
)
assert (
EnumValue(TestEnum, transformer=lambda s: str(s).upper())("bar") == TestEnum.BAR
)

assert EnumValue(TestEnum)(TestEnum.foo) == TestEnum.foo
assert EnumValue(TestEnum)(TestEnum.BAR) == TestEnum.BAR
3 changes: 1 addition & 2 deletions zigpy_znp/znp/nib.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def parse_nib(data: bytes) -> typing.Union[NIB, OldNIB]:
else:
raise ValueError(f"Unknown NIB format: {data!r}")

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

return nib

0 comments on commit c02d5b9

Please sign in to comment.