From 7eea21f2dd480f2a26890966622f278a67a1040e Mon Sep 17 00:00:00 2001 From: Teemu R Date: Tue, 14 Jan 2020 19:16:30 +0100 Subject: [PATCH] test the newly added device fixtures (#21) * make fixture detection saner * allow scrubbed locations --- kasa/tests/conftest.py | 59 ++++++++++++++++++++++--------------- kasa/tests/newfakes.py | 8 ++--- kasa/tests/test_fixtures.py | 10 +++---- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/kasa/tests/conftest.py b/kasa/tests/conftest.py index e2e723af..44a6987f 100644 --- a/kasa/tests/conftest.py +++ b/kasa/tests/conftest.py @@ -16,8 +16,8 @@ SUPPORTED_DEVICES = glob.glob( BULBS = {"LB100", "LB120", "LB130", "KL120"} VARIABLE_TEMP = {"LB120", "LB130", "KL120"} -PLUGS = {"HS100", "HS105", "HS110", "HS200", "HS220", "HS300"} -STRIPS = {"HS300"} +PLUGS = {"HS100", "HS105", "HS110", "HS200", "HS210", "HS220", "HS300"} +STRIPS = {"HS107", "HS300"} COLOR_BULBS = {"LB130"} DIMMABLE = {*BULBS, "HS220"} EMETER = {"HS110", "HS300", *BULBS} @@ -25,14 +25,15 @@ EMETER = {"HS110", "HS300", *BULBS} ALL_DEVICES = BULBS.union(PLUGS) -def filter_model(filter): - print(filter) +def filter_model(desc, filter): filtered = list() for dev in SUPPORTED_DEVICES: for filt in filter: if filt in basename(dev): filtered.append(dev) + filtered_basenames = [basename(f) for f in filtered] + print(f"{desc}: {filtered_basenames}") return filtered @@ -42,30 +43,36 @@ def get_ioloop(): return ioloop -has_emeter = pytest.mark.parametrize("dev", filter_model(EMETER), indirect=True) +has_emeter = pytest.mark.parametrize( + "dev", filter_model("has emeter", EMETER), indirect=True +) no_emeter = pytest.mark.parametrize( - "dev", filter_model(ALL_DEVICES - EMETER), indirect=True + "dev", filter_model("no emeter", ALL_DEVICES - EMETER), indirect=True ) -bulb = pytest.mark.parametrize("dev", filter_model(BULBS), indirect=True) -plug = pytest.mark.parametrize("dev", filter_model(PLUGS), indirect=True) -strip = pytest.mark.parametrize("dev", filter_model(STRIPS), indirect=True) +bulb = pytest.mark.parametrize("dev", filter_model("bulbs", BULBS), indirect=True) +plug = pytest.mark.parametrize("dev", filter_model("plugs", PLUGS), indirect=True) +strip = pytest.mark.parametrize("dev", filter_model("strips", STRIPS), indirect=True) -dimmable = pytest.mark.parametrize("dev", filter_model(DIMMABLE), indirect=True) +dimmable = pytest.mark.parametrize( + "dev", filter_model("dimmable", DIMMABLE), indirect=True +) non_dimmable = pytest.mark.parametrize( - "dev", filter_model(ALL_DEVICES - DIMMABLE), indirect=True + "dev", filter_model("non-dimmable", ALL_DEVICES - DIMMABLE), indirect=True ) variable_temp = pytest.mark.parametrize( - "dev", filter_model(VARIABLE_TEMP), indirect=True + "dev", filter_model("variable color temp", VARIABLE_TEMP), indirect=True ) non_variable_temp = pytest.mark.parametrize( - "dev", filter_model(BULBS - VARIABLE_TEMP), indirect=True + "dev", filter_model("non-variable color temp", BULBS - VARIABLE_TEMP), indirect=True ) -color_bulb = pytest.mark.parametrize("dev", filter_model(COLOR_BULBS), indirect=True) +color_bulb = pytest.mark.parametrize( + "dev", filter_model("color bulbs", COLOR_BULBS), indirect=True +) non_color_bulb = pytest.mark.parametrize( - "dev", filter_model(BULBS - COLOR_BULBS), indirect=True + "dev", filter_model("non-color bulbs", BULBS - COLOR_BULBS), indirect=True ) @@ -99,6 +106,19 @@ def dev(request): return d return + def device_for_file(model): + for d in STRIPS: + if d in model: + return SmartStrip + for d in PLUGS: + if d in model: + return SmartPlug + for d in BULBS: + if d in model: + return SmartBulb + + raise Exception("Unable to find type for %s", model) + with open(file) as f: sysinfo = json.load(f) model = basename(file) @@ -107,14 +127,7 @@ def dev(request): "protocol": FakeTransportProtocol(sysinfo), "cache_ttl": 0, } - if "LB" in model or "KL" in model: - p = SmartBulb(**params, ioloop=ioloop) - elif "HS300" in model: - p = SmartStrip(**params, ioloop=ioloop) - elif "HS" in model: - p = SmartPlug(**params, ioloop=ioloop) - else: - raise Exception("No tests for %s" % model) + p = device_for_file(model)(**params, ioloop=ioloop) ioloop.run_until_complete(p.update()) yield p diff --git a/kasa/tests/newfakes.py b/kasa/tests/newfakes.py index 0636b1ec..f9c58f88 100644 --- a/kasa/tests/newfakes.py +++ b/kasa/tests/newfakes.py @@ -73,10 +73,10 @@ PLUG_SCHEMA = Schema( "hw_ver": str, "icon_hash": str, "led_off": check_int_bool, - "latitude": Any(All(float, Range(min=-90, max=90)), None), - "latitude_i": Any(All(float, Range(min=-90, max=90)), None), - "longitude": Any(All(float, Range(min=-180, max=180)), None), - "longitude_i": Any(All(float, Range(min=-180, max=180)), None), + "latitude": Any(All(float, Range(min=-90, max=90)), 0, None), + "latitude_i": Any(All(float, Range(min=-90, max=90)), 0, None), + "longitude": Any(All(float, Range(min=-180, max=180)), 0, None), + "longitude_i": Any(All(float, Range(min=-180, max=180)), 0, None), "mac": check_mac, "model": str, "oemId": str, diff --git a/kasa/tests/test_fixtures.py b/kasa/tests/test_fixtures.py index f2b170c5..6a2ce500 100644 --- a/kasa/tests/test_fixtures.py +++ b/kasa/tests/test_fixtures.py @@ -116,7 +116,7 @@ async def test_no_emeter(dev): @has_emeter async def test_get_emeter_realtime(dev): if dev.is_strip: - pytest.skip("Disabled for HS300 temporarily") + pytest.skip("Disabled for strips temporarily") assert dev.has_emeter @@ -128,7 +128,7 @@ async def test_get_emeter_realtime(dev): @has_emeter async def test_get_emeter_daily(dev): if dev.is_strip: - pytest.skip("Disabled for HS300 temporarily") + pytest.skip("Disabled for strips temporarily") assert dev.has_emeter @@ -151,7 +151,7 @@ async def test_get_emeter_daily(dev): @has_emeter async def test_get_emeter_monthly(dev): if dev.is_strip: - pytest.skip("Disabled for HS300 temporarily") + pytest.skip("Disabled for strips temporarily") assert dev.has_emeter @@ -174,7 +174,7 @@ async def test_get_emeter_monthly(dev): @has_emeter async def test_emeter_status(dev): if dev.is_strip: - pytest.skip("Disabled for HS300 temporarily") + pytest.skip("Disabled for strips temporarily") assert dev.has_emeter @@ -205,7 +205,7 @@ async def test_erase_emeter_stats(dev): @has_emeter async def test_current_consumption(dev): if dev.is_strip: - pytest.skip("Disabled for HS300 temporarily") + pytest.skip("Disabled for strips temporarily") if dev.has_emeter: x = await dev.current_consumption()