Skip to content

Commit

Permalink
Fix remaining broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Feb 2, 2024
1 parent 85bd670 commit f90ee1f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ async def test_bad_command_parsing(api, caplog):

assert 0xFF not in deconz_api.COMMAND_SCHEMAS

with caplog.at_level(logging.WARNING):
with caplog.at_level(logging.DEBUG):
api.data_received(
bytes.fromhex(
"172c002f0028002e02000000020000000000"
Expand Down
22 changes: 16 additions & 6 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async def test_disconnect_no_api(app):

async def test_disconnect_close_error(app):
app._api.write_parameter = MagicMock(
side_effect=zigpy_deconz.exception.CommandError(1, "Error")
side_effect=zigpy_deconz.exception.CommandError("Error", status=1, command=None)
)
await app.disconnect()

Expand Down Expand Up @@ -399,13 +399,17 @@ def mock_add_neighbour(nwk, ieee, mac_capability_flags):

if max_neighbors < 0:
raise zigpy_deconz.exception.CommandError(
deconz_api.Status.FAILURE, "Failure"
"Failure",
status=deconz_api.Status.FAILURE,
command=None,
)

p = patch.object(app, "_api", spec_set=zigpy_deconz.api.Deconz(None, None))

with p as api_mock:
err = zigpy_deconz.exception.CommandError(deconz_api.Status.FAILURE, "Failure")
err = zigpy_deconz.exception.CommandError(
"Failure", status=deconz_api.Status.FAILURE, command=None
)
api_mock.add_neighbour = AsyncMock(side_effect=[None, err, err, err])

with caplog.at_level(logging.DEBUG):
Expand Down Expand Up @@ -483,7 +487,9 @@ async def read_param(param_id, index):

if index not in slots:
raise zigpy_deconz.exception.CommandError(
deconz_api.Status.UNSUPPORTED, "Unsupported"
"Unsupported",
status=deconz_api.Status.UNSUPPORTED,
command=None,
)
else:
return deconz_api.IndexedEndpoint(index=index, descriptor=slots[index])
Expand All @@ -504,7 +510,9 @@ async def read_param(param_id, index):
assert index in (0x00, 0x01)

raise zigpy_deconz.exception.CommandError(
deconz_api.Status.UNSUPPORTED, "Unsupported"
"Unsupported",
status=deconz_api.Status.UNSUPPORTED,
command=None,
)

app._api.read_parameter = AsyncMock(side_effect=read_param)
Expand All @@ -524,7 +532,9 @@ async def read_param(param_id, index):

if index > 0x01:
raise zigpy_deconz.exception.CommandError(
deconz_api.Status.UNSUPPORTED, "Unsupported"
"Unsupported",
status=deconz_api.Status.UNSUPPORTED,
command=None,
)

return deconz_api.IndexedEndpoint(
Expand Down
5 changes: 4 additions & 1 deletion tests/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

def test_command_error():
ex = zigpy_deconz.exception.CommandError(
mock.sentinel.status, mock.sentinel.message
mock.sentinel.message,
status=mock.sentinel.status,
command=mock.sentinel.command,
)
assert ex.status is mock.sentinel.status
assert ex.command is mock.sentinel.command
4 changes: 3 additions & 1 deletion tests/test_network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ async def write_parameter(param, *args):
and param == zigpy_deconz.api.NetworkParameter.nwk_frame_counter
):
raise zigpy_deconz.exception.CommandError(
status=zigpy_deconz.api.Status.UNSUPPORTED
"Command is unsupported",
status=zigpy_deconz.api.Status.UNSUPPORTED,
command=None,
)

params[param.name] = args
Expand Down
6 changes: 4 additions & 2 deletions tests/test_send_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import zigpy.exceptions
import zigpy.types as zigpy_t

from zigpy_deconz.api import TXStatus
from zigpy_deconz.api import Status, TXStatus
import zigpy_deconz.exception
import zigpy_deconz.types as t

Expand All @@ -23,7 +23,9 @@ async def mock_send(req_id, *args, **kwargs):
await asyncio.sleep(0)

if fail_enqueue:
raise zigpy_deconz.exception.CommandError("Error")
raise zigpy_deconz.exception.CommandError(
"Error", status=Status.FAILURE, command=None
)

if fail_deliver:
app.handle_tx_confirm(
Expand Down

0 comments on commit f90ee1f

Please sign in to comment.