Improve type hints in arcam_fmj tests (#119072)
parent
59c8270b1a
commit
5bf42e64e3
|
@ -5,10 +5,12 @@ from unittest.mock import Mock, patch
|
|||
from arcam.fmj.client import Client
|
||||
from arcam.fmj.state import State
|
||||
import pytest
|
||||
from typing_extensions import AsyncGenerator
|
||||
|
||||
from homeassistant.components.arcam_fmj.const import DEFAULT_NAME
|
||||
from homeassistant.components.arcam_fmj.media_player import ArcamFmj
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, MockEntityPlatform
|
||||
|
@ -27,7 +29,7 @@ MOCK_CONFIG_ENTRY = {CONF_HOST: MOCK_HOST, CONF_PORT: MOCK_PORT}
|
|||
|
||||
|
||||
@pytest.fixture(name="client")
|
||||
def client_fixture():
|
||||
def client_fixture() -> Mock:
|
||||
"""Get a mocked client."""
|
||||
client = Mock(Client)
|
||||
client.host = MOCK_HOST
|
||||
|
@ -36,7 +38,7 @@ def client_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="state_1")
|
||||
def state_1_fixture(client):
|
||||
def state_1_fixture(client: Mock) -> State:
|
||||
"""Get a mocked state."""
|
||||
state = Mock(State)
|
||||
state.client = client
|
||||
|
@ -51,7 +53,7 @@ def state_1_fixture(client):
|
|||
|
||||
|
||||
@pytest.fixture(name="state_2")
|
||||
def state_2_fixture(client):
|
||||
def state_2_fixture(client: Mock) -> State:
|
||||
"""Get a mocked state."""
|
||||
state = Mock(State)
|
||||
state.client = client
|
||||
|
@ -66,13 +68,13 @@ def state_2_fixture(client):
|
|||
|
||||
|
||||
@pytest.fixture(name="state")
|
||||
def state_fixture(state_1):
|
||||
def state_fixture(state_1: State) -> State:
|
||||
"""Get a mocked state."""
|
||||
return state_1
|
||||
|
||||
|
||||
@pytest.fixture(name="player")
|
||||
def player_fixture(hass, state):
|
||||
def player_fixture(hass: HomeAssistant, state: State) -> ArcamFmj:
|
||||
"""Get standard player."""
|
||||
player = ArcamFmj(MOCK_NAME, state, MOCK_UUID)
|
||||
player.entity_id = MOCK_ENTITY_ID
|
||||
|
@ -83,7 +85,9 @@ def player_fixture(hass, state):
|
|||
|
||||
|
||||
@pytest.fixture(name="player_setup")
|
||||
async def player_setup_fixture(hass, state_1, state_2, client):
|
||||
async def player_setup_fixture(
|
||||
hass: HomeAssistant, state_1: State, state_2: State, client: Mock
|
||||
) -> AsyncGenerator[str]:
|
||||
"""Get standard player."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain="arcam_fmj", data=MOCK_CONFIG_ENTRY, title=MOCK_NAME
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
"""Tests for the Arcam FMJ config flow module."""
|
||||
|
||||
from dataclasses import replace
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from arcam.fmj.client import ConnectionFailed
|
||||
import pytest
|
||||
from typing_extensions import Generator
|
||||
|
||||
from homeassistant.components import ssdp
|
||||
from homeassistant.components.arcam_fmj.config_flow import get_entry_client
|
||||
|
@ -53,7 +54,7 @@ MOCK_DISCOVER = ssdp.SsdpServiceInfo(
|
|||
|
||||
|
||||
@pytest.fixture(name="dummy_client", autouse=True)
|
||||
def dummy_client_fixture(hass):
|
||||
def dummy_client_fixture() -> Generator[MagicMock]:
|
||||
"""Mock out the real client."""
|
||||
with patch("homeassistant.components.arcam_fmj.config_flow.Client") as client:
|
||||
client.return_value.start.side_effect = AsyncMock(return_value=None)
|
||||
|
@ -61,7 +62,7 @@ def dummy_client_fixture(hass):
|
|||
yield client.return_value
|
||||
|
||||
|
||||
async def test_ssdp(hass: HomeAssistant, dummy_client) -> None:
|
||||
async def test_ssdp(hass: HomeAssistant) -> None:
|
||||
"""Test a ssdp import flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
|
@ -93,7 +94,9 @@ async def test_ssdp_abort(hass: HomeAssistant) -> None:
|
|||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_ssdp_unable_to_connect(hass: HomeAssistant, dummy_client) -> None:
|
||||
async def test_ssdp_unable_to_connect(
|
||||
hass: HomeAssistant, dummy_client: MagicMock
|
||||
) -> None:
|
||||
"""Test a ssdp import flow."""
|
||||
dummy_client.start.side_effect = AsyncMock(side_effect=ConnectionFailed)
|
||||
|
||||
|
@ -110,7 +113,7 @@ async def test_ssdp_unable_to_connect(hass: HomeAssistant, dummy_client) -> None
|
|||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
async def test_ssdp_invalid_id(hass: HomeAssistant, dummy_client) -> None:
|
||||
async def test_ssdp_invalid_id(hass: HomeAssistant) -> None:
|
||||
"""Test a ssdp with invalid UDN."""
|
||||
discover = replace(
|
||||
MOCK_DISCOVER, upnp=MOCK_DISCOVER.upnp | {ssdp.ATTR_UPNP_UDN: "invalid"}
|
||||
|
|
Loading…
Reference in New Issue