Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new zigpy radio API #123

Merged
merged 18 commits into from
Jun 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Increase patch test coverage to 100%
  • Loading branch information
puddly committed Mar 14, 2022
commit b9f6029856fb7aea51a064f8e61def72b78de1c6
20 changes: 0 additions & 20 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ def api():
return api


@pytest.mark.asyncio
async def test_connect(monkeypatch):
api = xbee_api.XBee(DEVICE_CONFIG)
monkeypatch.setattr(uart, "connect", mock.AsyncMock())
@@ -53,7 +52,6 @@ def test_commands():
assert reply is None or isinstance(reply, int)


@pytest.mark.asyncio
async def test_command(api):
def mock_api_frame(name, *args):
c = xbee_api.COMMAND_REQUESTS[name]
@@ -91,7 +89,6 @@ def mock_api_frame(name, *args):
api._uart.send.reset_mock()


@pytest.mark.asyncio
async def test_command_not_connected(api):
api._uart = None

@@ -136,20 +133,17 @@ def mock_command(name, *args):
api._command.reset_mock()


@pytest.mark.asyncio
async def test_at_command(api, monkeypatch):
await _test_at_or_queued_at_command(api, api._at_command, monkeypatch)


@pytest.mark.asyncio
async def test_at_command_no_response(api, monkeypatch):
with pytest.raises(asyncio.TimeoutError):
await _test_at_or_queued_at_command(
api, api._at_command, monkeypatch, do_reply=False
)


@pytest.mark.asyncio
async def test_queued_at_command(api, monkeypatch):
await _test_at_or_queued_at_command(api, api._queued_at, monkeypatch)

@@ -192,12 +186,10 @@ def mock_command(name, *args):
api._command.reset_mock()


@pytest.mark.asyncio
async def test_remote_at_cmd(api, monkeypatch):
await _test_remote_at_command(api, monkeypatch)


@pytest.mark.asyncio
async def test_remote_at_cmd_no_rsp(api, monkeypatch):
monkeypatch.setattr(xbee_api, "REMOTE_AT_COMMAND_TIMEOUT", 0.1)
with pytest.raises(asyncio.TimeoutError):
@@ -418,7 +410,6 @@ def test_handle_tx_status_duplicate(api):
assert send_fut.set_exception.call_count == 0


@pytest.mark.asyncio
async def test_command_mode_at_cmd(api):
command = "+++"

@@ -431,7 +422,6 @@ def cmd_mode_send(cmd):
assert result


@pytest.mark.asyncio
async def test_command_mode_at_cmd_timeout(api):
command = "+++"

@@ -463,15 +453,13 @@ def test_handle_command_mode_rsp(api):
assert api._cmd_mode_future.result() == data


@pytest.mark.asyncio
async def test_enter_at_command_mode(api):
api.command_mode_at_cmd = mock.AsyncMock(return_value=mock.sentinel.at_response)

res = await api.enter_at_command_mode()
assert res == mock.sentinel.at_response


@pytest.mark.asyncio
async def test_api_mode_at_commands(api):
api.command_mode_at_cmd = mock.AsyncMock(return_value=mock.sentinel.api_mode)

@@ -488,7 +476,6 @@ async def mock_at_cmd(cmd):
assert res is None


@pytest.mark.asyncio
async def test_init_api_mode(api, monkeypatch):
monkeypatch.setattr(api._uart, "baudrate", 57600)
api.enter_at_command_mode = mock.AsyncMock(return_value=True)
@@ -533,7 +520,6 @@ def test_handle_many_to_one_rri(api):
api._handle_many_to_one_rri(ieee, nwk, 0)


@pytest.mark.asyncio
async def test_reconnect_multiple_disconnects(monkeypatch, caplog):
api = xbee_api.XBee(DEVICE_CONFIG)
connect_mock = mock.AsyncMock(return_value=True)
@@ -554,7 +540,6 @@ async def test_reconnect_multiple_disconnects(monkeypatch, caplog):
assert connect_mock.call_count == 2


@pytest.mark.asyncio
async def test_reconnect_multiple_attempts(monkeypatch, caplog):
api = xbee_api.XBee(DEVICE_CONFIG)
connect_mock = mock.AsyncMock(return_value=True)
@@ -578,7 +563,6 @@ async def test_reconnect_multiple_attempts(monkeypatch, caplog):
assert connect_mock.call_count == 3


@pytest.mark.asyncio
@mock.patch.object(xbee_api.XBee, "_at_command", new_callable=mock.AsyncMock)
@mock.patch.object(uart, "connect")
async def test_probe_success(mock_connect, mock_at_cmd):
@@ -593,7 +577,6 @@ async def test_probe_success(mock_connect, mock_at_cmd):
assert mock_connect.return_value.close.call_count == 1


@pytest.mark.asyncio
@mock.patch.object(xbee_api.XBee, "init_api_mode", return_value=True)
@mock.patch.object(xbee_api.XBee, "_at_command", side_effect=asyncio.TimeoutError)
@mock.patch.object(uart, "connect")
@@ -610,7 +593,6 @@ async def test_probe_success_api_mode(mock_connect, mock_at_cmd, mock_api_mode):
assert mock_connect.return_value.close.call_count == 1


@pytest.mark.asyncio
@mock.patch.object(xbee_api.XBee, "init_api_mode")
@mock.patch.object(xbee_api.XBee, "_at_command", side_effect=asyncio.TimeoutError)
@mock.patch.object(uart, "connect")
@@ -635,7 +617,6 @@ async def test_probe_fail(mock_connect, mock_at_cmd, mock_api_mode, exception):
assert mock_connect.return_value.close.call_count == 1


@pytest.mark.asyncio
@mock.patch.object(xbee_api.XBee, "init_api_mode", return_value=False)
@mock.patch.object(xbee_api.XBee, "_at_command", side_effect=asyncio.TimeoutError)
@mock.patch.object(uart, "connect")
@@ -655,7 +636,6 @@ async def test_probe_fail_api_mode(mock_connect, mock_at_cmd, mock_api_mode):
assert mock_connect.return_value.close.call_count == 1


@pytest.mark.asyncio
@mock.patch.object(xbee_api.XBee, "connect")
async def test_xbee_new(conn_mck):
"""Test new class method."""
Loading