2021-09-24 21:25:43 +00:00
|
|
|
import asyncio
|
2020-06-30 00:29:52 +00:00
|
|
|
|
2024-05-16 16:13:44 +00:00
|
|
|
import pytest
|
2020-06-30 00:29:52 +00:00
|
|
|
import xdoctest
|
2021-03-18 18:22:10 +00:00
|
|
|
|
2024-06-03 09:14:10 +00:00
|
|
|
from kasa.tests.conftest import (
|
|
|
|
get_device_for_fixture_protocol,
|
|
|
|
get_fixture_info,
|
|
|
|
patch_discovery,
|
|
|
|
)
|
2020-06-30 00:29:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_bulb_examples(mocker):
|
|
|
|
"""Use KL130 (bulb with all features) to test the doctests."""
|
2024-02-27 17:39:04 +00:00
|
|
|
p = asyncio.run(get_device_for_fixture_protocol("KL130(US)_1.0_1.8.11.json", "IOT"))
|
2024-02-04 15:20:08 +00:00
|
|
|
mocker.patch("kasa.iot.iotbulb.IotBulb", return_value=p)
|
|
|
|
mocker.patch("kasa.iot.iotbulb.IotBulb.update")
|
|
|
|
res = xdoctest.doctest_module("kasa.iot.iotbulb", "all")
|
2020-06-30 00:29:52 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_smartdevice_examples(mocker):
|
|
|
|
"""Use HS110 for emeter examples."""
|
2024-02-27 17:39:04 +00:00
|
|
|
p = asyncio.run(get_device_for_fixture_protocol("HS110(EU)_1.0_1.2.5.json", "IOT"))
|
2024-02-04 15:20:08 +00:00
|
|
|
mocker.patch("kasa.iot.iotdevice.IotDevice", return_value=p)
|
|
|
|
mocker.patch("kasa.iot.iotdevice.IotDevice.update")
|
|
|
|
res = xdoctest.doctest_module("kasa.iot.iotdevice", "all")
|
2020-06-30 00:29:52 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_plug_examples(mocker):
|
|
|
|
"""Test plug examples."""
|
2024-02-27 17:39:04 +00:00
|
|
|
p = asyncio.run(get_device_for_fixture_protocol("HS110(EU)_1.0_1.2.5.json", "IOT"))
|
|
|
|
# p = await get_device_for_fixture_protocol("HS110(EU)_1.0_1.2.5.json", "IOT")
|
2024-02-04 15:20:08 +00:00
|
|
|
mocker.patch("kasa.iot.iotplug.IotPlug", return_value=p)
|
|
|
|
mocker.patch("kasa.iot.iotplug.IotPlug.update")
|
|
|
|
res = xdoctest.doctest_module("kasa.iot.iotplug", "all")
|
2020-06-30 00:29:52 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_strip_examples(mocker):
|
|
|
|
"""Test strip examples."""
|
2024-02-27 17:39:04 +00:00
|
|
|
p = asyncio.run(get_device_for_fixture_protocol("KP303(UK)_1.0_1.0.3.json", "IOT"))
|
2024-02-04 15:20:08 +00:00
|
|
|
mocker.patch("kasa.iot.iotstrip.IotStrip", return_value=p)
|
|
|
|
mocker.patch("kasa.iot.iotstrip.IotStrip.update")
|
|
|
|
res = xdoctest.doctest_module("kasa.iot.iotstrip", "all")
|
2020-06-30 00:29:52 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_dimmer_examples(mocker):
|
|
|
|
"""Test dimmer examples."""
|
2024-02-27 17:39:04 +00:00
|
|
|
p = asyncio.run(get_device_for_fixture_protocol("HS220(US)_1.0_1.5.7.json", "IOT"))
|
2024-02-04 15:20:08 +00:00
|
|
|
mocker.patch("kasa.iot.iotdimmer.IotDimmer", return_value=p)
|
|
|
|
mocker.patch("kasa.iot.iotdimmer.IotDimmer.update")
|
|
|
|
res = xdoctest.doctest_module("kasa.iot.iotdimmer", "all")
|
2020-06-30 00:29:52 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
2020-07-19 20:32:17 +00:00
|
|
|
def test_lightstrip_examples(mocker):
|
|
|
|
"""Test lightstrip examples."""
|
2024-02-27 17:39:04 +00:00
|
|
|
p = asyncio.run(get_device_for_fixture_protocol("KL430(US)_1.0_1.0.10.json", "IOT"))
|
2024-02-04 15:20:08 +00:00
|
|
|
mocker.patch("kasa.iot.iotlightstrip.IotLightStrip", return_value=p)
|
|
|
|
mocker.patch("kasa.iot.iotlightstrip.IotLightStrip.update")
|
|
|
|
res = xdoctest.doctest_module("kasa.iot.iotlightstrip", "all")
|
2020-07-19 20:32:17 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
2024-06-03 09:14:10 +00:00
|
|
|
def test_discovery_examples(readmes_mock):
|
2020-06-30 00:29:52 +00:00
|
|
|
"""Test discovery examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.discover", "all")
|
2024-06-03 09:14:10 +00:00
|
|
|
assert res["n_passed"] > 0
|
2024-06-19 08:53:40 +00:00
|
|
|
assert res["n_warned"] == 0
|
2020-06-30 00:29:52 +00:00
|
|
|
assert not res["failed"]
|
2024-05-16 16:13:44 +00:00
|
|
|
|
|
|
|
|
2024-06-03 09:14:10 +00:00
|
|
|
def test_deviceconfig_examples(readmes_mock):
|
|
|
|
"""Test discovery examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.deviceconfig", "all")
|
|
|
|
assert res["n_passed"] > 0
|
2024-06-19 08:53:40 +00:00
|
|
|
assert res["n_warned"] == 0
|
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_device_examples(readmes_mock):
|
|
|
|
"""Test device examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.device", "all")
|
|
|
|
assert res["n_passed"] > 0
|
|
|
|
assert res["n_warned"] == 0
|
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_light_examples(readmes_mock):
|
|
|
|
"""Test device examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.interfaces.light", "all")
|
|
|
|
assert res["n_passed"] > 0
|
|
|
|
assert res["n_warned"] == 0
|
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_light_preset_examples(readmes_mock):
|
|
|
|
"""Test device examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.interfaces.lightpreset", "all")
|
|
|
|
assert res["n_passed"] > 0
|
|
|
|
assert res["n_warned"] == 0
|
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_light_effect_examples(readmes_mock):
|
|
|
|
"""Test device examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.interfaces.lighteffect", "all")
|
|
|
|
assert res["n_passed"] > 0
|
|
|
|
assert res["n_warned"] == 0
|
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_child_examples(readmes_mock):
|
|
|
|
"""Test device examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.smart.modules.childdevice", "all")
|
|
|
|
assert res["n_passed"] > 0
|
|
|
|
assert res["n_warned"] == 0
|
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_module_examples(readmes_mock):
|
|
|
|
"""Test device examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.module", "all")
|
|
|
|
assert res["n_passed"] > 0
|
|
|
|
assert res["n_warned"] == 0
|
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_feature_examples(readmes_mock):
|
|
|
|
"""Test device examples."""
|
|
|
|
res = xdoctest.doctest_module("kasa.feature", "all")
|
|
|
|
assert res["n_passed"] > 0
|
|
|
|
assert res["n_warned"] == 0
|
2024-06-03 09:14:10 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_tutorial_examples(readmes_mock):
|
2024-05-16 16:13:44 +00:00
|
|
|
"""Test discovery examples."""
|
|
|
|
res = xdoctest.doctest_module("docs/tutorial.py", "all")
|
2024-06-03 09:14:10 +00:00
|
|
|
assert res["n_passed"] > 0
|
2024-06-19 08:53:40 +00:00
|
|
|
assert res["n_warned"] == 0
|
2024-05-16 16:13:44 +00:00
|
|
|
assert not res["failed"]
|
|
|
|
|
|
|
|
|
2024-08-30 15:30:07 +00:00
|
|
|
@pytest.fixture()
|
2024-08-22 15:14:47 +00:00
|
|
|
async def readmes_mock(mocker):
|
2024-06-03 09:14:10 +00:00
|
|
|
fixture_infos = {
|
|
|
|
"127.0.0.1": get_fixture_info("KP303(UK)_1.0_1.0.3.json", "IOT"), # Strip
|
|
|
|
"127.0.0.2": get_fixture_info("HS110(EU)_1.0_1.2.5.json", "IOT"), # Plug
|
|
|
|
"127.0.0.3": get_fixture_info("L530E(EU)_3.0_1.1.6.json", "SMART"), # Bulb
|
|
|
|
"127.0.0.4": get_fixture_info("KL430(US)_1.0_1.0.10.json", "IOT"), # Lightstrip
|
|
|
|
"127.0.0.5": get_fixture_info("HS220(US)_1.0_1.5.7.json", "IOT"), # Dimmer
|
|
|
|
}
|
2024-08-30 15:30:07 +00:00
|
|
|
return patch_discovery(fixture_infos, mocker)
|