Improve type hints in kaleidescape tests (#119040)
This commit is contained in:
parent
c107d980fa
commit
7638380add
6 changed files with 41 additions and 73 deletions
|
@ -1,6 +1,6 @@
|
|||
"""Fixtures for Kaleidescape integration."""
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from kaleidescape import Dispatcher
|
||||
from kaleidescape.device import Automation, Movie, Power, System
|
||||
|
@ -17,7 +17,7 @@ from tests.common import MockConfigEntry
|
|||
|
||||
|
||||
@pytest.fixture(name="mock_device")
|
||||
def fixture_mock_device() -> Generator[AsyncMock]:
|
||||
def fixture_mock_device() -> Generator[MagicMock]:
|
||||
"""Return a mocked Kaleidescape device."""
|
||||
with patch(
|
||||
"homeassistant.components.kaleidescape.KaleidescapeDevice", autospec=True
|
||||
|
@ -64,6 +64,7 @@ def fixture_mock_config_entry() -> MockConfigEntry:
|
|||
@pytest.fixture(name="mock_integration")
|
||||
async def fixture_mock_integration(
|
||||
hass: HomeAssistant,
|
||||
mock_device: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> MockConfigEntry:
|
||||
"""Return a mock ConfigEntry setup for Kaleidescape integration."""
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
"""Tests for Kaleidescape config flow."""
|
||||
|
||||
import dataclasses
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.kaleidescape.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER
|
||||
|
@ -11,12 +13,9 @@ from homeassistant.data_entry_flow import FlowResultType
|
|||
|
||||
from . import MOCK_HOST, MOCK_SSDP_DISCOVERY_INFO
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_user_config_flow_success(
|
||||
hass: HomeAssistant, mock_device: AsyncMock
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device")
|
||||
async def test_user_config_flow_success(hass: HomeAssistant) -> None:
|
||||
"""Test user config flow success."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
|
@ -35,7 +34,7 @@ async def test_user_config_flow_success(
|
|||
|
||||
|
||||
async def test_user_config_flow_bad_connect_errors(
|
||||
hass: HomeAssistant, mock_device: AsyncMock
|
||||
hass: HomeAssistant, mock_device: MagicMock
|
||||
) -> None:
|
||||
"""Test errors when connection error occurs."""
|
||||
mock_device.connect.side_effect = ConnectionError
|
||||
|
@ -50,7 +49,7 @@ async def test_user_config_flow_bad_connect_errors(
|
|||
|
||||
|
||||
async def test_user_config_flow_unsupported_device_errors(
|
||||
hass: HomeAssistant, mock_device: AsyncMock
|
||||
hass: HomeAssistant, mock_device: MagicMock
|
||||
) -> None:
|
||||
"""Test errors when connecting to unsupported device."""
|
||||
mock_device.is_server_only = True
|
||||
|
@ -64,9 +63,8 @@ async def test_user_config_flow_unsupported_device_errors(
|
|||
assert result["errors"] == {"base": "unsupported"}
|
||||
|
||||
|
||||
async def test_user_config_flow_device_exists_abort(
|
||||
hass: HomeAssistant, mock_device: AsyncMock, mock_integration: MockConfigEntry
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device", "mock_integration")
|
||||
async def test_user_config_flow_device_exists_abort(hass: HomeAssistant) -> None:
|
||||
"""Test flow aborts when device already configured."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: MOCK_HOST}
|
||||
|
@ -75,9 +73,8 @@ async def test_user_config_flow_device_exists_abort(
|
|||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_ssdp_config_flow_success(
|
||||
hass: HomeAssistant, mock_device: AsyncMock
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device")
|
||||
async def test_ssdp_config_flow_success(hass: HomeAssistant) -> None:
|
||||
"""Test ssdp config flow success."""
|
||||
discovery_info = dataclasses.replace(MOCK_SSDP_DISCOVERY_INFO)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -97,7 +94,7 @@ async def test_ssdp_config_flow_success(
|
|||
|
||||
|
||||
async def test_ssdp_config_flow_bad_connect_aborts(
|
||||
hass: HomeAssistant, mock_device: AsyncMock
|
||||
hass: HomeAssistant, mock_device: MagicMock
|
||||
) -> None:
|
||||
"""Test abort when connection error occurs."""
|
||||
mock_device.connect.side_effect = ConnectionError
|
||||
|
@ -112,7 +109,7 @@ async def test_ssdp_config_flow_bad_connect_aborts(
|
|||
|
||||
|
||||
async def test_ssdp_config_flow_unsupported_device_aborts(
|
||||
hass: HomeAssistant, mock_device: AsyncMock
|
||||
hass: HomeAssistant, mock_device: MagicMock
|
||||
) -> None:
|
||||
"""Test abort when connecting to unsupported device."""
|
||||
mock_device.is_server_only = True
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Tests for Kaleidescape config entry."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.kaleidescape.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
|
@ -14,7 +16,7 @@ from tests.common import MockConfigEntry
|
|||
|
||||
async def test_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_device: AsyncMock,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test config entry loading and unloading."""
|
||||
|
@ -32,7 +34,7 @@ async def test_unload_config_entry(
|
|||
|
||||
async def test_config_entry_not_ready(
|
||||
hass: HomeAssistant,
|
||||
mock_device: AsyncMock,
|
||||
mock_device: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test config entry not ready."""
|
||||
|
@ -45,12 +47,8 @@ async def test_config_entry_not_ready(
|
|||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_device: AsyncMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device", "mock_integration")
|
||||
async def test_device(device_registry: dr.DeviceRegistry) -> None:
|
||||
"""Test device."""
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={("kaleidescape", MOCK_SERIAL)}
|
||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import MagicMock
|
|||
|
||||
from kaleidescape import const as kaleidescape_const
|
||||
from kaleidescape.device import Movie
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||
from homeassistant.const import (
|
||||
|
@ -25,17 +26,12 @@ from homeassistant.helpers import device_registry as dr
|
|||
|
||||
from . import MOCK_SERIAL
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
ENTITY_ID = f"media_player.kaleidescape_device_{MOCK_SERIAL}"
|
||||
FRIENDLY_NAME = f"Kaleidescape Device {MOCK_SERIAL}"
|
||||
|
||||
|
||||
async def test_entity(
|
||||
hass: HomeAssistant,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device", "mock_integration")
|
||||
async def test_entity(hass: HomeAssistant) -> None:
|
||||
"""Test entity attributes."""
|
||||
entity = hass.states.get(ENTITY_ID)
|
||||
assert entity is not None
|
||||
|
@ -43,11 +39,8 @@ async def test_entity(
|
|||
assert entity.attributes["friendly_name"] == FRIENDLY_NAME
|
||||
|
||||
|
||||
async def test_update_state(
|
||||
hass: HomeAssistant,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_integration")
|
||||
async def test_update_state(hass: HomeAssistant, mock_device: MagicMock) -> None:
|
||||
"""Tests dispatched signals update player."""
|
||||
entity = hass.states.get(ENTITY_ID)
|
||||
assert entity is not None
|
||||
|
@ -105,11 +98,8 @@ async def test_update_state(
|
|||
assert entity.state == STATE_PAUSED
|
||||
|
||||
|
||||
async def test_services(
|
||||
hass: HomeAssistant,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_integration")
|
||||
async def test_services(hass: HomeAssistant, mock_device: MagicMock) -> None:
|
||||
"""Test service calls."""
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN,
|
||||
|
@ -168,12 +158,8 @@ async def test_services(
|
|||
assert mock_device.previous.call_count == 1
|
||||
|
||||
|
||||
async def test_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device", "mock_integration")
|
||||
async def test_device(device_registry: dr.DeviceRegistry) -> None:
|
||||
"""Test device attributes."""
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={("kaleidescape", MOCK_SERIAL)}
|
||||
|
|
|
@ -15,25 +15,17 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
|
||||
from . import MOCK_SERIAL
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
ENTITY_ID = f"remote.kaleidescape_device_{MOCK_SERIAL}"
|
||||
|
||||
|
||||
async def test_entity(
|
||||
hass: HomeAssistant,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device", "mock_integration")
|
||||
async def test_entity(hass: HomeAssistant) -> None:
|
||||
"""Test entity attributes."""
|
||||
assert hass.states.get(ENTITY_ID)
|
||||
|
||||
|
||||
async def test_commands(
|
||||
hass: HomeAssistant,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_integration")
|
||||
async def test_commands(hass: HomeAssistant, mock_device: MagicMock) -> None:
|
||||
"""Test service calls."""
|
||||
await hass.services.async_call(
|
||||
REMOTE_DOMAIN,
|
||||
|
@ -140,11 +132,8 @@ async def test_commands(
|
|||
assert mock_device.menu_toggle.call_count == 1
|
||||
|
||||
|
||||
async def test_unknown_command(
|
||||
hass: HomeAssistant,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_device", "mock_integration")
|
||||
async def test_unknown_command(hass: HomeAssistant) -> None:
|
||||
"""Test service calls."""
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
from kaleidescape import const as kaleidescape_const
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -10,17 +11,13 @@ from homeassistant.helpers import entity_registry as er
|
|||
|
||||
from . import MOCK_SERIAL
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
ENTITY_ID = f"sensor.kaleidescape_device_{MOCK_SERIAL}"
|
||||
FRIENDLY_NAME = f"Kaleidescape Device {MOCK_SERIAL}"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_integration")
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_device: MagicMock,
|
||||
mock_integration: MockConfigEntry,
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_device: MagicMock
|
||||
) -> None:
|
||||
"""Test sensors."""
|
||||
entity = hass.states.get(f"{ENTITY_ID}_media_location")
|
||||
|
|
Loading…
Add table
Reference in a new issue