Skip to content

Commit

Permalink
Add tests + fix test_model_autodetection
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Dec 13, 2021
1 parent ae58b8b commit 16a6307
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions miio/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from miio import Device
from miio import Device, MiotDevice, Vacuum
from miio.exceptions import DeviceInfoUnavailableException, PayloadDecodeException


Expand Down Expand Up @@ -59,7 +59,7 @@ def test_unavailable_device_info_raises(mocker):

def test_model_autodetection(mocker):
"""Make sure info() gets called if the model is unknown."""
info = mocker.patch("miio.Device.info")
info = mocker.patch("miio.Device._fetch_info")
_ = mocker.patch("miio.Device.send")

d = Device("127.0.0.1", "68ffffffffffffffffffffffffffffff")
Expand All @@ -83,15 +83,22 @@ def test_forced_model(mocker):
info.assert_not_called()


def test_missing_supported(mocker, caplog):
@pytest.mark.parametrize(
"cls,hidden", [(Device, True), (MiotDevice, True), (Vacuum, False)]
)
def test_missing_supported(mocker, caplog, cls, hidden):
"""Make sure warning is logged if the device is unsupported for the class."""
_ = mocker.patch("miio.Device.send")

d = Device("127.0.0.1", "68ffffffffffffffffffffffffffffff")
d = cls("127.0.0.1", "68ffffffffffffffffffffffffffffff")
d._fetch_info()

assert "Found an unsupported model" in caplog.text
assert "for class 'Device'" in caplog.text
if hidden:
assert "Found an unsupported model" not in caplog.text
assert f"for class '{cls.__name__}'" not in caplog.text
else:
assert "Found an unsupported model" in caplog.text
assert f"for class '{cls.__name__}'" in caplog.text


@pytest.mark.parametrize("cls", Device.__subclasses__())
Expand Down

0 comments on commit 16a6307

Please sign in to comment.