Improve type hints in kulersky tests (#121510)

pull/121516/head^2
epenet 2024-07-08 12:54:18 +02:00 committed by GitHub
parent 4d68ae1199
commit c4c623ea99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 9 deletions

View File

@ -1,5 +1,6 @@
"""Test the Kuler Sky lights."""
from collections.abc import AsyncGenerator
from unittest.mock import MagicMock, patch
import pykulersky
@ -37,13 +38,15 @@ from tests.common import MockConfigEntry, async_fire_time_changed
@pytest.fixture
async def mock_entry(hass):
async def mock_entry() -> MockConfigEntry:
"""Create a mock light entity."""
return MockConfigEntry(domain=DOMAIN)
@pytest.fixture
async def mock_light(hass, mock_entry):
async def mock_light(
hass: HomeAssistant, mock_entry: MockConfigEntry
) -> AsyncGenerator[MagicMock]:
"""Create a mock light entity."""
light = MagicMock(spec=pykulersky.Light)
@ -64,7 +67,7 @@ async def mock_light(hass, mock_entry):
yield light
async def test_init(hass: HomeAssistant, mock_light) -> None:
async def test_init(hass: HomeAssistant, mock_light: MagicMock) -> None:
"""Test platform setup."""
state = hass.states.get("light.bedroom")
assert state.state == STATE_OFF
@ -87,7 +90,9 @@ async def test_init(hass: HomeAssistant, mock_light) -> None:
assert mock_light.disconnect.called
async def test_remove_entry(hass: HomeAssistant, mock_light, mock_entry) -> None:
async def test_remove_entry(
hass: HomeAssistant, mock_light: MagicMock, mock_entry: MockConfigEntry
) -> None:
"""Test platform setup."""
assert hass.data[DOMAIN][DATA_ADDRESSES] == {"AA:BB:CC:11:22:33"}
assert DATA_DISCOVERY_SUBSCRIPTION in hass.data[DOMAIN]
@ -99,7 +104,7 @@ async def test_remove_entry(hass: HomeAssistant, mock_light, mock_entry) -> None
async def test_remove_entry_exceptions_caught(
hass: HomeAssistant, mock_light, mock_entry
hass: HomeAssistant, mock_light: MagicMock, mock_entry: MockConfigEntry
) -> None:
"""Assert that disconnect exceptions are caught."""
mock_light.disconnect.side_effect = pykulersky.PykulerskyException("Mock error")
@ -108,7 +113,7 @@ async def test_remove_entry_exceptions_caught(
assert mock_light.disconnect.called
async def test_update_exception(hass: HomeAssistant, mock_light) -> None:
async def test_update_exception(hass: HomeAssistant, mock_light: MagicMock) -> None:
"""Test platform setup."""
mock_light.get_color.side_effect = pykulersky.PykulerskyException
@ -118,7 +123,7 @@ async def test_update_exception(hass: HomeAssistant, mock_light) -> None:
assert state.state == STATE_UNAVAILABLE
async def test_light_turn_on(hass: HomeAssistant, mock_light) -> None:
async def test_light_turn_on(hass: HomeAssistant, mock_light: MagicMock) -> None:
"""Test KulerSkyLight turn_on."""
mock_light.get_color.return_value = (255, 255, 255, 255)
await hass.services.async_call(
@ -175,7 +180,7 @@ async def test_light_turn_on(hass: HomeAssistant, mock_light) -> None:
mock_light.set_color.assert_called_with(50, 41, 0, 50)
async def test_light_turn_off(hass: HomeAssistant, mock_light) -> None:
async def test_light_turn_off(hass: HomeAssistant, mock_light: MagicMock) -> None:
"""Test KulerSkyLight turn_on."""
mock_light.get_color.return_value = (0, 0, 0, 0)
await hass.services.async_call(
@ -188,7 +193,7 @@ async def test_light_turn_off(hass: HomeAssistant, mock_light) -> None:
mock_light.set_color.assert_called_with(0, 0, 0, 0)
async def test_light_update(hass: HomeAssistant, mock_light) -> None:
async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
"""Test KulerSkyLight update."""
utcnow = dt_util.utcnow()