Skip to content

Commit

Permalink
Improve test for device retry and timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Dec 24, 2020
1 parent 60a3468 commit 0dd2083
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions miio/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ def test_get_properties_splitting(mocker, max_properties):
if max_properties is None:
max_properties = len(properties)
assert send.call_count == math.ceil(len(properties) / max_properties)


def test_default_timeout_and_retry(mocker):
send = mocker.patch("miio.miioprotocol.MiIOProtocol.send")
d = Device("127.0.0.1", "68ffffffffffffffffffffffffffffff")
assert 5 == d._protocol._timeout
d.send(command="fake_command", parameters=[])
send.assert_called_with("fake_command", [], 3, extra_parameters=None)


def test_timeout_retry(mocker):
Expand All @@ -29,6 +36,15 @@ def test_timeout_retry(mocker):
d.send("fake_command", [])
send.assert_called_with("fake_command", [], 3, extra_parameters=None)

class CustomDevice(Device):
retry_count = 5
timeout = 1

d2 = CustomDevice("127.0.0.1", "68ffffffffffffffffffffffffffffff")
assert 1 == d2._protocol._timeout
d2.send("fake_command", [])
send.assert_called_with("fake_command", [], 5, extra_parameters=None)


def test_unavailable_device_info_raises(mocker):
send = mocker.patch("miio.Device.send", side_effect=PayloadDecodeException)
Expand Down

0 comments on commit 0dd2083

Please sign in to comment.