From c2a03dced0dab1a4d62c344568b459325b806797 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 3 Oct 2026 10:33:40 +0000 Subject: [PATCH] Make tests fail when the code they test does nothing The tests for switching to the next or previous app, and for showing a widget, never checked that a request was made. They kept passing with those methods replaced by no-ops. Nothing tested a volume or brightness of zero, or turning the display off. A truthiness check slipping in where `is not None` belongs would have quietly broken muting and switching off. --- tests/test_apps.py | 28 ++++++++++++++-------------- tests/test_audio.py | 9 +++++++++ tests/test_display.py | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/tests/test_apps.py b/tests/test_apps.py index 7fb9aadb..bfc71adc 100644 --- a/tests/test_apps.py +++ b/tests/test_apps.py @@ -1,6 +1,7 @@ """Asynchronous Python client for LaMetric TIME devices.""" from aioresponses import aioresponses +from yarl import URL from demetriek import Chart, Goal, GoalData, LaMetricDevice, Simple @@ -9,25 +10,23 @@ async def test_app_next(responses: aioresponses, device: LaMetricDevice) -> None: """Test switching to the next app.""" - responses.put( - f"{DEVICE_URL}/api/v2/device/apps/next", - status=200, - body=load_fixture("apps_next.json"), - ) + url = f"{DEVICE_URL}/api/v2/device/apps/next" + responses.put(url, status=200, body=load_fixture("apps_next.json")) await device.app_next() + assert ("PUT", URL(url)) in responses.requests + async def test_app_previous(responses: aioresponses, device: LaMetricDevice) -> None: """Test switching to the previous app.""" - responses.put( - f"{DEVICE_URL}/api/v2/device/apps/prev", - status=200, - body=load_fixture("apps_prev.json"), - ) + url = f"{DEVICE_URL}/api/v2/device/apps/prev" + responses.put(url, status=200, body=load_fixture("apps_prev.json")) await device.app_previous() + assert ("PUT", URL(url)) in responses.requests + async def test_apps(responses: aioresponses, device: LaMetricDevice) -> None: """Test getting the installed apps.""" @@ -88,18 +87,19 @@ async def test_app(responses: aioresponses, device: LaMetricDevice) -> None: async def test_activate_widget(responses: aioresponses, device: LaMetricDevice) -> None: """Test showing a specific widget.""" - responses.put( + url = ( f"{DEVICE_URL}/api/v2/device/apps/com.lametric.clock" - "/widgets/1_com.lametric.clock/activate", - status=200, - body=load_fixture("app_action.json"), + "/widgets/1_com.lametric.clock/activate" ) + responses.put(url, status=200, body=load_fixture("app_action.json")) await device.activate_widget( package="com.lametric.clock", widget_id="1_com.lametric.clock", ) + assert ("PUT", URL(url)) in responses.requests + async def test_app_action(responses: aioresponses, device: LaMetricDevice) -> None: """Test running an app action with parameters.""" diff --git a/tests/test_audio.py b/tests/test_audio.py index b0e5349e..630d1b64 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -40,3 +40,12 @@ async def test_set_audio(responses: aioresponses, device: LaMetricDevice) -> Non assert audio.volume_limit assert audio.volume_limit.range_min == 0 assert audio.volume_limit.range_max == 100 + + +async def test_set_audio_mute(responses: aioresponses, device: LaMetricDevice) -> None: + """Test a volume of zero is sent, and not mistaken for no volume at all.""" + responses.put(AUDIO_URL, status=200, body=load_fixture("audio_set.json")) + + await device.audio(volume=0) + + assert request_json(responses, "PUT", AUDIO_URL) == {"volume": 0} diff --git a/tests/test_display.py b/tests/test_display.py index 4a4c5bb4..b1011f87 100644 --- a/tests/test_display.py +++ b/tests/test_display.py @@ -75,6 +75,21 @@ async def test_set_display(responses: aioresponses, device: LaMetricDevice) -> N assert display.on is True +async def test_set_display_zero_and_off( + responses: aioresponses, device: LaMetricDevice +) -> None: + """Test zero and off are sent, and not mistaken for no value at all.""" + responses.put(DISPLAY_URL, status=200, body=load_fixture("display_set.json")) + + await device.display(brightness=0, screensaver_enabled=False, on=False) + + assert request_json(responses, "PUT", DISPLAY_URL) == { + "brightness": 0, + "screensaver": {"enabled": False}, + "on": False, + } + + async def test_set_display_screensaver_mode( responses: aioresponses, device: LaMetricDevice ) -> None: