Improve hass type hints for autouse fixtures in tests (#121311)

This commit is contained in:
epenet 2024-07-05 16:49:22 +02:00 committed by GitHub
parent 9383920b1a
commit 4b4b17e774
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 16 additions and 15 deletions

View file

@ -8,7 +8,7 @@ from homeassistant.setup import async_setup_component
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_media_source(hass): async def setup_media_source(hass: HomeAssistant) -> None:
"""Set up media source.""" """Set up media source."""
assert await async_setup_component(hass, "media_source", {}) assert await async_setup_component(hass, "media_source", {})

View file

@ -19,7 +19,7 @@ def mock_load_json():
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_dependencies(hass): def mock_dependencies(hass: HomeAssistant) -> None:
"""Mock dependencies loaded.""" """Mock dependencies loaded."""
mock_component(hass, "zeroconf") mock_component(hass, "zeroconf")
mock_component(hass, "device_tracker") mock_component(hass, "device_tracker")

View file

@ -67,7 +67,7 @@ async def webhook_client(
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_ws(hass): async def setup_ws(hass: HomeAssistant) -> None:
"""Configure the websocket_api component.""" """Configure the websocket_api component."""
assert await async_setup_component(hass, "repairs", {}) assert await async_setup_component(hass, "repairs", {})
assert await async_setup_component(hass, "websocket_api", {}) assert await async_setup_component(hass, "websocket_api", {})

View file

@ -18,7 +18,7 @@ from homeassistant.setup import async_setup_component
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def init_sensors_fixture(hass): def init_sensors_fixture(hass: HomeAssistant) -> None:
"""Set up things to be run when tests are started.""" """Set up things to be run when tests are started."""
hass.states.async_set( hass.states.async_set(
"test.indoortemp", "20", {ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS} "test.indoortemp", "20", {ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS}

View file

@ -109,7 +109,7 @@ async def auth(aiohttp_client: ClientSessionGenerator) -> FakeAuth:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def cleanup_media_storage(hass): def cleanup_media_storage(hass: HomeAssistant) -> Generator[None]:
"""Test cleanup, remove any media storage persisted during the test.""" """Test cleanup, remove any media storage persisted during the test."""
tmp_path = str(uuid.uuid4()) tmp_path = str(uuid.uuid4())
with patch("homeassistant.components.nest.media_source.MEDIA_PATH", new=tmp_path): with patch("homeassistant.components.nest.media_source.MEDIA_PATH", new=tmp_path):

View file

@ -28,7 +28,7 @@ from tests.typing import ClientSessionGenerator
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def auth_active(hass): def auth_active(hass: HomeAssistant) -> None:
"""Ensure auth is always active.""" """Ensure auth is always active."""
hass.loop.run_until_complete( hass.loop.run_until_complete(
register_auth_provider(hass, {"type": "homeassistant"}) register_auth_provider(hass, {"type": "homeassistant"})

View file

@ -3,10 +3,11 @@
import pytest import pytest
import homeassistant.components.persistent_notification as pn import homeassistant.components.persistent_notification as pn
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_integration(hass): async def setup_integration(hass: HomeAssistant) -> None:
"""Set up persistent notification integration.""" """Set up persistent notification integration."""
assert await async_setup_component(hass, pn.DOMAIN, {}) assert await async_setup_component(hass, pn.DOMAIN, {})

View file

@ -12,7 +12,7 @@ from tests.common import assert_setup_component, mock_component
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup_comp(hass): def setup_comp(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
mock_component(hass, "pilight") mock_component(hass, "pilight")

View file

@ -115,7 +115,7 @@ class MockFixFlowAbort(RepairsFlow):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def mock_repairs_integration(hass): async def mock_repairs_integration(hass: HomeAssistant) -> None:
"""Mock a repairs integration.""" """Mock a repairs integration."""
hass.config.components.add("fake_integration") hass.config.components.add("fake_integration")

View file

@ -35,7 +35,7 @@ from tests.common import async_fire_time_changed
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def stream_component(hass): async def stream_component(hass: HomeAssistant) -> None:
"""Set up the component before each test.""" """Set up the component before each test."""
await async_setup_component(hass, "stream", {"stream": {}}) await async_setup_component(hass, "stream", {"stream": {}})

View file

@ -83,7 +83,7 @@ def filename(tmp_path: Path) -> str:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_stream_settings(hass): def mock_stream_settings(hass: HomeAssistant) -> None:
"""Set the stream settings data in hass before each test.""" """Set the stream settings data in hass before each test."""
hass.data[DOMAIN] = { hass.data[DOMAIN] = {
ATTR_SETTINGS: StreamSettings( ATTR_SETTINGS: StreamSettings(

View file

@ -27,7 +27,7 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup_comp(hass): def setup_comp(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
mock_component(hass, "group") mock_component(hass, "group")
hass.loop.run_until_complete( hass.loop.run_until_complete(

View file

@ -45,7 +45,7 @@ async def traccar_client(
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_zones(hass): async def setup_zones(hass: HomeAssistant) -> None:
"""Set up Zone config in HA.""" """Set up Zone config in HA."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,

View file

@ -17,7 +17,7 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_http(hass): async def setup_http(hass: HomeAssistant) -> None:
"""Set up http.""" """Set up http."""
assert await async_setup_component(hass, "http", {}) assert await async_setup_component(hass, "http", {})
assert await async_setup_component(hass, "webhook", {}) assert await async_setup_component(hass, "webhook", {})

View file

@ -17,7 +17,7 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup_comp(hass): def setup_comp(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
mock_component(hass, "group") mock_component(hass, "group")
hass.loop.run_until_complete( hass.loop.run_until_complete(