Skip to content

Commit

Permalink
Add monkeypatch type hints to webostv tests (home-assistant#121054)
Browse files Browse the repository at this point in the history
* Add monkeypatch type hints to webostv

* Improve
  • Loading branch information
epenet authored Jul 3, 2024
1 parent c9240b8 commit 73716ea
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
6 changes: 4 additions & 2 deletions tests/components/webostv/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ async def test_form_abort_uuid_configured(hass: HomeAssistant, client) -> None:
assert entry.data[CONF_HOST] == "new_host"


async def test_reauth_successful(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_reauth_successful(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test that the reauthorization is successful."""
entry = await setup_webostv(hass)
assert client
Expand Down Expand Up @@ -331,7 +333,7 @@ async def test_reauth_successful(hass: HomeAssistant, client, monkeypatch) -> No
],
)
async def test_reauth_errors(
hass: HomeAssistant, client, monkeypatch, side_effect, reason
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch, side_effect, reason
) -> None:
"""Test reauthorization errors."""
entry = await setup_webostv(hass)
Expand Down
9 changes: 7 additions & 2 deletions tests/components/webostv/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import Mock

from aiowebostv import WebOsTvPairError
import pytest

from homeassistant.components.webostv.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
Expand All @@ -12,7 +13,9 @@
from . import setup_webostv


async def test_reauth_setup_entry(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_reauth_setup_entry(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test reauth flow triggered by setup entry."""
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
monkeypatch.setattr(client, "connect", Mock(side_effect=WebOsTvPairError))
Expand All @@ -32,7 +35,9 @@ async def test_reauth_setup_entry(hass: HomeAssistant, client, monkeypatch) -> N
assert flow["context"].get("entry_id") == entry.entry_id


async def test_key_update_setup_entry(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_key_update_setup_entry(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test key update from setup entry."""
monkeypatch.setattr(client, "client_key", "new_key")
entry = await setup_webostv(hass)
Expand Down
45 changes: 31 additions & 14 deletions tests/components/webostv/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async def test_media_play_pause(hass: HomeAssistant, client) -> None:
],
)
async def test_media_next_previous_track(
hass: HomeAssistant, client, service, client_call, monkeypatch
hass: HomeAssistant, client, service, client_call, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test media next/previous track services."""
await setup_webostv(hass)
Expand Down Expand Up @@ -270,7 +270,10 @@ async def test_select_sound_output(hass: HomeAssistant, client) -> None:


async def test_device_info_startup_off(
hass: HomeAssistant, client, monkeypatch, device_registry: dr.DeviceRegistry
hass: HomeAssistant,
client,
monkeypatch: pytest.MonkeyPatch,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test device info when device is off at startup."""
monkeypatch.setattr(client, "system_info", None)
Expand All @@ -291,7 +294,10 @@ async def test_device_info_startup_off(


async def test_entity_attributes(
hass: HomeAssistant, client, monkeypatch, device_registry: dr.DeviceRegistry
hass: HomeAssistant,
client,
monkeypatch: pytest.MonkeyPatch,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test entity attributes."""
entry = await setup_webostv(hass)
Expand Down Expand Up @@ -383,7 +389,7 @@ async def test_play_media(hass: HomeAssistant, client, media_id, ch_id) -> None:


async def test_update_sources_live_tv_find(
hass: HomeAssistant, client, monkeypatch
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test finding live TV app id in update sources."""
await setup_webostv(hass)
Expand Down Expand Up @@ -466,7 +472,9 @@ async def test_update_sources_live_tv_find(
assert len(sources) == 1


async def test_client_disconnected(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_client_disconnected(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test error not raised when client is disconnected."""
await setup_webostv(hass)
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
Expand All @@ -477,7 +485,10 @@ async def test_client_disconnected(hass: HomeAssistant, client, monkeypatch) ->


async def test_control_error_handling(
hass: HomeAssistant, client, caplog: pytest.LogCaptureFixture, monkeypatch
hass: HomeAssistant,
client,
caplog: pytest.LogCaptureFixture,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test control errors handling."""
await setup_webostv(hass)
Expand Down Expand Up @@ -507,7 +518,9 @@ async def test_control_error_handling(
)


async def test_supported_features(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_supported_features(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test test supported features."""
monkeypatch.setattr(client, "sound_output", "lineout")
await setup_webostv(hass)
Expand Down Expand Up @@ -565,7 +578,7 @@ async def test_supported_features(hass: HomeAssistant, client, monkeypatch) -> N


async def test_cached_supported_features(
hass: HomeAssistant, client, monkeypatch
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test test supported features."""
monkeypatch.setattr(client, "is_on", False)
Expand Down Expand Up @@ -672,7 +685,7 @@ async def test_cached_supported_features(


async def test_supported_features_no_cache(
hass: HomeAssistant, client, monkeypatch
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test supported features if device is off and no cache."""
monkeypatch.setattr(client, "is_on", False)
Expand Down Expand Up @@ -716,7 +729,7 @@ async def test_get_image_http(
client,
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
monkeypatch,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test get image via http."""
url = "http://something/valid_icon"
Expand All @@ -742,7 +755,7 @@ async def test_get_image_http_error(
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
caplog: pytest.LogCaptureFixture,
monkeypatch,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test get image via http error."""
url = "http://something/icon_error"
Expand All @@ -769,7 +782,7 @@ async def test_get_image_https(
client,
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
monkeypatch,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test get image via http."""
url = "https://something/valid_icon_https"
Expand All @@ -789,7 +802,9 @@ async def test_get_image_https(
assert content == b"https_image"


async def test_reauth_reconnect(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_reauth_reconnect(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test reauth flow triggered by reconnect."""
entry = await setup_webostv(hass)
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
Expand All @@ -814,7 +829,9 @@ async def test_reauth_reconnect(hass: HomeAssistant, client, monkeypatch) -> Non
assert flow["context"].get("entry_id") == entry.entry_id


async def test_update_media_state(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_update_media_state(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test updating media state."""
await setup_webostv(hass)

Expand Down
11 changes: 8 additions & 3 deletions tests/components/webostv/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ async def test_notify(hass: HomeAssistant, client) -> None:
)


async def test_notify_not_connected(hass: HomeAssistant, client, monkeypatch) -> None:
async def test_notify_not_connected(
hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test sending a message when client is not connected."""
await setup_webostv(hass)
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
Expand All @@ -95,7 +97,10 @@ async def test_notify_not_connected(hass: HomeAssistant, client, monkeypatch) ->


async def test_icon_not_found(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, client, monkeypatch
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
client,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test notify icon not found error."""
await setup_webostv(hass)
Expand Down Expand Up @@ -130,7 +135,7 @@ async def test_connection_errors(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
client,
monkeypatch,
monkeypatch: pytest.MonkeyPatch,
side_effect,
error,
) -> None:
Expand Down

0 comments on commit 73716ea

Please sign in to comment.