Skip to content

Commit

Permalink
Add remaining unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Nov 20, 2023
1 parent 718fcea commit 1367d0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,17 @@ async def test_xbee_new(conn_mck):
assert isinstance(api, xbee_api.XBee)
assert conn_mck.call_count == 1
assert conn_mck.await_count == 1


@mock.patch.object(xbee_api.XBee, "connect", return_value=mock.MagicMock())
async def test_connection_lost(conn_mck):
"""Test `connection_lost` propagataion."""
api = await xbee_api.XBee.new(mock.sentinel.application, DEVICE_CONFIG)
await api.connect()

app = api._app = mock.MagicMock()

err = RuntimeError()
api.connection_lost(err)

app.connection_lost.assert_called_once_with(err)
8 changes: 8 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,11 @@ async def test_routes_updated(app, device):
assert router2.radio_details.call_count == 0

app._api._at_command.assert_awaited_once_with("DB")


async def test_watchdog(self):
"""Test watchdog feed method."""
app._api._at_command = mock.AsyncMock(return_value="OK")
await app._watchdog_feed()

assert app._api._at_command.mock_calls == [mock.call("VR")]
2 changes: 0 additions & 2 deletions zigpy_xbee/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ def connection_lost(self, exc: Exception) -> None:
if self._app is not None:
self._app.connection_lost(exc)

self.close()

def close(self):
"""Close the connection."""
if self._uart:
Expand Down

0 comments on commit 1367d0d

Please sign in to comment.