Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Oct 28, 2024
1 parent 2acf21e commit 66c64da
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 257 deletions.
6 changes: 6 additions & 0 deletions bellows/ash.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def __init__(self, code: t.NcpResetCode) -> None:
def __repr__(self) -> str:
return f"<{self.__class__.__name__}(code={self.code})>"

def __eq__(self, other: object) -> bool | NotImplemented:
if not isinstance(other, NcpFailure):
return NotImplemented

return self.code == other.code


class AshFrame(abc.ABC, BaseDataclassMixin):
MASK: t.uint8_t
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ async def startup_reset(self) -> None:
async def connect(self, *, use_thread: bool = True) -> None:
assert self._gw is None
self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
self._protocol = v4.EZSPv4(self.handle_callback, self._gw)

try:
self._protocol = v4.EZSPv4(self.handle_callback, self._gw)
await self.startup_reset()
except Exception:
await self.disconnect()
Expand Down
15 changes: 5 additions & 10 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import zigpy.types as zigpy_t
import zigpy.zdo.types as zdo_t

from bellows.ash import NcpFailure
import bellows.config as config
from bellows.exception import ControllerError, EzspError
import bellows.ezsp as ezsp
Expand Down Expand Up @@ -112,7 +113,7 @@ def _create_app_for_startup(
ezsp_mock.start_ezsp()

ezsp_mock.connect = AsyncMock()
ezsp_mock.close = AsyncMock(wraps=ezsp_mock.close)
ezsp_mock.disconnect = AsyncMock()
ezsp_mock.startup_reset = AsyncMock()
ezsp_mock.can_burn_userdata_custom_eui64 = AsyncMock(return_value=True)
ezsp_mock.can_rewrite_custom_eui64 = AsyncMock(return_value=True)
Expand Down Expand Up @@ -1122,12 +1123,6 @@ def test_is_controller_running(app):
assert ezsp_running.call_count == 1


def test_reset_frame(app):
app.connection_lost = MagicMock(spec_set=app.connection_lost)
app.ezsp_callback_handler("_reset_controller_application", (sentinel.error,))
assert app.connection_lost.mock_calls == [call(sentinel.error)]


@pytest.mark.parametrize("ezsp_version", (4, 7))
async def test_watchdog(make_app, monkeypatch, ezsp_version):
from bellows.zigbee import application
Expand Down Expand Up @@ -1287,9 +1282,9 @@ async def counters_mock():
async def test_shutdown(app):
ezsp = app._ezsp

await app.shutdown()
await app.disconnect()
assert app.controller_event.is_set() is False
assert ezsp.close.call_count == 1
assert len(ezsp.disconnect.mock_calls) == 1


@pytest.fixture
Expand Down Expand Up @@ -1731,7 +1726,7 @@ async def test_connect_failure(app: ControllerApplication) -> None:

assert app._ezsp is None

assert len(ezsp.close.mock_calls) == 1
assert len(ezsp.disconnect.mock_calls) == 1


async def test_repair_tclk_partner_ieee(
Expand Down
Loading

0 comments on commit 66c64da

Please sign in to comment.