mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Improve type hints in tile tests (#123916)
This commit is contained in:
parent
1e5762fbf7
commit
78c868c075
@ -1,6 +1,8 @@
|
|||||||
"""Define test fixtures for Tile."""
|
"""Define test fixtures for Tile."""
|
||||||
|
|
||||||
|
from collections.abc import Generator
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -8,6 +10,7 @@ from pytile.tile import Tile
|
|||||||
|
|
||||||
from homeassistant.components.tile.const import DOMAIN
|
from homeassistant.components.tile.const import DOMAIN
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_fixture
|
||||||
|
|
||||||
@ -16,7 +19,7 @@ TEST_USERNAME = "user@host.com"
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="api")
|
@pytest.fixture(name="api")
|
||||||
def api_fixture(hass, data_tile_details):
|
def api_fixture(data_tile_details: dict[str, Any]) -> Mock:
|
||||||
"""Define a pytile API object."""
|
"""Define a pytile API object."""
|
||||||
tile = Tile(None, data_tile_details)
|
tile = Tile(None, data_tile_details)
|
||||||
tile.async_update = AsyncMock()
|
tile.async_update = AsyncMock()
|
||||||
@ -29,7 +32,9 @@ def api_fixture(hass, data_tile_details):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config_entry")
|
@pytest.fixture(name="config_entry")
|
||||||
def config_entry_fixture(hass, config):
|
def config_entry_fixture(
|
||||||
|
hass: HomeAssistant, config: dict[str, Any]
|
||||||
|
) -> MockConfigEntry:
|
||||||
"""Define a config entry fixture."""
|
"""Define a config entry fixture."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, unique_id=config[CONF_USERNAME], data=config)
|
entry = MockConfigEntry(domain=DOMAIN, unique_id=config[CONF_USERNAME], data=config)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -37,7 +42,7 @@ def config_entry_fixture(hass, config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config")
|
@pytest.fixture(name="config")
|
||||||
def config_fixture():
|
def config_fixture() -> dict[str, Any]:
|
||||||
"""Define a config entry data fixture."""
|
"""Define a config entry data fixture."""
|
||||||
return {
|
return {
|
||||||
CONF_USERNAME: TEST_USERNAME,
|
CONF_USERNAME: TEST_USERNAME,
|
||||||
@ -52,7 +57,7 @@ def data_tile_details_fixture():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_pytile")
|
@pytest.fixture(name="mock_pytile")
|
||||||
async def mock_pytile_fixture(api):
|
def mock_pytile_fixture(api: Mock) -> Generator[None]:
|
||||||
"""Define a fixture to patch pytile."""
|
"""Define a fixture to patch pytile."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
@ -64,7 +69,9 @@ async def mock_pytile_fixture(api):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_config_entry")
|
@pytest.fixture(name="setup_config_entry")
|
||||||
async def setup_config_entry_fixture(hass, config_entry, mock_pytile):
|
async def setup_config_entry_fixture(
|
||||||
|
hass: HomeAssistant, config_entry: MockConfigEntry, mock_pytile: None
|
||||||
|
) -> None:
|
||||||
"""Define a fixture to set up tile."""
|
"""Define a fixture to set up tile."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user