Skip to content

Commit 66c64da

Browse files
committed
Fix unit tests
1 parent 2acf21e commit 66c64da

File tree

6 files changed

+214
-257
lines changed

6 files changed

+214
-257
lines changed

bellows/ash.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ def __init__(self, code: t.NcpResetCode) -> None:
130130
def __repr__(self) -> str:
131131
return f"<{self.__class__.__name__}(code={self.code})>"
132132

133+
def __eq__(self, other: object) -> bool | NotImplemented:
134+
if not isinstance(other, NcpFailure):
135+
return NotImplemented
136+
137+
return self.code == other.code
138+
133139

134140
class AshFrame(abc.ABC, BaseDataclassMixin):
135141
MASK: t.uint8_t

bellows/ezsp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ async def startup_reset(self) -> None:
128128
async def connect(self, *, use_thread: bool = True) -> None:
129129
assert self._gw is None
130130
self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
131-
self._protocol = v4.EZSPv4(self.handle_callback, self._gw)
132131

133132
try:
133+
self._protocol = v4.EZSPv4(self.handle_callback, self._gw)
134134
await self.startup_reset()
135135
except Exception:
136136
await self.disconnect()

tests/test_application.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import zigpy.types as zigpy_t
1313
import zigpy.zdo.types as zdo_t
1414

15+
from bellows.ash import NcpFailure
1516
import bellows.config as config
1617
from bellows.exception import ControllerError, EzspError
1718
import bellows.ezsp as ezsp
@@ -112,7 +113,7 @@ def _create_app_for_startup(
112113
ezsp_mock.start_ezsp()
113114

114115
ezsp_mock.connect = AsyncMock()
115-
ezsp_mock.close = AsyncMock(wraps=ezsp_mock.close)
116+
ezsp_mock.disconnect = AsyncMock()
116117
ezsp_mock.startup_reset = AsyncMock()
117118
ezsp_mock.can_burn_userdata_custom_eui64 = AsyncMock(return_value=True)
118119
ezsp_mock.can_rewrite_custom_eui64 = AsyncMock(return_value=True)
@@ -1122,12 +1123,6 @@ def test_is_controller_running(app):
11221123
assert ezsp_running.call_count == 1
11231124

11241125

1125-
def test_reset_frame(app):
1126-
app.connection_lost = MagicMock(spec_set=app.connection_lost)
1127-
app.ezsp_callback_handler("_reset_controller_application", (sentinel.error,))
1128-
assert app.connection_lost.mock_calls == [call(sentinel.error)]
1129-
1130-
11311126
@pytest.mark.parametrize("ezsp_version", (4, 7))
11321127
async def test_watchdog(make_app, monkeypatch, ezsp_version):
11331128
from bellows.zigbee import application
@@ -1287,9 +1282,9 @@ async def counters_mock():
12871282
async def test_shutdown(app):
12881283
ezsp = app._ezsp
12891284

1290-
await app.shutdown()
1285+
await app.disconnect()
12911286
assert app.controller_event.is_set() is False
1292-
assert ezsp.close.call_count == 1
1287+
assert len(ezsp.disconnect.mock_calls) == 1
12931288

12941289

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

17321727
assert app._ezsp is None
17331728

1734-
assert len(ezsp.close.mock_calls) == 1
1729+
assert len(ezsp.disconnect.mock_calls) == 1
17351730

17361731

17371732
async def test_repair_tclk_partner_ieee(

0 commit comments

Comments
 (0)