Add monkeypatch type hints to webostv tests (#121054)

* Add monkeypatch type hints to webostv

* Improve
This commit is contained in:
epenet 2024-07-03 22:49:31 +02:00 committed by GitHub
parent c9240b8e34
commit 73716ea529
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 21 deletions

View File

@ -295,7 +295,9 @@ async def test_form_abort_uuid_configured(hass: HomeAssistant, client) -> None:
assert entry.data[CONF_HOST] == "new_host" 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.""" """Test that the reauthorization is successful."""
entry = await setup_webostv(hass) entry = await setup_webostv(hass)
assert client assert client
@ -331,7 +333,7 @@ async def test_reauth_successful(hass: HomeAssistant, client, monkeypatch) -> No
], ],
) )
async def test_reauth_errors( async def test_reauth_errors(
hass: HomeAssistant, client, monkeypatch, side_effect, reason hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch, side_effect, reason
) -> None: ) -> None:
"""Test reauthorization errors.""" """Test reauthorization errors."""
entry = await setup_webostv(hass) entry = await setup_webostv(hass)

View File

@ -3,6 +3,7 @@
from unittest.mock import Mock from unittest.mock import Mock
from aiowebostv import WebOsTvPairError from aiowebostv import WebOsTvPairError
import pytest
from homeassistant.components.webostv.const import DOMAIN from homeassistant.components.webostv.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
@ -12,7 +13,9 @@ from homeassistant.core import HomeAssistant
from . import setup_webostv 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.""" """Test reauth flow triggered by setup entry."""
monkeypatch.setattr(client, "is_connected", Mock(return_value=False)) monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
monkeypatch.setattr(client, "connect", Mock(side_effect=WebOsTvPairError)) monkeypatch.setattr(client, "connect", Mock(side_effect=WebOsTvPairError))
@ -32,7 +35,9 @@ async def test_reauth_setup_entry(hass: HomeAssistant, client, monkeypatch) -> N
assert flow["context"].get("entry_id") == entry.entry_id 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.""" """Test key update from setup entry."""
monkeypatch.setattr(client, "client_key", "new_key") monkeypatch.setattr(client, "client_key", "new_key")
entry = await setup_webostv(hass) entry = await setup_webostv(hass)

View File

@ -144,7 +144,7 @@ async def test_media_play_pause(hass: HomeAssistant, client) -> None:
], ],
) )
async def test_media_next_previous_track( async def test_media_next_previous_track(
hass: HomeAssistant, client, service, client_call, monkeypatch hass: HomeAssistant, client, service, client_call, monkeypatch: pytest.MonkeyPatch
) -> None: ) -> None:
"""Test media next/previous track services.""" """Test media next/previous track services."""
await setup_webostv(hass) await setup_webostv(hass)
@ -270,7 +270,10 @@ async def test_select_sound_output(hass: HomeAssistant, client) -> None:
async def test_device_info_startup_off( 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: ) -> None:
"""Test device info when device is off at startup.""" """Test device info when device is off at startup."""
monkeypatch.setattr(client, "system_info", None) monkeypatch.setattr(client, "system_info", None)
@ -291,7 +294,10 @@ async def test_device_info_startup_off(
async def test_entity_attributes( async def test_entity_attributes(
hass: HomeAssistant, client, monkeypatch, device_registry: dr.DeviceRegistry hass: HomeAssistant,
client,
monkeypatch: pytest.MonkeyPatch,
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Test entity attributes.""" """Test entity attributes."""
entry = await setup_webostv(hass) entry = await setup_webostv(hass)
@ -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( async def test_update_sources_live_tv_find(
hass: HomeAssistant, client, monkeypatch hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None: ) -> None:
"""Test finding live TV app id in update sources.""" """Test finding live TV app id in update sources."""
await setup_webostv(hass) await setup_webostv(hass)
@ -466,7 +472,9 @@ async def test_update_sources_live_tv_find(
assert len(sources) == 1 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.""" """Test error not raised when client is disconnected."""
await setup_webostv(hass) await setup_webostv(hass)
monkeypatch.setattr(client, "is_connected", Mock(return_value=False)) monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
@ -477,7 +485,10 @@ async def test_client_disconnected(hass: HomeAssistant, client, monkeypatch) ->
async def test_control_error_handling( async def test_control_error_handling(
hass: HomeAssistant, client, caplog: pytest.LogCaptureFixture, monkeypatch hass: HomeAssistant,
client,
caplog: pytest.LogCaptureFixture,
monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None:
"""Test control errors handling.""" """Test control errors handling."""
await setup_webostv(hass) await setup_webostv(hass)
@ -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.""" """Test test supported features."""
monkeypatch.setattr(client, "sound_output", "lineout") monkeypatch.setattr(client, "sound_output", "lineout")
await setup_webostv(hass) await setup_webostv(hass)
@ -565,7 +578,7 @@ async def test_supported_features(hass: HomeAssistant, client, monkeypatch) -> N
async def test_cached_supported_features( async def test_cached_supported_features(
hass: HomeAssistant, client, monkeypatch hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None: ) -> None:
"""Test test supported features.""" """Test test supported features."""
monkeypatch.setattr(client, "is_on", False) monkeypatch.setattr(client, "is_on", False)
@ -672,7 +685,7 @@ async def test_cached_supported_features(
async def test_supported_features_no_cache( async def test_supported_features_no_cache(
hass: HomeAssistant, client, monkeypatch hass: HomeAssistant, client, monkeypatch: pytest.MonkeyPatch
) -> None: ) -> None:
"""Test supported features if device is off and no cache.""" """Test supported features if device is off and no cache."""
monkeypatch.setattr(client, "is_on", False) monkeypatch.setattr(client, "is_on", False)
@ -716,7 +729,7 @@ async def test_get_image_http(
client, client,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
monkeypatch, monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None:
"""Test get image via http.""" """Test get image via http."""
url = "http://something/valid_icon" url = "http://something/valid_icon"
@ -742,7 +755,7 @@ async def test_get_image_http_error(
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
monkeypatch, monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None:
"""Test get image via http error.""" """Test get image via http error."""
url = "http://something/icon_error" url = "http://something/icon_error"
@ -769,7 +782,7 @@ async def test_get_image_https(
client, client,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
monkeypatch, monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None:
"""Test get image via http.""" """Test get image via http."""
url = "https://something/valid_icon_https" url = "https://something/valid_icon_https"
@ -789,7 +802,9 @@ async def test_get_image_https(
assert content == b"https_image" 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.""" """Test reauth flow triggered by reconnect."""
entry = await setup_webostv(hass) entry = await setup_webostv(hass)
monkeypatch.setattr(client, "is_connected", Mock(return_value=False)) monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
@ -814,7 +829,9 @@ async def test_reauth_reconnect(hass: HomeAssistant, client, monkeypatch) -> Non
assert flow["context"].get("entry_id") == entry.entry_id 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.""" """Test updating media state."""
await setup_webostv(hass) await setup_webostv(hass)

View File

@ -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.""" """Test sending a message when client is not connected."""
await setup_webostv(hass) await setup_webostv(hass)
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME) assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
@ -95,7 +97,10 @@ async def test_notify_not_connected(hass: HomeAssistant, client, monkeypatch) ->
async def test_icon_not_found( async def test_icon_not_found(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, client, monkeypatch hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
client,
monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None:
"""Test notify icon not found error.""" """Test notify icon not found error."""
await setup_webostv(hass) await setup_webostv(hass)
@ -130,7 +135,7 @@ async def test_connection_errors(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
client, client,
monkeypatch, monkeypatch: pytest.MonkeyPatch,
side_effect, side_effect,
error, error,
) -> None: ) -> None: