Import Generator from typing_extensions (2) (#118989)

This commit is contained in:
Marc Mueller 2024-06-06 17:24:22 +02:00 committed by GitHub
parent 49c7b1aab9
commit 279483ddb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
96 changed files with 298 additions and 290 deletions

View file

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from collections.abc import AsyncGenerator, Generator, Mapping, Sequence from collections.abc import Mapping, Sequence
from contextlib import asynccontextmanager, contextmanager from contextlib import asynccontextmanager, contextmanager
from datetime import UTC, datetime, timedelta from datetime import UTC, datetime, timedelta
from enum import Enum from enum import Enum
@ -23,6 +23,7 @@ from unittest.mock import AsyncMock, Mock, patch
from aiohttp.test_utils import unused_port as get_test_instance_port # noqa: F401 from aiohttp.test_utils import unused_port as get_test_instance_port # noqa: F401
import pytest import pytest
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion
from typing_extensions import AsyncGenerator, Generator
import voluptuous as vol import voluptuous as vol
from homeassistant import auth, bootstrap, config_entries, loader from homeassistant import auth, bootstrap, config_entries, loader
@ -161,7 +162,7 @@ def get_test_config_dir(*add_path):
@contextmanager @contextmanager
def get_test_home_assistant() -> Generator[HomeAssistant, None, None]: def get_test_home_assistant() -> Generator[HomeAssistant]:
"""Return a Home Assistant object pointing at test config directory.""" """Return a Home Assistant object pointing at test config directory."""
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
@ -222,7 +223,7 @@ async def async_test_home_assistant(
event_loop: asyncio.AbstractEventLoop | None = None, event_loop: asyncio.AbstractEventLoop | None = None,
load_registries: bool = True, load_registries: bool = True,
config_dir: str | None = None, config_dir: str | None = None,
) -> AsyncGenerator[HomeAssistant, None]: ) -> AsyncGenerator[HomeAssistant]:
"""Return a Home Assistant object pointing at test config dir.""" """Return a Home Assistant object pointing at test config dir."""
hass = HomeAssistant(config_dir or get_test_config_dir()) hass = HomeAssistant(config_dir or get_test_config_dir())
store = auth_store.AuthStore(hass) store = auth_store.AuthStore(hass)
@ -1325,9 +1326,7 @@ class MockEntity(entity.Entity):
@contextmanager @contextmanager
def mock_storage( def mock_storage(data: dict[str, Any] | None = None) -> Generator[dict[str, Any]]:
data: dict[str, Any] | None = None,
) -> Generator[dict[str, Any], None, None]:
"""Mock storage. """Mock storage.
Data is a dict {'key': {'version': version, 'data': data}} Data is a dict {'key': {'version': version, 'data': data}}

View file

@ -1,18 +1,18 @@
"""Configuration for Abode tests.""" """Configuration for Abode tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from jaraco.abode.helpers import urls as URL from jaraco.abode.helpers import urls as URL
import pytest import pytest
from requests_mock import Mocker from requests_mock import Mocker
from typing_extensions import Generator
from tests.common import load_fixture from tests.common import load_fixture
from tests.components.light.conftest import mock_light_profiles # noqa: F401 from tests.components.light.conftest import mock_light_profiles # noqa: F401
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.abode.async_setup_entry", return_value=True "homeassistant.components.abode.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Common fixtures for the AccuWeather tests.""" """Common fixtures for the AccuWeather tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.accuweather.const import DOMAIN from homeassistant.components.accuweather.const import DOMAIN
@ -11,7 +11,7 @@ from tests.common import load_json_array_fixture, load_json_object_fixture
@pytest.fixture @pytest.fixture
def mock_accuweather_client() -> Generator[AsyncMock, None, None]: def mock_accuweather_client() -> Generator[AsyncMock]:
"""Mock a AccuWeather client.""" """Mock a AccuWeather client."""
current = load_json_object_fixture("current_conditions_data.json", DOMAIN) current = load_json_object_fixture("current_conditions_data.json", DOMAIN)
forecast = load_json_array_fixture("forecast_data.json", DOMAIN) forecast = load_json_array_fixture("forecast_data.json", DOMAIN)

View file

@ -1,13 +1,13 @@
"""Test fixtures for aemet.""" """Test fixtures for aemet."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.aemet.async_setup_entry", return_value=True "homeassistant.components.aemet.async_setup_entry", return_value=True

View file

@ -1,13 +1,13 @@
"""Common fixtures for the AfterShip tests.""" """Common fixtures for the AfterShip tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.aftership.async_setup_entry", return_value=True "homeassistant.components.aftership.async_setup_entry", return_value=True

View file

@ -1,13 +1,13 @@
"""Test fixtures for Agent DVR.""" """Test fixtures for Agent DVR."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.agent_dvr.async_setup_entry", return_value=True "homeassistant.components.agent_dvr.async_setup_entry", return_value=True

View file

@ -1,10 +1,10 @@
"""AirGradient tests configuration.""" """AirGradient tests configuration."""
from collections.abc import Generator
from unittest.mock import patch from unittest.mock import patch
from airgradient import Config, Measures from airgradient import Config, Measures
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.airgradient.const import DOMAIN from homeassistant.components.airgradient.const import DOMAIN
from homeassistant.const import CONF_HOST from homeassistant.const import CONF_HOST
@ -14,7 +14,7 @@ from tests.components.smhi.common import AsyncMock
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.airgradient.async_setup_entry", "homeassistant.components.airgradient.async_setup_entry",
@ -24,7 +24,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_airgradient_client() -> Generator[AsyncMock, None, None]: def mock_airgradient_client() -> Generator[AsyncMock]:
"""Mock an AirGradient client.""" """Mock an AirGradient client."""
with ( with (
patch( patch(
@ -50,7 +50,7 @@ def mock_airgradient_client() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_new_airgradient_client( def mock_new_airgradient_client(
mock_airgradient_client: AsyncMock, mock_airgradient_client: AsyncMock,
) -> Generator[AsyncMock, None, None]: ) -> Generator[AsyncMock]:
"""Mock a new AirGradient client.""" """Mock a new AirGradient client."""
mock_airgradient_client.get_config.return_value = Config.from_json( mock_airgradient_client.get_config.return_value = Config.from_json(
load_fixture("get_config.json", DOMAIN) load_fixture("get_config.json", DOMAIN)
@ -61,7 +61,7 @@ def mock_new_airgradient_client(
@pytest.fixture @pytest.fixture
def mock_cloud_airgradient_client( def mock_cloud_airgradient_client(
mock_airgradient_client: AsyncMock, mock_airgradient_client: AsyncMock,
) -> Generator[AsyncMock, None, None]: ) -> Generator[AsyncMock]:
"""Mock a cloud AirGradient client.""" """Mock a cloud AirGradient client."""
mock_airgradient_client.get_config.return_value = Config.from_json( mock_airgradient_client.get_config.return_value = Config.from_json(
load_fixture("get_config_cloud.json", DOMAIN) load_fixture("get_config_cloud.json", DOMAIN)

View file

@ -1,13 +1,13 @@
"""Test fixtures for air-Q.""" """Test fixtures for air-Q."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.airq.async_setup_entry", return_value=True "homeassistant.components.airq.async_setup_entry", return_value=True

View file

@ -1,13 +1,13 @@
"""Common fixtures for the Airtouch 5 tests.""" """Common fixtures for the Airtouch 5 tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.airtouch5.async_setup_entry", return_value=True "homeassistant.components.airtouch5.async_setup_entry", return_value=True

View file

@ -1,10 +1,10 @@
"""Define test fixtures for AirVisual.""" """Define test fixtures for AirVisual."""
from collections.abc import Generator
import json import json
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.airvisual import ( from homeassistant.components.airvisual import (
CONF_CITY, CONF_CITY,
@ -152,7 +152,7 @@ async def setup_config_entry_fixture(hass, config_entry, mock_pyairvisual):
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.airvisual.async_setup_entry", return_value=True "homeassistant.components.airvisual.async_setup_entry", return_value=True

View file

@ -1,10 +1,10 @@
"""Define test fixtures for AirVisual Pro.""" """Define test fixtures for AirVisual Pro."""
from collections.abc import Generator
import json import json
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.airvisual_pro.const import DOMAIN from homeassistant.components.airvisual_pro.const import DOMAIN
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD
@ -14,7 +14,7 @@ from tests.common import MockConfigEntry, load_fixture
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.airvisual_pro.async_setup_entry", return_value=True "homeassistant.components.airvisual_pro.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Test fixtures for the Aladdin Connect Garage Door integration.""" """Test fixtures for the Aladdin Connect Garage Door integration."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.aladdin_connect import DOMAIN from homeassistant.components.aladdin_connect import DOMAIN
@ -11,7 +11,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.aladdin_connect.async_setup_entry", return_value=True "homeassistant.components.aladdin_connect.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Fixturs for Alarm Control Panel tests.""" """Fixturs for Alarm Control Panel tests."""
from collections.abc import Generator
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.alarm_control_panel import ( from homeassistant.components.alarm_control_panel import (
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN, DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
@ -108,7 +108,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View file

@ -1,13 +1,13 @@
"""Provide common Amber fixtures.""" """Provide common Amber fixtures."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.amberelectric.async_setup_entry", return_value=True "homeassistant.components.amberelectric.async_setup_entry", return_value=True

View file

@ -1,11 +1,11 @@
"""Common fixtures for the Ambient Weather Network integration tests.""" """Common fixtures for the Ambient Weather Network integration tests."""
from collections.abc import Generator
from typing import Any from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
from aioambient import OpenAPI from aioambient import OpenAPI
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components import ambient_network from homeassistant.components import ambient_network
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -18,7 +18,7 @@ from tests.common import (
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.ambient_network.async_setup_entry", return_value=True "homeassistant.components.ambient_network.async_setup_entry", return_value=True

View file

@ -1,11 +1,11 @@
"""Common fixtures for the Homeassistant Analytics tests.""" """Common fixtures for the Homeassistant Analytics tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from python_homeassistant_analytics import CurrentAnalytics from python_homeassistant_analytics import CurrentAnalytics
from python_homeassistant_analytics.models import CustomIntegration, Integration from python_homeassistant_analytics.models import CustomIntegration, Integration
from typing_extensions import Generator
from homeassistant.components.analytics_insights.const import ( from homeassistant.components.analytics_insights.const import (
CONF_TRACKED_CUSTOM_INTEGRATIONS, CONF_TRACKED_CUSTOM_INTEGRATIONS,
@ -17,7 +17,7 @@ from tests.common import MockConfigEntry, load_fixture, load_json_object_fixture
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.analytics_insights.async_setup_entry", "homeassistant.components.analytics_insights.async_setup_entry",
@ -27,7 +27,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_analytics_client() -> Generator[AsyncMock, None, None]: def mock_analytics_client() -> Generator[AsyncMock]:
"""Mock a Homeassistant Analytics client.""" """Mock a Homeassistant Analytics client."""
with ( with (
patch( patch(

View file

@ -1,9 +1,10 @@
"""Fixtures for the Android TV Remote integration tests.""" """Fixtures for the Android TV Remote integration tests."""
from collections.abc import Callable, Generator from collections.abc import Callable
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.androidtv_remote.const import DOMAIN from homeassistant.components.androidtv_remote.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
@ -12,7 +13,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.androidtv_remote.async_setup_entry", "homeassistant.components.androidtv_remote.async_setup_entry",
@ -22,7 +23,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_unload_entry() -> Generator[AsyncMock, None, None]: def mock_unload_entry() -> Generator[AsyncMock]:
"""Mock unloading a config entry.""" """Mock unloading a config entry."""
with patch( with patch(
"homeassistant.components.androidtv_remote.async_unload_entry", "homeassistant.components.androidtv_remote.async_unload_entry",

View file

@ -1,6 +1,5 @@
"""Common fixtures for the A. O. Smith tests.""" """Common fixtures for the A. O. Smith tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from py_aosmith import AOSmithAPIClient from py_aosmith import AOSmithAPIClient
@ -15,6 +14,7 @@ from py_aosmith.models import (
SupportedOperationModeInfo, SupportedOperationModeInfo,
) )
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.aosmith.const import DOMAIN from homeassistant.components.aosmith.const import DOMAIN
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
@ -128,7 +128,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.aosmith.async_setup_entry", return_value=True "homeassistant.components.aosmith.async_setup_entry", return_value=True
@ -166,7 +166,7 @@ async def mock_client(
get_devices_fixture_mode_pending: bool, get_devices_fixture_mode_pending: bool,
get_devices_fixture_setpoint_pending: bool, get_devices_fixture_setpoint_pending: bool,
get_devices_fixture_has_vacation_mode: bool, get_devices_fixture_has_vacation_mode: bool,
) -> Generator[MagicMock, None, None]: ) -> Generator[MagicMock]:
"""Return a mocked client.""" """Return a mocked client."""
get_devices_fixture = [ get_devices_fixture = [
build_device_fixture( build_device_fixture(

View file

@ -1,10 +1,10 @@
"""Tests for the sensor platform of the A. O. Smith integration.""" """Tests for the sensor platform of the A. O. Smith integration."""
from collections.abc import AsyncGenerator
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from typing_extensions import AsyncGenerator
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -14,7 +14,7 @@ from tests.common import MockConfigEntry, snapshot_platform
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def platforms() -> AsyncGenerator[list[str], None]: async def platforms() -> AsyncGenerator[list[str]]:
"""Return the platforms to be loaded for this test.""" """Return the platforms to be loaded for this test."""
with patch("homeassistant.components.aosmith.PLATFORMS", [Platform.SENSOR]): with patch("homeassistant.components.aosmith.PLATFORMS", [Platform.SENSOR]):
yield yield

View file

@ -1,11 +1,11 @@
"""Tests for the water heater platform of the A. O. Smith integration.""" """Tests for the water heater platform of the A. O. Smith integration."""
from collections.abc import AsyncGenerator
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from py_aosmith.models import OperationMode from py_aosmith.models import OperationMode
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from typing_extensions import AsyncGenerator
from homeassistant.components.water_heater import ( from homeassistant.components.water_heater import (
ATTR_AWAY_MODE, ATTR_AWAY_MODE,
@ -29,7 +29,7 @@ from tests.common import MockConfigEntry, snapshot_platform
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def platforms() -> AsyncGenerator[list[str], None]: async def platforms() -> AsyncGenerator[list[str]]:
"""Return the platforms to be loaded for this test.""" """Return the platforms to be loaded for this test."""
with patch("homeassistant.components.aosmith.PLATFORMS", [Platform.WATER_HEATER]): with patch("homeassistant.components.aosmith.PLATFORMS", [Platform.WATER_HEATER]):
yield yield

View file

@ -2,12 +2,13 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable, Generator from collections.abc import Callable
import logging import logging
from typing import Any from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
from homeassistant.components.application_credentials import ( from homeassistant.components.application_credentials import (
@ -114,7 +115,7 @@ class FakeConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def config_flow_handler( def config_flow_handler(
hass: HomeAssistant, current_request_with_host: None hass: HomeAssistant, current_request_with_host: None
) -> Generator[None, None, None]: ) -> Generator[None]:
"""Fixture for a test config flow.""" """Fixture for a test config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")
with mock_config_flow(TEST_DOMAIN, FakeConfigFlow): with mock_config_flow(TEST_DOMAIN, FakeConfigFlow):

View file

@ -1,11 +1,11 @@
"""Test APRS device tracker.""" """Test APRS device tracker."""
from collections.abc import Generator
from unittest.mock import MagicMock, Mock, patch from unittest.mock import MagicMock, Mock, patch
import aprslib import aprslib
from aprslib import IS from aprslib import IS
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.aprs import device_tracker from homeassistant.components.aprs import device_tracker
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -20,7 +20,7 @@ TEST_PASSWORD = "testpass"
@pytest.fixture(name="mock_ais") @pytest.fixture(name="mock_ais")
def mock_ais() -> Generator[MagicMock, None, None]: def mock_ais() -> Generator[MagicMock]:
"""Mock aprslib.""" """Mock aprslib."""
with patch("aprslib.IS") as mock_ais: with patch("aprslib.IS") as mock_ais:
yield mock_ais yield mock_ais

View file

@ -1,13 +1,13 @@
"""Common fixtures for the APsystems Local API tests.""" """Common fixtures for the APsystems Local API tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.apsystems.async_setup_entry", "homeassistant.components.apsystems.async_setup_entry",

View file

@ -1,10 +1,10 @@
"""Common fixtures for the Arve tests.""" """Common fixtures for the Arve tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from asyncarve import ArveCustomer, ArveDevices, ArveSensPro, ArveSensProData from asyncarve import ArveCustomer, ArveDevices, ArveSensPro, ArveSensProData
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.arve.const import DOMAIN from homeassistant.components.arve.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -15,7 +15,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.arve.async_setup_entry", return_value=True "homeassistant.components.arve.async_setup_entry", return_value=True

View file

@ -2,12 +2,13 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import AsyncIterable, Generator from collections.abc import AsyncIterable
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from unittest.mock import AsyncMock from unittest.mock import AsyncMock
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components import stt, tts, wake_word from homeassistant.components import stt, tts, wake_word
from homeassistant.components.assist_pipeline import DOMAIN, select as assist_select from homeassistant.components.assist_pipeline import DOMAIN, select as assist_select
@ -272,7 +273,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture @pytest.fixture
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, "test.config_flow") mock_platform(hass, "test.config_flow")

View file

@ -1,10 +1,10 @@
"""Websocket tests for Voice Assistant integration.""" """Websocket tests for Voice Assistant integration."""
from collections.abc import AsyncGenerator
from typing import Any from typing import Any
from unittest.mock import ANY, patch from unittest.mock import ANY, patch
import pytest import pytest
from typing_extensions import AsyncGenerator
from homeassistant.components import conversation from homeassistant.components import conversation
from homeassistant.components.assist_pipeline.const import DOMAIN from homeassistant.components.assist_pipeline.const import DOMAIN
@ -32,7 +32,7 @@ from tests.common import flush_store
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def delay_save_fixture() -> AsyncGenerator[None, None]: async def delay_save_fixture() -> AsyncGenerator[None]:
"""Load the homeassistant integration.""" """Load the homeassistant integration."""
with patch("homeassistant.helpers.collection.SAVE_DELAY", new=0): with patch("homeassistant.helpers.collection.SAVE_DELAY", new=0):
yield yield

View file

@ -1,9 +1,9 @@
"""Test mailbox.""" """Test mailbox."""
from collections.abc import Generator
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.asterisk_mbox import DOMAIN from homeassistant.components.asterisk_mbox import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -14,7 +14,7 @@ from .const import CONFIG
@pytest.fixture @pytest.fixture
def client() -> Generator[Mock, None, None]: def client() -> Generator[Mock]:
"""Mock client.""" """Mock client."""
with patch( with patch(
"homeassistant.components.asterisk_mbox.asteriskClient", autospec=True "homeassistant.components.asterisk_mbox.asteriskClient", autospec=True

View file

@ -1,14 +1,14 @@
"""Provide common Atag fixtures.""" """Provide common Atag fixtures."""
import asyncio import asyncio
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.atag.async_setup_entry", return_value=True "homeassistant.components.atag.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Common fixtures for the Aurora tests.""" """Common fixtures for the Aurora tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.aurora.const import CONF_THRESHOLD, DOMAIN from homeassistant.components.aurora.const import CONF_THRESHOLD, DOMAIN
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
@ -12,7 +12,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.aurora.async_setup_entry", "homeassistant.components.aurora.async_setup_entry",
@ -22,7 +22,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_aurora_client() -> Generator[AsyncMock, None, None]: def mock_aurora_client() -> Generator[AsyncMock]:
"""Mock a Homeassistant Analytics client.""" """Mock a Homeassistant Analytics client."""
with ( with (
patch( patch(

View file

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable, Generator from collections.abc import Callable
from copy import deepcopy from copy import deepcopy
from types import MappingProxyType from types import MappingProxyType
from typing import Any from typing import Any
@ -11,6 +11,7 @@ from unittest.mock import AsyncMock, patch
from axis.rtsp import Signal, State from axis.rtsp import Signal, State
import pytest import pytest
import respx import respx
from typing_extensions import Generator
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -49,7 +50,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.axis.async_setup_entry", return_value=True "homeassistant.components.axis.async_setup_entry", return_value=True
@ -280,7 +281,7 @@ async def setup_config_entry_fixture(
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_axis_rtspclient() -> Generator[Callable[[dict | None, str], None], None, None]: def mock_axis_rtspclient() -> Generator[Callable[[dict | None, str], None]]:
"""No real RTSP communication allowed.""" """No real RTSP communication allowed."""
with patch("axis.stream_manager.RTSPClient") as rtsp_client_mock: with patch("axis.stream_manager.RTSPClient") as rtsp_client_mock:
rtsp_client_mock.return_value.session.state = State.STOPPED rtsp_client_mock.return_value.session.state = State.STOPPED

View file

@ -1,12 +1,12 @@
"""Test fixtures for Azure Data Explorer.""" """Test fixtures for Azure Data Explorer."""
from collections.abc import Generator
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any from typing import Any
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.azure_data_explorer.const import ( from homeassistant.components.azure_data_explorer.const import (
CONF_FILTER, CONF_FILTER,
@ -94,7 +94,7 @@ async def mock_entry_with_one_event(
# Fixtures for config_flow tests # Fixtures for config_flow tests
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[MockConfigEntry, None, None]: def mock_setup_entry() -> Generator[MockConfigEntry]:
"""Mock the setup entry call, used for config flow tests.""" """Mock the setup entry call, used for config flow tests."""
with patch( with patch(
f"{AZURE_DATA_EXPLORER_PATH}.async_setup_entry", return_value=True f"{AZURE_DATA_EXPLORER_PATH}.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Test fixtures for Azure DevOps.""" """Test fixtures for Azure DevOps."""
from collections.abc import AsyncGenerator, Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from typing_extensions import AsyncGenerator, Generator
from homeassistant.components.azure_devops.const import DOMAIN from homeassistant.components.azure_devops.const import DOMAIN
@ -13,7 +13,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
async def mock_devops_client() -> AsyncGenerator[MagicMock, None]: async def mock_devops_client() -> AsyncGenerator[MagicMock]:
"""Mock the Azure DevOps client.""" """Mock the Azure DevOps client."""
with ( with (
@ -49,7 +49,7 @@ async def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.azure_devops.async_setup_entry", "homeassistant.components.azure_devops.async_setup_entry",

View file

@ -2,11 +2,12 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable, Generator from collections.abc import Callable
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from pybalboa.enums import HeatMode, LowHighRange from pybalboa.enums import HeatMode, LowHighRange
import pytest import pytest
from typing_extensions import Generator
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -22,7 +23,7 @@ async def integration_fixture(hass: HomeAssistant) -> MockConfigEntry:
@pytest.fixture(name="client") @pytest.fixture(name="client")
def client_fixture() -> Generator[MagicMock, None, None]: def client_fixture() -> Generator[MagicMock]:
"""Mock balboa spa client.""" """Mock balboa spa client."""
with patch( with patch(
"homeassistant.components.balboa.SpaClient", autospec=True "homeassistant.components.balboa.SpaClient", autospec=True

View file

@ -1,10 +1,10 @@
"""Test fixtures for bang_olufsen.""" """Test fixtures for bang_olufsen."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from mozart_api.models import BeolinkPeer from mozart_api.models import BeolinkPeer
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.bang_olufsen.const import DOMAIN from homeassistant.components.bang_olufsen.const import DOMAIN
@ -31,7 +31,7 @@ def mock_config_entry():
@pytest.fixture @pytest.fixture
def mock_mozart_client() -> Generator[AsyncMock, None, None]: def mock_mozart_client() -> Generator[AsyncMock]:
"""Mock MozartClient.""" """Mock MozartClient."""
with ( with (

View file

@ -1,9 +1,9 @@
"""The tests for the Binary sensor component.""" """The tests for the Binary sensor component."""
from collections.abc import Generator
from unittest import mock from unittest import mock
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components import binary_sensor from homeassistant.components import binary_sensor
from homeassistant.config_entries import ConfigEntry, ConfigFlow from homeassistant.config_entries import ConfigEntry, ConfigFlow
@ -48,7 +48,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View file

@ -1,10 +1,11 @@
"""Blueprints test helpers.""" """Blueprints test helpers."""
from collections.abc import Generator
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import Generator
def stub_blueprint_populate_fixture_helper() -> Generator[None, None, None]:
def stub_blueprint_populate_fixture_helper() -> Generator[None]:
"""Stub copying the blueprints to the config folder.""" """Stub copying the blueprints to the config folder."""
with patch( with patch(
"homeassistant.components.blueprint.models.DomainBlueprints.async_populate" "homeassistant.components.blueprint.models.DomainBlueprints.async_populate"

View file

@ -1,12 +1,12 @@
"""Tests for the bluetooth component.""" """Tests for the bluetooth component."""
from collections.abc import Generator
from unittest.mock import patch from unittest.mock import patch
from bleak_retry_connector import bleak_manager from bleak_retry_connector import bleak_manager
from dbus_fast.aio import message_bus from dbus_fast.aio import message_bus
import habluetooth.util as habluetooth_utils import habluetooth.util as habluetooth_utils
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture(name="disable_bluez_manager_socket", autouse=True, scope="package") @pytest.fixture(name="disable_bluez_manager_socket", autouse=True, scope="package")
@ -75,7 +75,7 @@ def mock_operating_system_90():
@pytest.fixture(name="macos_adapter") @pytest.fixture(name="macos_adapter")
def macos_adapter() -> Generator[None, None, None]: def macos_adapter() -> Generator[None]:
"""Fixture that mocks the macos adapter.""" """Fixture that mocks the macos adapter."""
with ( with (
patch("bleak.get_platform_scanner_backend_type"), patch("bleak.get_platform_scanner_backend_type"),
@ -110,7 +110,7 @@ def windows_adapter():
@pytest.fixture(name="no_adapters") @pytest.fixture(name="no_adapters")
def no_adapter_fixture() -> Generator[None, None, None]: def no_adapter_fixture() -> Generator[None]:
"""Fixture that mocks no adapters on Linux.""" """Fixture that mocks no adapters on Linux."""
with ( with (
patch( patch(
@ -138,7 +138,7 @@ def no_adapter_fixture() -> Generator[None, None, None]:
@pytest.fixture(name="one_adapter") @pytest.fixture(name="one_adapter")
def one_adapter_fixture() -> Generator[None, None, None]: def one_adapter_fixture() -> Generator[None]:
"""Fixture that mocks one adapter on Linux.""" """Fixture that mocks one adapter on Linux."""
with ( with (
patch( patch(
@ -177,7 +177,7 @@ def one_adapter_fixture() -> Generator[None, None, None]:
@pytest.fixture(name="two_adapters") @pytest.fixture(name="two_adapters")
def two_adapters_fixture() -> Generator[None, None, None]: def two_adapters_fixture() -> Generator[None]:
"""Fixture that mocks two adapters on Linux.""" """Fixture that mocks two adapters on Linux."""
with ( with (
patch( patch(

View file

@ -1,6 +1,5 @@
"""Tests for the Bluetooth integration manager.""" """Tests for the Bluetooth integration manager."""
from collections.abc import Generator
from datetime import timedelta from datetime import timedelta
import time import time
from typing import Any from typing import Any
@ -10,6 +9,7 @@ from bleak.backends.scanner import AdvertisementData, BLEDevice
from bluetooth_adapters import AdvertisementHistory from bluetooth_adapters import AdvertisementHistory
from habluetooth.advertisement_tracker import TRACKER_BUFFERING_WOBBLE_SECONDS from habluetooth.advertisement_tracker import TRACKER_BUFFERING_WOBBLE_SECONDS
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components import bluetooth from homeassistant.components import bluetooth
from homeassistant.components.bluetooth import ( from homeassistant.components.bluetooth import (
@ -54,7 +54,7 @@ from tests.common import async_fire_time_changed, load_fixture
@pytest.fixture @pytest.fixture
def register_hci0_scanner(hass: HomeAssistant) -> Generator[None, None, None]: def register_hci0_scanner(hass: HomeAssistant) -> Generator[None]:
"""Register an hci0 scanner.""" """Register an hci0 scanner."""
hci0_scanner = FakeScanner("hci0", "hci0") hci0_scanner = FakeScanner("hci0", "hci0")
cancel = bluetooth.async_register_scanner(hass, hci0_scanner) cancel = bluetooth.async_register_scanner(hass, hci0_scanner)
@ -63,7 +63,7 @@ def register_hci0_scanner(hass: HomeAssistant) -> Generator[None, None, None]:
@pytest.fixture @pytest.fixture
def register_hci1_scanner(hass: HomeAssistant) -> Generator[None, None, None]: def register_hci1_scanner(hass: HomeAssistant) -> Generator[None]:
"""Register an hci1 scanner.""" """Register an hci1 scanner."""
hci1_scanner = FakeScanner("hci1", "hci1") hci1_scanner = FakeScanner("hci1", "hci1")
cancel = bluetooth.async_register_scanner(hass, hci1_scanner) cancel = bluetooth.async_register_scanner(hass, hci1_scanner)

View file

@ -1,18 +1,17 @@
"""Fixtures for BMW tests.""" """Fixtures for BMW tests."""
from collections.abc import Generator
from bimmer_connected.tests import ALL_CHARGING_SETTINGS, ALL_PROFILES, ALL_STATES from bimmer_connected.tests import ALL_CHARGING_SETTINGS, ALL_PROFILES, ALL_STATES
from bimmer_connected.tests.common import MyBMWMockRouter from bimmer_connected.tests.common import MyBMWMockRouter
from bimmer_connected.vehicle import remote_services from bimmer_connected.vehicle import remote_services
import pytest import pytest
import respx import respx
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def bmw_fixture( def bmw_fixture(
request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch
) -> Generator[respx.MockRouter, None, None]: ) -> Generator[respx.MockRouter]:
"""Patch MyBMW login API calls.""" """Patch MyBMW login API calls."""
# we use the library's mock router to mock the API calls, but only with a subset of vehicles # we use the library's mock router to mock the API calls, but only with a subset of vehicles

View file

@ -1,13 +1,13 @@
"""Test fixtures for Bravia TV.""" """Test fixtures for Bravia TV."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.braviatv.async_setup_entry", return_value=True "homeassistant.components.braviatv.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Common fixtures for the Bring! tests.""" """Common fixtures for the Bring! tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.bring import DOMAIN from homeassistant.components.bring import DOMAIN
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
@ -17,7 +17,7 @@ UUID = "00000000-00000000-00000000-00000000"
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.bring.async_setup_entry", return_value=True "homeassistant.components.bring.async_setup_entry", return_value=True
@ -26,7 +26,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_bring_client() -> Generator[AsyncMock, None, None]: def mock_bring_client() -> Generator[AsyncMock]:
"""Mock a Bring client.""" """Mock a Bring client."""
with ( with (
patch( patch(

View file

@ -1,11 +1,11 @@
"""Test fixtures for brother.""" """Test fixtures for brother."""
from collections.abc import Generator
from datetime import UTC, datetime from datetime import UTC, datetime
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from brother import BrotherSensors from brother import BrotherSensors
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.brother.const import DOMAIN from homeassistant.components.brother.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_TYPE from homeassistant.const import CONF_HOST, CONF_TYPE
@ -78,7 +78,7 @@ BROTHER_DATA = BrotherSensors(
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.brother.async_setup_entry", return_value=True "homeassistant.components.brother.async_setup_entry", return_value=True
@ -87,7 +87,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_brother_client() -> Generator[AsyncMock, None, None]: def mock_brother_client() -> Generator[AsyncMock]:
"""Mock Brother client.""" """Mock Brother client."""
with ( with (
patch("homeassistant.components.brother.Brother", autospec=True) as mock_client, patch("homeassistant.components.brother.Brother", autospec=True) as mock_client,

View file

@ -1,13 +1,13 @@
"""Test fixtures for Brottplatskartan.""" """Test fixtures for Brottplatskartan."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.brottsplatskartan.async_setup_entry", "homeassistant.components.brottsplatskartan.async_setup_entry",
@ -17,7 +17,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def uuid_generator() -> Generator[AsyncMock, None, None]: def uuid_generator() -> Generator[AsyncMock]:
"""Generate uuid for app-id.""" """Generate uuid for app-id."""
with patch( with patch(
"homeassistant.components.brottsplatskartan.config_flow.uuid.getnode", "homeassistant.components.brottsplatskartan.config_flow.uuid.getnode",

View file

@ -1,13 +1,13 @@
"""Configuration for brunt tests.""" """Configuration for brunt tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.brunt.async_setup_entry", return_value=True "homeassistant.components.brunt.async_setup_entry", return_value=True

View file

@ -1,10 +1,10 @@
"""Fixtures for BSBLAN integration tests.""" """Fixtures for BSBLAN integration tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from bsblan import Device, Info, State from bsblan import Device, Info, State
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.bsblan.const import CONF_PASSKEY, DOMAIN from homeassistant.components.bsblan.const import CONF_PASSKEY, DOMAIN
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
@ -31,7 +31,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.bsblan.async_setup_entry", return_value=True "homeassistant.components.bsblan.async_setup_entry", return_value=True

View file

@ -1,13 +1,13 @@
"""Test fixtures for buienradar2.""" """Test fixtures for buienradar2."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.buienradar.async_setup_entry", return_value=True "homeassistant.components.buienradar.async_setup_entry", return_value=True

View file

@ -1,11 +1,11 @@
"""The tests for the Button component.""" """The tests for the Button component."""
from collections.abc import Generator
from datetime import timedelta from datetime import timedelta
from unittest.mock import MagicMock from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.button import ( from homeassistant.components.button import (
DOMAIN, DOMAIN,
@ -121,7 +121,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View file

@ -1,11 +1,11 @@
"""Test the CalDAV config flow.""" """Test the CalDAV config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
from caldav.lib.error import AuthorizationError, DAVError from caldav.lib.error import AuthorizationError, DAVError
import pytest import pytest
import requests import requests
from typing_extensions import Generator
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.caldav.const import DOMAIN from homeassistant.components.caldav.const import DOMAIN
@ -19,7 +19,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
f"homeassistant.components.{DOMAIN}.async_setup_entry", return_value=True f"homeassistant.components.{DOMAIN}.async_setup_entry", return_value=True

View file

@ -1,12 +1,12 @@
"""Test fixtures for calendar sensor platforms.""" """Test fixtures for calendar sensor platforms."""
from collections.abc import Generator
import datetime import datetime
import secrets import secrets
from typing import Any from typing import Any
from unittest.mock import AsyncMock from unittest.mock import AsyncMock
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.calendar import DOMAIN, CalendarEntity, CalendarEvent from homeassistant.components.calendar import DOMAIN, CalendarEntity, CalendarEvent
from homeassistant.config_entries import ConfigEntry, ConfigFlow from homeassistant.config_entries import ConfigEntry, ConfigFlow
@ -92,7 +92,7 @@ class MockCalendarEntity(CalendarEntity):
@pytest.fixture @pytest.fixture
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View file

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator
from datetime import timedelta from datetime import timedelta
from http import HTTPStatus from http import HTTPStatus
from typing import Any from typing import Any
@ -10,6 +9,7 @@ from typing import Any
from freezegun import freeze_time from freezegun import freeze_time
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from typing_extensions import Generator
import voluptuous as vol import voluptuous as vol
from homeassistant.components.calendar import ( from homeassistant.components.calendar import (
@ -37,7 +37,7 @@ def mock_frozen_time() -> None:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_set_frozen_time(frozen_time: Any) -> Generator[None, None, None]: def mock_set_frozen_time(frozen_time: Any) -> Generator[None]:
"""Fixture to freeze time that also can work for other fixtures.""" """Fixture to freeze time that also can work for other fixtures."""
if not frozen_time: if not frozen_time:
yield yield

View file

@ -9,7 +9,7 @@ forward exercising the triggers.
from __future__ import annotations from __future__ import annotations
from collections.abc import AsyncIterator, Callable, Generator from collections.abc import AsyncIterator, Callable
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
import datetime import datetime
import logging import logging
@ -19,6 +19,7 @@ import zoneinfo
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components import automation, calendar from homeassistant.components import automation, calendar
from homeassistant.components.calendar.trigger import EVENT_END, EVENT_START from homeassistant.components.calendar.trigger import EVENT_END, EVENT_START
@ -86,7 +87,7 @@ class FakeSchedule:
@pytest.fixture @pytest.fixture
def fake_schedule( def fake_schedule(
hass: HomeAssistant, freezer: FrozenDateTimeFactory hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> Generator[FakeSchedule, None, None]: ) -> Generator[FakeSchedule]:
"""Fixture that tests can use to make fake events.""" """Fixture that tests can use to make fake events."""
# Setup start time for all tests # Setup start time for all tests
@ -161,7 +162,7 @@ def calls_data(hass: HomeAssistant) -> Callable[[], list[dict[str, Any]]]:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_update_interval() -> Generator[None, None, None]: def mock_update_interval() -> Generator[None]:
"""Fixture to override the update interval for refreshing events.""" """Fixture to override the update interval for refreshing events."""
with patch( with patch(
"homeassistant.components.calendar.trigger.UPDATE_INTERVAL", "homeassistant.components.calendar.trigger.UPDATE_INTERVAL",

View file

@ -1,14 +1,14 @@
"""Common fixtures for the Midea ccm15 AC Controller tests.""" """Common fixtures for the Midea ccm15 AC Controller tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from ccm15 import CCM15DeviceState, CCM15SlaveDevice from ccm15 import CCM15DeviceState, CCM15SlaveDevice
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.ccm15.async_setup_entry", return_value=True "homeassistant.components.ccm15.async_setup_entry", return_value=True
@ -17,7 +17,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def ccm15_device() -> Generator[AsyncMock, None, None]: def ccm15_device() -> Generator[AsyncMock]:
"""Mock ccm15 device.""" """Mock ccm15 device."""
ccm15_devices = { ccm15_devices = {
0: CCM15SlaveDevice(bytes.fromhex("000000b0b8001b")), 0: CCM15SlaveDevice(bytes.fromhex("000000b0b8001b")),
@ -32,7 +32,7 @@ def ccm15_device() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def network_failure_ccm15_device() -> Generator[AsyncMock, None, None]: def network_failure_ccm15_device() -> Generator[AsyncMock]:
"""Mock empty set of ccm15 device.""" """Mock empty set of ccm15 device."""
device_state = CCM15DeviceState(devices={}) device_state = CCM15DeviceState(devices={})
with patch( with patch(

View file

@ -1,13 +1,13 @@
"""Configuration for cert_expiry tests.""" """Configuration for cert_expiry tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.cert_expiry.async_setup_entry", return_value=True "homeassistant.components.cert_expiry.async_setup_entry", return_value=True

View file

@ -1,8 +1,7 @@
"""Fixtures for Climate platform tests.""" """Fixtures for Climate platform tests."""
from collections.abc import Generator
import pytest import pytest
from typing_extensions import Generator
from homeassistant.config_entries import ConfigFlow from homeassistant.config_entries import ConfigFlow
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -15,7 +14,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture @pytest.fixture
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, "test.config_flow") mock_platform(hass, "test.config_flow")

View file

@ -1,9 +1,9 @@
"""Test climate intents.""" """Test climate intents."""
from collections.abc import Generator
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.climate import ( from homeassistant.components.climate import (
DOMAIN, DOMAIN,
@ -34,7 +34,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View file

@ -1,6 +1,6 @@
"""Fixtures for cloud tests.""" """Fixtures for cloud tests."""
from collections.abc import AsyncGenerator, Callable, Coroutine from collections.abc import Callable, Coroutine
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from unittest.mock import DEFAULT, MagicMock, PropertyMock, patch from unittest.mock import DEFAULT, MagicMock, PropertyMock, patch
@ -15,6 +15,7 @@ from hass_nabucasa.remote import RemoteUI
from hass_nabucasa.voice import Voice from hass_nabucasa.voice import Voice
import jwt import jwt
import pytest import pytest
from typing_extensions import AsyncGenerator
from homeassistant.components.cloud import CloudClient, const, prefs from homeassistant.components.cloud import CloudClient, const, prefs
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -34,7 +35,7 @@ async def load_homeassistant(hass: HomeAssistant) -> None:
@pytest.fixture(name="cloud") @pytest.fixture(name="cloud")
async def cloud_fixture() -> AsyncGenerator[MagicMock, None]: async def cloud_fixture() -> AsyncGenerator[MagicMock]:
"""Mock the cloud object. """Mock the cloud object.
See the real hass_nabucasa.Cloud class for how to configure the mock. See the real hass_nabucasa.Cloud class for how to configure the mock.

View file

@ -1,10 +1,10 @@
"""Tests for the cloud binary sensor.""" """Tests for the cloud binary sensor."""
from collections.abc import Generator
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from hass_nabucasa.const import DISPATCH_REMOTE_CONNECT, DISPATCH_REMOTE_DISCONNECT from hass_nabucasa.const import DISPATCH_REMOTE_CONNECT, DISPATCH_REMOTE_DISCONNECT
import pytest import pytest
from typing_extensions import Generator
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import EntityRegistry from homeassistant.helpers.entity_registry import EntityRegistry
@ -12,7 +12,7 @@ from homeassistant.setup import async_setup_component
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_wait_until() -> Generator[None, None, None]: def mock_wait_until() -> Generator[None]:
"""Mock WAIT_UNTIL_CHANGE to execute callback immediately.""" """Mock WAIT_UNTIL_CHANGE to execute callback immediately."""
with patch("homeassistant.components.cloud.binary_sensor.WAIT_UNTIL_CHANGE", 0): with patch("homeassistant.components.cloud.binary_sensor.WAIT_UNTIL_CHANGE", 0):
yield yield

View file

@ -1,6 +1,5 @@
"""Test the speech-to-text platform for the cloud integration.""" """Test the speech-to-text platform for the cloud integration."""
from collections.abc import AsyncGenerator
from copy import deepcopy from copy import deepcopy
from http import HTTPStatus from http import HTTPStatus
from typing import Any from typing import Any
@ -8,6 +7,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
from hass_nabucasa.voice import STTResponse, VoiceError from hass_nabucasa.voice import STTResponse, VoiceError
import pytest import pytest
from typing_extensions import AsyncGenerator
from homeassistant.components.assist_pipeline.pipeline import STORAGE_KEY from homeassistant.components.assist_pipeline.pipeline import STORAGE_KEY
from homeassistant.components.cloud import DOMAIN from homeassistant.components.cloud import DOMAIN
@ -21,7 +21,7 @@ from tests.typing import ClientSessionGenerator
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def delay_save_fixture() -> AsyncGenerator[None, None]: async def delay_save_fixture() -> AsyncGenerator[None]:
"""Load the homeassistant integration.""" """Load the homeassistant integration."""
with patch("homeassistant.helpers.collection.SAVE_DELAY", new=0): with patch("homeassistant.helpers.collection.SAVE_DELAY", new=0):
yield yield

View file

@ -1,6 +1,6 @@
"""Tests for cloud tts.""" """Tests for cloud tts."""
from collections.abc import AsyncGenerator, Callable, Coroutine from collections.abc import Callable, Coroutine
from copy import deepcopy from copy import deepcopy
from http import HTTPStatus from http import HTTPStatus
from typing import Any from typing import Any
@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
from hass_nabucasa.voice import TTS_VOICES, VoiceError, VoiceTokenError from hass_nabucasa.voice import TTS_VOICES, VoiceError, VoiceTokenError
import pytest import pytest
from typing_extensions import AsyncGenerator
import voluptuous as vol import voluptuous as vol
from homeassistant.components.assist_pipeline.pipeline import STORAGE_KEY from homeassistant.components.assist_pipeline.pipeline import STORAGE_KEY
@ -39,7 +40,7 @@ from tests.typing import ClientSessionGenerator
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def delay_save_fixture() -> AsyncGenerator[None, None]: async def delay_save_fixture() -> AsyncGenerator[None]:
"""Load the homeassistant integration.""" """Load the homeassistant integration."""
with patch("homeassistant.helpers.collection.SAVE_DELAY", new=0): with patch("homeassistant.helpers.collection.SAVE_DELAY", new=0):
yield yield

View file

@ -2,12 +2,13 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable, Generator from collections.abc import Callable
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -21,7 +22,7 @@ if TYPE_CHECKING:
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def patch_zeroconf_multiple_catcher() -> Generator[None, None, None]: def patch_zeroconf_multiple_catcher() -> Generator[None]:
"""Patch zeroconf wrapper that detects if multiple instances are used.""" """Patch zeroconf wrapper that detects if multiple instances are used."""
with patch( with patch(
"homeassistant.components.zeroconf.install_multiple_zeroconf_catcher", "homeassistant.components.zeroconf.install_multiple_zeroconf_catcher",
@ -31,7 +32,7 @@ def patch_zeroconf_multiple_catcher() -> Generator[None, None, None]:
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def prevent_io() -> Generator[None, None, None]: def prevent_io() -> Generator[None]:
"""Fixture to prevent certain I/O from happening.""" """Fixture to prevent certain I/O from happening."""
with patch( with patch(
"homeassistant.components.http.ban.load_yaml_config_file", "homeassistant.components.http.ban.load_yaml_config_file",
@ -40,7 +41,7 @@ def prevent_io() -> Generator[None, None, None]:
@pytest.fixture @pytest.fixture
def entity_registry_enabled_by_default() -> Generator[None, None, None]: def entity_registry_enabled_by_default() -> Generator[None]:
"""Test fixture that ensures all entities are enabled in the registry.""" """Test fixture that ensures all entities are enabled in the registry."""
with patch( with patch(
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default", "homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
@ -51,7 +52,7 @@ def entity_registry_enabled_by_default() -> Generator[None, None, None]:
# Blueprint test fixtures # Blueprint test fixtures
@pytest.fixture(name="stub_blueprint_populate") @pytest.fixture(name="stub_blueprint_populate")
def stub_blueprint_populate_fixture() -> Generator[None, None, None]: def stub_blueprint_populate_fixture() -> Generator[None]:
"""Stub copying the blueprints to the config folder.""" """Stub copying the blueprints to the config folder."""
from tests.components.blueprint.common import stub_blueprint_populate_fixture_helper from tests.components.blueprint.common import stub_blueprint_populate_fixture_helper
@ -60,7 +61,7 @@ def stub_blueprint_populate_fixture() -> Generator[None, None, None]:
# TTS test fixtures # TTS test fixtures
@pytest.fixture(name="mock_tts_get_cache_files") @pytest.fixture(name="mock_tts_get_cache_files")
def mock_tts_get_cache_files_fixture() -> Generator[MagicMock, None, None]: def mock_tts_get_cache_files_fixture() -> Generator[MagicMock]:
"""Mock the list TTS cache function.""" """Mock the list TTS cache function."""
from tests.components.tts.common import mock_tts_get_cache_files_fixture_helper from tests.components.tts.common import mock_tts_get_cache_files_fixture_helper
@ -70,7 +71,7 @@ def mock_tts_get_cache_files_fixture() -> Generator[MagicMock, None, None]:
@pytest.fixture(name="mock_tts_init_cache_dir") @pytest.fixture(name="mock_tts_init_cache_dir")
def mock_tts_init_cache_dir_fixture( def mock_tts_init_cache_dir_fixture(
init_tts_cache_dir_side_effect: Any, init_tts_cache_dir_side_effect: Any,
) -> Generator[MagicMock, None, None]: ) -> Generator[MagicMock]:
"""Mock the TTS cache dir in memory.""" """Mock the TTS cache dir in memory."""
from tests.components.tts.common import mock_tts_init_cache_dir_fixture_helper from tests.components.tts.common import mock_tts_init_cache_dir_fixture_helper
@ -93,7 +94,7 @@ def mock_tts_cache_dir_fixture(
mock_tts_init_cache_dir: MagicMock, mock_tts_init_cache_dir: MagicMock,
mock_tts_get_cache_files: MagicMock, mock_tts_get_cache_files: MagicMock,
request: pytest.FixtureRequest, request: pytest.FixtureRequest,
) -> Generator[Path, None, None]: ) -> Generator[Path]:
"""Mock the TTS cache dir with empty dir.""" """Mock the TTS cache dir with empty dir."""
from tests.components.tts.common import mock_tts_cache_dir_fixture_helper from tests.components.tts.common import mock_tts_cache_dir_fixture_helper
@ -103,7 +104,7 @@ def mock_tts_cache_dir_fixture(
@pytest.fixture(name="tts_mutagen_mock") @pytest.fixture(name="tts_mutagen_mock")
def tts_mutagen_mock_fixture() -> Generator[MagicMock, None, None]: def tts_mutagen_mock_fixture() -> Generator[MagicMock]:
"""Mock writing tags.""" """Mock writing tags."""
from tests.components.tts.common import tts_mutagen_mock_fixture_helper from tests.components.tts.common import tts_mutagen_mock_fixture_helper
@ -121,7 +122,7 @@ def mock_conversation_agent_fixture(hass: HomeAssistant) -> MockAgent:
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def prevent_ffmpeg_subprocess() -> Generator[None, None, None]: def prevent_ffmpeg_subprocess() -> Generator[None]:
"""Prevent ffmpeg from creating a subprocess.""" """Prevent ffmpeg from creating a subprocess."""
with patch( with patch(
"homeassistant.components.ffmpeg.FFVersion.get_version", return_value="6.0" "homeassistant.components.ffmpeg.FFVersion.get_version", return_value="6.0"

View file

@ -2,10 +2,10 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.cpuspeed.const import DOMAIN from homeassistant.components.cpuspeed.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -25,7 +25,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_cpuinfo_config_flow() -> Generator[MagicMock, None, None]: def mock_cpuinfo_config_flow() -> Generator[MagicMock]:
"""Return a mocked get_cpu_info. """Return a mocked get_cpu_info.
It is only used to check truthy or falsy values, so it is mocked It is only used to check truthy or falsy values, so it is mocked
@ -39,7 +39,7 @@ def mock_cpuinfo_config_flow() -> Generator[MagicMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.cpuspeed.async_setup_entry", return_value=True "homeassistant.components.cpuspeed.async_setup_entry", return_value=True
@ -48,7 +48,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_cpuinfo() -> Generator[MagicMock, None, None]: def mock_cpuinfo() -> Generator[MagicMock]:
"""Return a mocked get_cpu_info.""" """Return a mocked get_cpu_info."""
info = { info = {
"hz_actual": (3200000001, 0), "hz_actual": (3200000001, 0),

View file

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from crownstone_cloud.cloud_models.spheres import Spheres from crownstone_cloud.cloud_models.spheres import Spheres
@ -12,6 +11,7 @@ from crownstone_cloud.exceptions import (
) )
import pytest import pytest
from serial.tools.list_ports_common import ListPortInfo from serial.tools.list_ports_common import ListPortInfo
from typing_extensions import Generator
from homeassistant.components import usb from homeassistant.components import usb
from homeassistant.components.crownstone.const import ( from homeassistant.components.crownstone.const import (
@ -30,7 +30,7 @@ from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
type MockFixture = Generator[MagicMock | AsyncMock, None, None] type MockFixture = Generator[MagicMock | AsyncMock]
@pytest.fixture(name="crownstone_setup") @pytest.fixture(name="crownstone_setup")

View file

@ -1,9 +1,9 @@
"""Test Device Tracker config entry things.""" """Test Device Tracker config entry things."""
from collections.abc import Generator
from typing import Any from typing import Any
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.device_tracker import ( from homeassistant.components.device_tracker import (
ATTR_HOST_NAME, ATTR_HOST_NAME,
@ -55,7 +55,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View file

@ -1,9 +1,9 @@
"""Fixtures for tests.""" """Fixtures for tests."""
from collections.abc import Generator
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
@ -19,9 +19,7 @@ def maintenance() -> bool:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def patch_mydevolo( def patch_mydevolo(credentials_valid: bool, maintenance: bool) -> Generator[None]:
credentials_valid: bool, maintenance: bool
) -> Generator[None, None, None]:
"""Fixture to patch mydevolo into a desired state.""" """Fixture to patch mydevolo into a desired state."""
with ( with (
patch( patch(

View file

@ -1,10 +1,10 @@
"""Fixtures for Discovergy integration tests.""" """Fixtures for Discovergy integration tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from pydiscovergy.models import Reading from pydiscovergy.models import Reading
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.discovergy.const import DOMAIN from homeassistant.components.discovergy.const import DOMAIN
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
@ -25,7 +25,7 @@ def _meter_last_reading(meter_id: str) -> Reading:
@pytest.fixture(name="discovergy") @pytest.fixture(name="discovergy")
def mock_discovergy() -> Generator[AsyncMock, None, None]: def mock_discovergy() -> Generator[AsyncMock]:
"""Mock the pydiscovergy client.""" """Mock the pydiscovergy client."""
with ( with (
patch( patch(

View file

@ -1,10 +1,11 @@
"""Configure pytest for D-Link tests.""" """Configure pytest for D-Link tests."""
from collections.abc import Awaitable, Callable, Generator from collections.abc import Awaitable, Callable
from copy import deepcopy from copy import deepcopy
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components import dhcp from homeassistant.components import dhcp
from homeassistant.components.dlink.const import CONF_USE_LEGACY_PROTOCOL, DOMAIN from homeassistant.components.dlink.const import CONF_USE_LEGACY_PROTOCOL, DOMAIN
@ -130,7 +131,7 @@ async def setup_integration(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_with_uid: MockConfigEntry, config_entry_with_uid: MockConfigEntry,
mocked_plug: MagicMock, mocked_plug: MagicMock,
) -> Generator[ComponentSetup, None, None]: ) -> Generator[ComponentSetup]:
"""Set up the D-Link integration in Home Assistant.""" """Set up the D-Link integration in Home Assistant."""
async def func() -> None: async def func() -> None:
@ -144,7 +145,7 @@ async def setup_integration_legacy(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_with_uid: MockConfigEntry, config_entry_with_uid: MockConfigEntry,
mocked_plug_legacy: MagicMock, mocked_plug_legacy: MagicMock,
) -> Generator[ComponentSetup, None, None]: ) -> Generator[ComponentSetup]:
"""Set up the D-Link integration in Home Assistant with different data.""" """Set up the D-Link integration in Home Assistant with different data."""
async def func() -> None: async def func() -> None:

View file

@ -1,13 +1,13 @@
"""Common fixtures for the duotecno tests.""" """Common fixtures for the duotecno tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.duotecno.async_setup_entry", return_value=True "homeassistant.components.duotecno.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Configuration for Deutscher Wetterdienst (DWD) Weather Warnings tests.""" """Configuration for Deutscher Wetterdienst (DWD) Weather Warnings tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, Mock, patch from unittest.mock import AsyncMock, MagicMock, Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.dwd_weather_warnings.const import ( from homeassistant.components.dwd_weather_warnings.const import (
ADVANCE_WARNING_SENSOR, ADVANCE_WARNING_SENSOR,
@ -23,7 +23,7 @@ MOCK_CONDITIONS = [CURRENT_WARNING_SENSOR, ADVANCE_WARNING_SENSOR]
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.dwd_weather_warnings.async_setup_entry", "homeassistant.components.dwd_weather_warnings.async_setup_entry",
@ -59,7 +59,7 @@ def mock_tracker_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_dwdwfsapi() -> Generator[MagicMock, None, None]: def mock_dwdwfsapi() -> Generator[MagicMock]:
"""Return a mocked dwdwfsapi API client.""" """Return a mocked dwdwfsapi API client."""
with ( with (
patch( patch(

View file

@ -1,11 +1,11 @@
"""Fixtures for easyEnergy integration tests.""" """Fixtures for easyEnergy integration tests."""
from collections.abc import Generator
import json import json
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from easyenergy import Electricity, Gas from easyenergy import Electricity, Gas
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.easyenergy.const import DOMAIN from homeassistant.components.easyenergy.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -14,7 +14,7 @@ from tests.common import MockConfigEntry, load_fixture
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.easyenergy.async_setup_entry", return_value=True "homeassistant.components.easyenergy.async_setup_entry", return_value=True
@ -34,7 +34,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_easyenergy() -> Generator[MagicMock, None, None]: def mock_easyenergy() -> Generator[MagicMock]:
"""Return a mocked easyEnergy client.""" """Return a mocked easyEnergy client."""
with patch( with patch(
"homeassistant.components.easyenergy.coordinator.EasyEnergy", autospec=True "homeassistant.components.easyenergy.coordinator.EasyEnergy", autospec=True

View file

@ -1,10 +1,10 @@
"""Common fixtures for the Ecoforest tests.""" """Common fixtures for the Ecoforest tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
from pyecoforest.models.device import Alarm, Device, OperationMode, State from pyecoforest.models.device import Alarm, Device, OperationMode, State
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.ecoforest import DOMAIN from homeassistant.components.ecoforest import DOMAIN
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
@ -14,7 +14,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.ecoforest.async_setup_entry", return_value=True "homeassistant.components.ecoforest.async_setup_entry", return_value=True

View file

@ -1,6 +1,5 @@
"""Common fixtures for the Ecovacs tests.""" """Common fixtures for the Ecovacs tests."""
from collections.abc import AsyncGenerator, Generator
from typing import Any from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
@ -10,6 +9,7 @@ from deebot_client.device import Device
from deebot_client.exceptions import ApiError from deebot_client.exceptions import ApiError
from deebot_client.models import Credentials from deebot_client.models import Credentials
import pytest import pytest
from typing_extensions import AsyncGenerator, Generator
from homeassistant.components.ecovacs import PLATFORMS from homeassistant.components.ecovacs import PLATFORMS
from homeassistant.components.ecovacs.const import DOMAIN from homeassistant.components.ecovacs.const import DOMAIN
@ -23,7 +23,7 @@ from tests.common import MockConfigEntry, load_json_object_fixture
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.ecovacs.async_setup_entry", return_value=True "homeassistant.components.ecovacs.async_setup_entry", return_value=True
@ -54,7 +54,7 @@ def device_fixture() -> str:
@pytest.fixture @pytest.fixture
def mock_authenticator(device_fixture: str) -> Generator[Mock, None, None]: def mock_authenticator(device_fixture: str) -> Generator[Mock]:
"""Mock the authenticator.""" """Mock the authenticator."""
with ( with (
patch( patch(
@ -99,7 +99,7 @@ def mock_authenticator_authenticate(mock_authenticator: Mock) -> AsyncMock:
@pytest.fixture @pytest.fixture
def mock_mqtt_client(mock_authenticator: Mock) -> Generator[Mock, None, None]: def mock_mqtt_client(mock_authenticator: Mock) -> Generator[Mock]:
"""Mock the MQTT client.""" """Mock the MQTT client."""
with ( with (
patch( patch(
@ -118,7 +118,7 @@ def mock_mqtt_client(mock_authenticator: Mock) -> Generator[Mock, None, None]:
@pytest.fixture @pytest.fixture
def mock_device_execute() -> Generator[AsyncMock, None, None]: def mock_device_execute() -> Generator[AsyncMock]:
"""Mock the device execute function.""" """Mock the device execute function."""
with patch.object( with patch.object(
Device, Device,
@ -142,7 +142,7 @@ async def init_integration(
mock_mqtt_client: Mock, mock_mqtt_client: Mock,
mock_device_execute: AsyncMock, mock_device_execute: AsyncMock,
platforms: Platform | list[Platform], platforms: Platform | list[Platform],
) -> AsyncGenerator[MockConfigEntry, None]: ) -> AsyncGenerator[MockConfigEntry]:
"""Set up the Ecovacs integration for testing.""" """Set up the Ecovacs integration for testing."""
if not isinstance(platforms, list): if not isinstance(platforms, list):
platforms = [platforms] platforms = [platforms]

View file

@ -1,13 +1,13 @@
"""Define test fixtures for EDL21.""" """Define test fixtures for EDL21."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.edl21.async_setup_entry", return_value=True "homeassistant.components.edl21.async_setup_entry", return_value=True

View file

@ -2,12 +2,13 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Awaitable, Callable, Generator from collections.abc import Awaitable, Callable
from time import time from time import time
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from electrickiwi_api.model import AccountBalance, Hop, HopIntervals from electrickiwi_api.model import AccountBalance, Hop, HopIntervals
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.application_credentials import ( from homeassistant.components.application_credentials import (
ClientCredential, ClientCredential,
@ -23,7 +24,7 @@ CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"
REDIRECT_URI = "https://example.com/auth/external/callback" REDIRECT_URI = "https://example.com/auth/external/callback"
type YieldFixture = Generator[AsyncMock, None, None] type YieldFixture = Generator[AsyncMock]
type ComponentSetup = Callable[[], Awaitable[bool]] type ComponentSetup = Callable[[], Awaitable[bool]]
@ -79,7 +80,7 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.electric_kiwi.async_setup_entry", return_value=True "homeassistant.components.electric_kiwi.async_setup_entry", return_value=True

View file

@ -1,10 +1,10 @@
"""Fixtures for Elgato integration tests.""" """Fixtures for Elgato integration tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from elgato import BatteryInfo, ElgatoNoBatteryError, Info, Settings, State from elgato import BatteryInfo, ElgatoNoBatteryError, Info, Settings, State
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.elgato.const import DOMAIN from homeassistant.components.elgato.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT
@ -42,7 +42,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.elgato.async_setup_entry", return_value=True "homeassistant.components.elgato.async_setup_entry", return_value=True

View file

@ -1,6 +1,5 @@
"""Configuration for Elmax tests.""" """Configuration for Elmax tests."""
from collections.abc import Generator
import json import json
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
@ -13,6 +12,7 @@ from elmax_api.constants import (
from httpx import Response from httpx import Response
import pytest import pytest
import respx import respx
from typing_extensions import Generator
from . import ( from . import (
MOCK_DIRECT_HOST, MOCK_DIRECT_HOST,
@ -30,7 +30,7 @@ MOCK_DIRECT_BASE_URI = (
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def httpx_mock_cloud_fixture() -> Generator[respx.MockRouter, None, None]: def httpx_mock_cloud_fixture() -> Generator[respx.MockRouter]:
"""Configure httpx fixture for cloud API communication.""" """Configure httpx fixture for cloud API communication."""
with respx.mock(base_url=BASE_URL, assert_all_called=False) as respx_mock: with respx.mock(base_url=BASE_URL, assert_all_called=False) as respx_mock:
# Mock Login POST. # Mock Login POST.
@ -57,7 +57,7 @@ def httpx_mock_cloud_fixture() -> Generator[respx.MockRouter, None, None]:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def httpx_mock_direct_fixture() -> Generator[respx.MockRouter, None, None]: def httpx_mock_direct_fixture() -> Generator[respx.MockRouter]:
"""Configure httpx fixture for direct Panel-API communication.""" """Configure httpx fixture for direct Panel-API communication."""
with respx.mock( with respx.mock(
base_url=MOCK_DIRECT_BASE_URI, assert_all_called=False base_url=MOCK_DIRECT_BASE_URI, assert_all_called=False
@ -80,7 +80,7 @@ def httpx_mock_direct_fixture() -> Generator[respx.MockRouter, None, None]:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def elmax_mock_direct_cert() -> Generator[AsyncMock, None, None]: def elmax_mock_direct_cert() -> Generator[AsyncMock]:
"""Patch elmax library to return a specific PEM for SSL communication.""" """Patch elmax library to return a specific PEM for SSL communication."""
with patch( with patch(
"elmax_api.http.GenericElmax.retrieve_server_certificate", "elmax_api.http.GenericElmax.retrieve_server_certificate",

View file

@ -1,13 +1,13 @@
"""Common fixtures for the Elvia tests.""" """Common fixtures for the Elvia tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.elvia.async_setup_entry", return_value=True "homeassistant.components.elvia.async_setup_entry", return_value=True

View file

@ -1,7 +1,6 @@
"""The tests for the emulated Hue component.""" """The tests for the emulated Hue component."""
from asyncio import AbstractEventLoop from asyncio import AbstractEventLoop
from collections.abc import Generator
from http import HTTPStatus from http import HTTPStatus
import json import json
import unittest import unittest
@ -11,6 +10,7 @@ from aiohttp import web
from aiohttp.test_utils import TestClient from aiohttp.test_utils import TestClient
import defusedxml.ElementTree as ET import defusedxml.ElementTree as ET
import pytest import pytest
from typing_extensions import Generator
from homeassistant import setup from homeassistant import setup
from homeassistant.components import emulated_hue from homeassistant.components import emulated_hue
@ -49,7 +49,7 @@ def aiohttp_client(
@pytest.fixture @pytest.fixture
def hue_client( def hue_client(
aiohttp_client: ClientSessionGenerator, aiohttp_client: ClientSessionGenerator,
) -> Generator[TestClient, None, None]: ) -> Generator[TestClient]:
"""Return a hue API client.""" """Return a hue API client."""
app = web.Application() app = web.Application()
with unittest.mock.patch( with unittest.mock.patch(

View file

@ -1,11 +1,11 @@
"""Configure tests for Energenie-Power-Sockets.""" """Configure tests for Energenie-Power-Sockets."""
from collections.abc import Generator
from typing import Final from typing import Final
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from pyegps.fakes.powerstrip import FakePowerStrip from pyegps.fakes.powerstrip import FakePowerStrip
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.energenie_power_sockets.const import ( from homeassistant.components.energenie_power_sockets.const import (
CONF_DEVICE_API_ID, CONF_DEVICE_API_ID,
@ -58,7 +58,7 @@ def get_pyegps_device_mock() -> MagicMock:
@pytest.fixture(name="mock_get_device") @pytest.fixture(name="mock_get_device")
def patch_get_device(pyegps_device_mock: MagicMock) -> Generator[MagicMock, None, None]: def patch_get_device(pyegps_device_mock: MagicMock) -> Generator[MagicMock]:
"""Fixture to patch the `get_device` api method.""" """Fixture to patch the `get_device` api method."""
with ( with (
patch("homeassistant.components.energenie_power_sockets.get_device") as m1, patch("homeassistant.components.energenie_power_sockets.get_device") as m1,
@ -74,7 +74,7 @@ def patch_get_device(pyegps_device_mock: MagicMock) -> Generator[MagicMock, None
@pytest.fixture(name="mock_search_for_devices") @pytest.fixture(name="mock_search_for_devices")
def patch_search_devices( def patch_search_devices(
pyegps_device_mock: MagicMock, pyegps_device_mock: MagicMock,
) -> Generator[MagicMock, None, None]: ) -> Generator[MagicMock]:
"""Fixture to patch the `search_for_devices` api method.""" """Fixture to patch the `search_for_devices` api method."""
with patch( with patch(
"homeassistant.components.energenie_power_sockets.config_flow.search_for_devices", "homeassistant.components.energenie_power_sockets.config_flow.search_for_devices",

View file

@ -1,11 +1,11 @@
"""Fixtures for EnergyZero integration tests.""" """Fixtures for EnergyZero integration tests."""
from collections.abc import Generator
import json import json
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from energyzero import Electricity, Gas from energyzero import Electricity, Gas
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.energyzero.const import DOMAIN from homeassistant.components.energyzero.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -14,7 +14,7 @@ from tests.common import MockConfigEntry, load_fixture
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.energyzero.async_setup_entry", return_value=True "homeassistant.components.energyzero.async_setup_entry", return_value=True
@ -34,7 +34,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_energyzero() -> Generator[MagicMock, None, None]: def mock_energyzero() -> Generator[MagicMock]:
"""Return a mocked EnergyZero client.""" """Return a mocked EnergyZero client."""
with patch( with patch(
"homeassistant.components.energyzero.coordinator.EnergyZero", autospec=True "homeassistant.components.energyzero.coordinator.EnergyZero", autospec=True

View file

@ -1,10 +1,10 @@
"""The tests for the event integration.""" """The tests for the event integration."""
from collections.abc import Generator
from typing import Any from typing import Any
from freezegun import freeze_time from freezegun import freeze_time
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.event import ( from homeassistant.components.event import (
ATTR_EVENT_TYPE, ATTR_EVENT_TYPE,
@ -238,7 +238,7 @@ class MockFlow(ConfigFlow):
@pytest.fixture @pytest.fixture
def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]: def config_flow_fixture(hass: HomeAssistant) -> Generator[None]:
"""Mock config flow.""" """Mock config flow."""
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View file

@ -1,9 +1,9 @@
"""Test helpers.""" """Test helpers."""
from collections.abc import Generator
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.fibaro import CONF_IMPORT_PLUGINS, DOMAIN from homeassistant.components.fibaro import CONF_IMPORT_PLUGINS, DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME
@ -21,7 +21,7 @@ TEST_MODEL = "HC3"
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.fibaro.async_setup_entry", return_value=True "homeassistant.components.fibaro.async_setup_entry", return_value=True
@ -66,7 +66,7 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_fibaro_client() -> Generator[Mock, None, None]: def mock_fibaro_client() -> Generator[Mock]:
"""Return a mocked FibaroClient.""" """Return a mocked FibaroClient."""
info_mock = Mock() info_mock = Mock()
info_mock.serial_number = TEST_SERIALNUMBER info_mock.serial_number = TEST_SERIALNUMBER

View file

@ -1,15 +1,15 @@
"""Test fixtures for file platform.""" """Test fixtures for file platform."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.file.async_setup_entry", return_value=True "homeassistant.components.file.async_setup_entry", return_value=True

View file

@ -2,11 +2,11 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator
from pathlib import Path from pathlib import Path
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.filesize.const import DOMAIN from homeassistant.components.filesize.const import DOMAIN
from homeassistant.const import CONF_FILE_PATH from homeassistant.const import CONF_FILE_PATH
@ -29,7 +29,7 @@ def mock_config_entry(tmp_path: Path) -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[None, None, None]: def mock_setup_entry() -> Generator[None]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.filesize.async_setup_entry", return_value=True "homeassistant.components.filesize.async_setup_entry", return_value=True

View file

@ -1,6 +1,6 @@
"""Test fixtures for fitbit.""" """Test fixtures for fitbit."""
from collections.abc import Awaitable, Callable, Generator from collections.abc import Awaitable, Callable
import datetime import datetime
from http import HTTPStatus from http import HTTPStatus
import time import time
@ -9,6 +9,7 @@ from unittest.mock import patch
import pytest import pytest
from requests_mock.mocker import Mocker from requests_mock.mocker import Mocker
from typing_extensions import Generator
from homeassistant.components.application_credentials import ( from homeassistant.components.application_credentials import (
ClientCredential, ClientCredential,
@ -122,7 +123,7 @@ def mock_fitbit_config_yaml(token_expiration_time: float) -> dict[str, Any] | No
@pytest.fixture(name="fitbit_config_setup") @pytest.fixture(name="fitbit_config_setup")
def mock_fitbit_config_setup( def mock_fitbit_config_setup(
fitbit_config_yaml: dict[str, Any] | None, fitbit_config_yaml: dict[str, Any] | None,
) -> Generator[None, None, None]: ) -> Generator[None]:
"""Fixture to mock out fitbit.conf file data loading and persistence.""" """Fixture to mock out fitbit.conf file data loading and persistence."""
has_config = fitbit_config_yaml is not None has_config = fitbit_config_yaml is not None
with ( with (

View file

@ -1,10 +1,10 @@
"""Configuration for Flexit Nordic (BACnet) tests.""" """Configuration for Flexit Nordic (BACnet) tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from flexit_bacnet import FlexitBACnet from flexit_bacnet import FlexitBACnet
import pytest import pytest
from typing_extensions import Generator
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.flexit_bacnet.const import DOMAIN from homeassistant.components.flexit_bacnet.const import DOMAIN
@ -29,7 +29,7 @@ async def flow_id(hass: HomeAssistant) -> str:
@pytest.fixture @pytest.fixture
def mock_flexit_bacnet() -> Generator[AsyncMock, None, None]: def mock_flexit_bacnet() -> Generator[AsyncMock]:
"""Mock data from the device.""" """Mock data from the device."""
flexit_bacnet = AsyncMock(spec=FlexitBACnet) flexit_bacnet = AsyncMock(spec=FlexitBACnet)
with ( with (
@ -83,7 +83,7 @@ def mock_flexit_bacnet() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.flexit_bacnet.async_setup_entry", return_value=True "homeassistant.components.flexit_bacnet.async_setup_entry", return_value=True

View file

@ -2,12 +2,12 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator
from pathlib import Path from pathlib import Path
from unittest.mock import patch from unittest.mock import patch
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.folder_watcher.const import DOMAIN from homeassistant.components.folder_watcher.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER from homeassistant.config_entries import SOURCE_USER
@ -17,7 +17,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[None, None, None]: def mock_setup_entry() -> Generator[None]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.folder_watcher.async_setup_entry", return_value=True "homeassistant.components.folder_watcher.async_setup_entry", return_value=True

View file

@ -1,11 +1,11 @@
"""Fixtures for Forecast.Solar integration tests.""" """Fixtures for Forecast.Solar integration tests."""
from collections.abc import Generator
from datetime import datetime, timedelta from datetime import datetime, timedelta
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from forecast_solar import models from forecast_solar import models
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.forecast_solar.const import ( from homeassistant.components.forecast_solar.const import (
CONF_AZIMUTH, CONF_AZIMUTH,
@ -24,7 +24,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.forecast_solar.async_setup_entry", return_value=True "homeassistant.components.forecast_solar.async_setup_entry", return_value=True

View file

@ -2,12 +2,12 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator
from copy import deepcopy from copy import deepcopy
from typing import Any from typing import Any
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.freedompro.const import DOMAIN from homeassistant.components.freedompro.const import DOMAIN
@ -17,7 +17,7 @@ from tests.common import MockConfigEntry
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.freedompro.async_setup_entry", return_value=True "homeassistant.components.freedompro.async_setup_entry", return_value=True

View file

@ -1,9 +1,9 @@
"""Configuration for frontier_silicon tests.""" """Configuration for frontier_silicon tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.frontier_silicon.const import CONF_WEBFSAPI_URL, DOMAIN from homeassistant.components.frontier_silicon.const import CONF_WEBFSAPI_URL, DOMAIN
from homeassistant.const import CONF_PIN from homeassistant.const import CONF_PIN
@ -22,7 +22,7 @@ def config_entry() -> MockConfigEntry:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_valid_device_url() -> Generator[None, None, None]: def mock_valid_device_url() -> Generator[None]:
"""Return a valid webfsapi endpoint.""" """Return a valid webfsapi endpoint."""
with patch( with patch(
"afsapi.AFSAPI.get_webfsapi_endpoint", "afsapi.AFSAPI.get_webfsapi_endpoint",
@ -32,7 +32,7 @@ def mock_valid_device_url() -> Generator[None, None, None]:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_valid_pin() -> Generator[None, None, None]: def mock_valid_pin() -> Generator[None]:
"""Make get_friendly_name return a value, indicating a valid pin.""" """Make get_friendly_name return a value, indicating a valid pin."""
with patch( with patch(
"afsapi.AFSAPI.get_friendly_name", "afsapi.AFSAPI.get_friendly_name",
@ -42,14 +42,14 @@ def mock_valid_pin() -> Generator[None, None, None]:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_radio_id() -> Generator[None, None, None]: def mock_radio_id() -> Generator[None]:
"""Return a valid radio_id.""" """Return a valid radio_id."""
with patch("afsapi.AFSAPI.get_radio_id", return_value="mock_radio_id"): with patch("afsapi.AFSAPI.get_radio_id", return_value="mock_radio_id"):
yield yield
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.frontier_silicon.async_setup_entry", return_value=True "homeassistant.components.frontier_silicon.async_setup_entry", return_value=True

View file

@ -2,11 +2,11 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator
import json import json
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.fully_kiosk.const import DOMAIN from homeassistant.components.fully_kiosk.const import DOMAIN
from homeassistant.const import ( from homeassistant.const import (
@ -39,7 +39,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry.""" """Mock setting up a config entry."""
with patch( with patch(
"homeassistant.components.fully_kiosk.async_setup_entry", return_value=True "homeassistant.components.fully_kiosk.async_setup_entry", return_value=True
@ -48,7 +48,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_fully_kiosk_config_flow() -> Generator[MagicMock, None, None]: def mock_fully_kiosk_config_flow() -> Generator[MagicMock]:
"""Return a mocked Fully Kiosk client for the config flow.""" """Return a mocked Fully Kiosk client for the config flow."""
with patch( with patch(
"homeassistant.components.fully_kiosk.config_flow.FullyKiosk", "homeassistant.components.fully_kiosk.config_flow.FullyKiosk",
@ -64,7 +64,7 @@ def mock_fully_kiosk_config_flow() -> Generator[MagicMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_fully_kiosk() -> Generator[MagicMock, None, None]: def mock_fully_kiosk() -> Generator[MagicMock]:
"""Return a mocked Fully Kiosk client.""" """Return a mocked Fully Kiosk client."""
with patch( with patch(
"homeassistant.components.fully_kiosk.coordinator.FullyKiosk", "homeassistant.components.fully_kiosk.coordinator.FullyKiosk",

View file

@ -1,10 +1,10 @@
"""Test helpers for FYTA.""" """Test helpers for FYTA."""
from collections.abc import Generator
from datetime import UTC, datetime from datetime import UTC, datetime
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant.components.fyta.const import CONF_EXPIRATION, DOMAIN as FYTA_DOMAIN from homeassistant.components.fyta.const import CONF_EXPIRATION, DOMAIN as FYTA_DOMAIN
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME
@ -69,7 +69,7 @@ def mock_fyta_connector():
@pytest.fixture @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]: def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry.""" """Override async_setup_entry."""
with patch( with patch(
"homeassistant.components.fyta.async_setup_entry", return_value=True "homeassistant.components.fyta.async_setup_entry", return_value=True

View file

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from collections.abc import AsyncGenerator, Callable, Coroutine, Generator from collections.abc import Callable, Coroutine
from contextlib import asynccontextmanager, contextmanager from contextlib import asynccontextmanager, contextmanager
import functools import functools
import gc import gc
@ -32,6 +32,7 @@ import pytest
import pytest_socket import pytest_socket
import requests_mock import requests_mock
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from typing_extensions import AsyncGenerator, Generator
# Setup patching if dt_util time functions before any other Home Assistant imports # Setup patching if dt_util time functions before any other Home Assistant imports
from . import patch_time # noqa: F401, isort:skip from . import patch_time # noqa: F401, isort:skip
@ -292,7 +293,7 @@ def wait_for_stop_scripts_after_shutdown() -> bool:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def skip_stop_scripts( def skip_stop_scripts(
wait_for_stop_scripts_after_shutdown: bool, wait_for_stop_scripts_after_shutdown: bool,
) -> Generator[None, None, None]: ) -> Generator[None]:
"""Add ability to bypass _schedule_stop_scripts_after_shutdown.""" """Add ability to bypass _schedule_stop_scripts_after_shutdown."""
if wait_for_stop_scripts_after_shutdown: if wait_for_stop_scripts_after_shutdown:
yield yield
@ -305,7 +306,7 @@ def skip_stop_scripts(
@contextmanager @contextmanager
def long_repr_strings() -> Generator[None, None, None]: def long_repr_strings() -> Generator[None]:
"""Increase reprlib maxstring and maxother to 300.""" """Increase reprlib maxstring and maxother to 300."""
arepr = reprlib.aRepr arepr = reprlib.aRepr
original_maxstring = arepr.maxstring original_maxstring = arepr.maxstring
@ -330,7 +331,7 @@ def verify_cleanup(
event_loop: asyncio.AbstractEventLoop, event_loop: asyncio.AbstractEventLoop,
expected_lingering_tasks: bool, expected_lingering_tasks: bool,
expected_lingering_timers: bool, expected_lingering_timers: bool,
) -> Generator[None, None, None]: ) -> Generator[None]:
"""Verify that the test has cleaned up resources correctly.""" """Verify that the test has cleaned up resources correctly."""
threads_before = frozenset(threading.enumerate()) threads_before = frozenset(threading.enumerate())
tasks_before = asyncio.all_tasks(event_loop) tasks_before = asyncio.all_tasks(event_loop)
@ -378,14 +379,14 @@ def verify_cleanup(
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def reset_hass_threading_local_object() -> Generator[None, None, None]: def reset_hass_threading_local_object() -> Generator[None]:
"""Reset the _Hass threading.local object for every test case.""" """Reset the _Hass threading.local object for every test case."""
yield yield
ha._hass.__dict__.clear() ha._hass.__dict__.clear()
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def bcrypt_cost() -> Generator[None, None, None]: def bcrypt_cost() -> Generator[None]:
"""Run with reduced rounds during tests, to speed up uses.""" """Run with reduced rounds during tests, to speed up uses."""
import bcrypt import bcrypt
@ -400,7 +401,7 @@ def bcrypt_cost() -> Generator[None, None, None]:
@pytest.fixture @pytest.fixture
def hass_storage() -> Generator[dict[str, Any], None, None]: def hass_storage() -> Generator[dict[str, Any]]:
"""Fixture to mock storage.""" """Fixture to mock storage."""
with mock_storage() as stored_data: with mock_storage() as stored_data:
yield stored_data yield stored_data
@ -458,7 +459,7 @@ def aiohttp_client_cls() -> type[CoalescingClient]:
@pytest.fixture @pytest.fixture
def aiohttp_client( def aiohttp_client(
event_loop: asyncio.AbstractEventLoop, event_loop: asyncio.AbstractEventLoop,
) -> Generator[ClientSessionGenerator, None, None]: ) -> Generator[ClientSessionGenerator]:
"""Override the default aiohttp_client since 3.x does not support aiohttp_client_cls. """Override the default aiohttp_client since 3.x does not support aiohttp_client_cls.
Remove this when upgrading to 4.x as aiohttp_client_cls Remove this when upgrading to 4.x as aiohttp_client_cls
@ -523,7 +524,7 @@ async def hass(
hass_storage: dict[str, Any], hass_storage: dict[str, Any],
request: pytest.FixtureRequest, request: pytest.FixtureRequest,
mock_recorder_before_hass: None, mock_recorder_before_hass: None,
) -> AsyncGenerator[HomeAssistant, None]: ) -> AsyncGenerator[HomeAssistant]:
"""Create a test instance of Home Assistant.""" """Create a test instance of Home Assistant."""
loop = asyncio.get_running_loop() loop = asyncio.get_running_loop()
@ -582,7 +583,7 @@ async def hass(
@pytest.fixture @pytest.fixture
async def stop_hass() -> AsyncGenerator[None, None]: async def stop_hass() -> AsyncGenerator[None]:
"""Make sure all hass are stopped.""" """Make sure all hass are stopped."""
orig_hass = ha.HomeAssistant orig_hass = ha.HomeAssistant
@ -608,21 +609,21 @@ async def stop_hass() -> AsyncGenerator[None, None]:
@pytest.fixture(name="requests_mock") @pytest.fixture(name="requests_mock")
def requests_mock_fixture() -> Generator[requests_mock.Mocker, None, None]: def requests_mock_fixture() -> Generator[requests_mock.Mocker]:
"""Fixture to provide a requests mocker.""" """Fixture to provide a requests mocker."""
with requests_mock.mock() as m: with requests_mock.mock() as m:
yield m yield m
@pytest.fixture @pytest.fixture
def aioclient_mock() -> Generator[AiohttpClientMocker, None, None]: def aioclient_mock() -> Generator[AiohttpClientMocker]:
"""Fixture to mock aioclient calls.""" """Fixture to mock aioclient calls."""
with mock_aiohttp_client() as mock_session: with mock_aiohttp_client() as mock_session:
yield mock_session yield mock_session
@pytest.fixture @pytest.fixture
def mock_device_tracker_conf() -> Generator[list[Device], None, None]: def mock_device_tracker_conf() -> Generator[list[Device]]:
"""Prevent device tracker from reading/writing data.""" """Prevent device tracker from reading/writing data."""
devices: list[Device] = [] devices: list[Device] = []
@ -801,7 +802,7 @@ def hass_client_no_auth(
@pytest.fixture @pytest.fixture
def current_request() -> Generator[MagicMock, None, None]: def current_request() -> Generator[MagicMock]:
"""Mock current request.""" """Mock current request."""
with patch("homeassistant.components.http.current_request") as mock_request_context: with patch("homeassistant.components.http.current_request") as mock_request_context:
mocked_request = make_mocked_request( mocked_request = make_mocked_request(
@ -851,7 +852,7 @@ def hass_ws_client(
auth_ok = await websocket.receive_json() auth_ok = await websocket.receive_json()
assert auth_ok["type"] == TYPE_AUTH_OK assert auth_ok["type"] == TYPE_AUTH_OK
def _get_next_id() -> Generator[int, None, None]: def _get_next_id() -> Generator[int]:
i = 0 i = 0
while True: while True:
yield (i := i + 1) yield (i := i + 1)
@ -903,7 +904,7 @@ def mqtt_config_entry_data() -> dict[str, Any] | None:
@pytest.fixture @pytest.fixture
def mqtt_client_mock(hass: HomeAssistant) -> Generator[MqttMockPahoClient, None, None]: def mqtt_client_mock(hass: HomeAssistant) -> Generator[MqttMockPahoClient]:
"""Fixture to mock MQTT client.""" """Fixture to mock MQTT client."""
mid: int = 0 mid: int = 0
@ -975,7 +976,7 @@ async def mqtt_mock(
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None, mqtt_config_entry_data: dict[str, Any] | None,
mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> AsyncGenerator[MqttMockHAClient, None]: ) -> AsyncGenerator[MqttMockHAClient]:
"""Fixture to mock MQTT component.""" """Fixture to mock MQTT component."""
return await mqtt_mock_entry() return await mqtt_mock_entry()
@ -985,7 +986,7 @@ async def _mqtt_mock_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None, mqtt_config_entry_data: dict[str, Any] | None,
) -> AsyncGenerator[MqttMockHAClientGenerator, None]: ) -> AsyncGenerator[MqttMockHAClientGenerator]:
"""Fixture to mock a delayed setup of the MQTT config entry.""" """Fixture to mock a delayed setup of the MQTT config entry."""
# Local import to avoid processing MQTT modules when running a testcase # Local import to avoid processing MQTT modules when running a testcase
# which does not use MQTT. # which does not use MQTT.
@ -1059,9 +1060,7 @@ def hass_config() -> ConfigType:
@pytest.fixture @pytest.fixture
def mock_hass_config( def mock_hass_config(hass: HomeAssistant, hass_config: ConfigType) -> Generator[None]:
hass: HomeAssistant, hass_config: ConfigType
) -> Generator[None, None, None]:
"""Fixture to mock the content of main configuration. """Fixture to mock the content of main configuration.
Patches homeassistant.config.load_yaml_config_file and hass.config_entries Patches homeassistant.config.load_yaml_config_file and hass.config_entries
@ -1100,7 +1099,7 @@ def hass_config_yaml_files(hass_config_yaml: str) -> dict[str, str]:
@pytest.fixture @pytest.fixture
def mock_hass_config_yaml( def mock_hass_config_yaml(
hass: HomeAssistant, hass_config_yaml_files: dict[str, str] hass: HomeAssistant, hass_config_yaml_files: dict[str, str]
) -> Generator[None, None, None]: ) -> Generator[None]:
"""Fixture to mock the content of the yaml configuration files. """Fixture to mock the content of the yaml configuration files.
Patches yaml configuration files using the `hass_config_yaml` Patches yaml configuration files using the `hass_config_yaml`
@ -1115,7 +1114,7 @@ async def mqtt_mock_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None, mqtt_config_entry_data: dict[str, Any] | None,
) -> AsyncGenerator[MqttMockHAClientGenerator, None]: ) -> AsyncGenerator[MqttMockHAClientGenerator]:
"""Set up an MQTT config entry.""" """Set up an MQTT config entry."""
async def _async_setup_config_entry( async def _async_setup_config_entry(
@ -1137,7 +1136,7 @@ async def mqtt_mock_entry(
@pytest.fixture(autouse=True, scope="session") @pytest.fixture(autouse=True, scope="session")
def mock_network() -> Generator[None, None, None]: def mock_network() -> Generator[None]:
"""Mock network.""" """Mock network."""
with patch( with patch(
"homeassistant.components.network.util.ifaddr.get_adapters", "homeassistant.components.network.util.ifaddr.get_adapters",
@ -1153,7 +1152,7 @@ def mock_network() -> Generator[None, None, None]:
@pytest.fixture(autouse=True, scope="session") @pytest.fixture(autouse=True, scope="session")
def mock_get_source_ip() -> Generator[_patch, None, None]: def mock_get_source_ip() -> Generator[_patch]:
"""Mock network util's async_get_source_ip.""" """Mock network util's async_get_source_ip."""
patcher = patch( patcher = patch(
"homeassistant.components.network.util.async_get_source_ip", "homeassistant.components.network.util.async_get_source_ip",
@ -1167,7 +1166,7 @@ def mock_get_source_ip() -> Generator[_patch, None, None]:
@pytest.fixture(autouse=True, scope="session") @pytest.fixture(autouse=True, scope="session")
def translations_once() -> Generator[_patch, None, None]: def translations_once() -> Generator[_patch]:
"""Only load translations once per session.""" """Only load translations once per session."""
from homeassistant.helpers.translation import _TranslationsCacheData from homeassistant.helpers.translation import _TranslationsCacheData
@ -1186,7 +1185,7 @@ def translations_once() -> Generator[_patch, None, None]:
@pytest.fixture @pytest.fixture
def disable_translations_once( def disable_translations_once(
translations_once: _patch, translations_once: _patch,
) -> Generator[None, None, None]: ) -> Generator[None]:
"""Override loading translations once.""" """Override loading translations once."""
translations_once.stop() translations_once.stop()
yield yield
@ -1194,7 +1193,7 @@ def disable_translations_once(
@pytest.fixture @pytest.fixture
def mock_zeroconf() -> Generator[MagicMock, None, None]: def mock_zeroconf() -> Generator[MagicMock]:
"""Mock zeroconf.""" """Mock zeroconf."""
from zeroconf import DNSCache # pylint: disable=import-outside-toplevel from zeroconf import DNSCache # pylint: disable=import-outside-toplevel
@ -1210,7 +1209,7 @@ def mock_zeroconf() -> Generator[MagicMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_async_zeroconf(mock_zeroconf: MagicMock) -> Generator[MagicMock, None, None]: def mock_async_zeroconf(mock_zeroconf: MagicMock) -> Generator[MagicMock]:
"""Mock AsyncZeroconf.""" """Mock AsyncZeroconf."""
from zeroconf import DNSCache, Zeroconf # pylint: disable=import-outside-toplevel from zeroconf import DNSCache, Zeroconf # pylint: disable=import-outside-toplevel
from zeroconf.asyncio import ( # pylint: disable=import-outside-toplevel from zeroconf.asyncio import ( # pylint: disable=import-outside-toplevel
@ -1315,7 +1314,7 @@ def recorder_config() -> dict[str, Any] | None:
def recorder_db_url( def recorder_db_url(
pytestconfig: pytest.Config, pytestconfig: pytest.Config,
hass_fixture_setup: list[bool], hass_fixture_setup: list[bool],
) -> Generator[str, None, None]: ) -> Generator[str]:
"""Prepare a default database for tests and return a connection URL.""" """Prepare a default database for tests and return a connection URL."""
assert not hass_fixture_setup assert not hass_fixture_setup
@ -1368,7 +1367,7 @@ def hass_recorder(
enable_migrate_event_type_ids: bool, enable_migrate_event_type_ids: bool,
enable_migrate_entity_ids: bool, enable_migrate_entity_ids: bool,
hass_storage, hass_storage,
) -> Generator[Callable[..., HomeAssistant], None, None]: ) -> Generator[Callable[..., HomeAssistant]]:
"""Home Assistant fixture with in-memory recorder.""" """Home Assistant fixture with in-memory recorder."""
# pylint: disable-next=import-outside-toplevel # pylint: disable-next=import-outside-toplevel
from homeassistant.components import recorder from homeassistant.components import recorder
@ -1509,7 +1508,7 @@ async def async_setup_recorder_instance(
enable_migrate_context_ids: bool, enable_migrate_context_ids: bool,
enable_migrate_event_type_ids: bool, enable_migrate_event_type_ids: bool,
enable_migrate_entity_ids: bool, enable_migrate_entity_ids: bool,
) -> AsyncGenerator[RecorderInstanceGenerator, None]: ) -> AsyncGenerator[RecorderInstanceGenerator]:
"""Yield callable to setup recorder instance.""" """Yield callable to setup recorder instance."""
# pylint: disable-next=import-outside-toplevel # pylint: disable-next=import-outside-toplevel
from homeassistant.components import recorder from homeassistant.components import recorder
@ -1632,7 +1631,7 @@ async def mock_enable_bluetooth(
hass: HomeAssistant, hass: HomeAssistant,
mock_bleak_scanner_start: MagicMock, mock_bleak_scanner_start: MagicMock,
mock_bluetooth_adapters: None, mock_bluetooth_adapters: None,
) -> AsyncGenerator[None, None]: ) -> AsyncGenerator[None]:
"""Fixture to mock starting the bleak scanner.""" """Fixture to mock starting the bleak scanner."""
entry = MockConfigEntry(domain="bluetooth", unique_id="00:00:00:00:00:01") entry = MockConfigEntry(domain="bluetooth", unique_id="00:00:00:00:00:01")
entry.add_to_hass(hass) entry.add_to_hass(hass)
@ -1644,7 +1643,7 @@ async def mock_enable_bluetooth(
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def mock_bluetooth_adapters() -> Generator[None, None, None]: def mock_bluetooth_adapters() -> Generator[None]:
"""Fixture to mock bluetooth adapters.""" """Fixture to mock bluetooth adapters."""
with ( with (
patch("bluetooth_auto_recovery.recover_adapter"), patch("bluetooth_auto_recovery.recover_adapter"),
@ -1670,7 +1669,7 @@ def mock_bluetooth_adapters() -> Generator[None, None, None]:
@pytest.fixture @pytest.fixture
def mock_bleak_scanner_start() -> Generator[MagicMock, None, None]: def mock_bleak_scanner_start() -> Generator[MagicMock]:
"""Fixture to mock starting the bleak scanner.""" """Fixture to mock starting the bleak scanner."""
# Late imports to avoid loading bleak unless we need it # Late imports to avoid loading bleak unless we need it
@ -1693,7 +1692,7 @@ def mock_bleak_scanner_start() -> Generator[MagicMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_integration_frame() -> Generator[Mock, None, None]: def mock_integration_frame() -> Generator[Mock]:
"""Mock as if we're calling code from inside an integration.""" """Mock as if we're calling code from inside an integration."""
correct_frame = Mock( correct_frame = Mock(
filename="/home/paulus/homeassistant/components/hue/light.py", filename="/home/paulus/homeassistant/components/hue/light.py",

View file

@ -1,9 +1,9 @@
"""Tests for the Config Entry Flow helper.""" """Tests for the Config Entry Flow helper."""
from collections.abc import Generator
from unittest.mock import Mock, PropertyMock, patch from unittest.mock import Mock, PropertyMock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant import config_entries, data_entry_flow, setup from homeassistant import config_entries, data_entry_flow, setup
from homeassistant.config import async_process_ha_core_config from homeassistant.config import async_process_ha_core_config
@ -14,7 +14,7 @@ from tests.common import MockConfigEntry, MockModule, mock_integration, mock_pla
@pytest.fixture @pytest.fixture
def discovery_flow_conf(hass: HomeAssistant) -> Generator[dict[str, bool], None, None]: def discovery_flow_conf(hass: HomeAssistant) -> Generator[dict[str, bool]]:
"""Register a handler.""" """Register a handler."""
handler_conf = {"discovered": False} handler_conf = {"discovered": False}
@ -30,7 +30,7 @@ def discovery_flow_conf(hass: HomeAssistant) -> Generator[dict[str, bool], None,
@pytest.fixture @pytest.fixture
def webhook_flow_conf(hass: HomeAssistant) -> Generator[None, None, None]: def webhook_flow_conf(hass: HomeAssistant) -> Generator[None]:
"""Register a handler.""" """Register a handler."""
with patch.dict(config_entries.HANDLERS): with patch.dict(config_entries.HANDLERS):
config_entry_flow.register_webhook_flow("test_single", "Test Single", {}, False) config_entry_flow.register_webhook_flow("test_single", "Test Single", {}, False)

View file

@ -1,7 +1,7 @@
"""Test the bootstrapping.""" """Test the bootstrapping."""
import asyncio import asyncio
from collections.abc import Generator, Iterable from collections.abc import Iterable
import contextlib import contextlib
import glob import glob
import logging import logging
@ -11,6 +11,7 @@ from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from typing_extensions import Generator
from homeassistant import bootstrap, loader, runner from homeassistant import bootstrap, loader, runner
import homeassistant.config as config_util import homeassistant.config as config_util
@ -38,7 +39,7 @@ VERSION_PATH = os.path.join(get_test_config_dir(), config_util.VERSION_FILE)
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def disable_installed_check() -> Generator[None, None, None]: def disable_installed_check() -> Generator[None]:
"""Disable package installed check.""" """Disable package installed check."""
with patch("homeassistant.util.package.is_installed", return_value=True): with patch("homeassistant.util.package.is_installed", return_value=True):
yield yield
@ -55,7 +56,7 @@ async def apply_stop_hass(stop_hass: None) -> None:
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def mock_http_start_stop() -> Generator[None, None, None]: def mock_http_start_stop() -> Generator[None]:
"""Mock HTTP start and stop.""" """Mock HTTP start and stop."""
with ( with (
patch("homeassistant.components.http.start_http_server_and_save_config"), patch("homeassistant.components.http.start_http_server_and_save_config"),
@ -583,7 +584,7 @@ async def test_setup_after_deps_not_present(hass: HomeAssistant) -> None:
@pytest.fixture @pytest.fixture
def mock_is_virtual_env() -> Generator[Mock, None, None]: def mock_is_virtual_env() -> Generator[Mock]:
"""Mock is_virtual_env.""" """Mock is_virtual_env."""
with patch( with patch(
"homeassistant.bootstrap.is_virtual_env", return_value=False "homeassistant.bootstrap.is_virtual_env", return_value=False
@ -592,14 +593,14 @@ def mock_is_virtual_env() -> Generator[Mock, None, None]:
@pytest.fixture @pytest.fixture
def mock_enable_logging() -> Generator[Mock, None, None]: def mock_enable_logging() -> Generator[Mock]:
"""Mock enable logging.""" """Mock enable logging."""
with patch("homeassistant.bootstrap.async_enable_logging") as enable_logging: with patch("homeassistant.bootstrap.async_enable_logging") as enable_logging:
yield enable_logging yield enable_logging
@pytest.fixture @pytest.fixture
def mock_mount_local_lib_path() -> Generator[AsyncMock, None, None]: def mock_mount_local_lib_path() -> Generator[AsyncMock]:
"""Mock enable logging.""" """Mock enable logging."""
with patch( with patch(
"homeassistant.bootstrap.async_mount_local_lib_path" "homeassistant.bootstrap.async_mount_local_lib_path"
@ -608,7 +609,7 @@ def mock_mount_local_lib_path() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_process_ha_config_upgrade() -> Generator[Mock, None, None]: def mock_process_ha_config_upgrade() -> Generator[Mock]:
"""Mock enable logging.""" """Mock enable logging."""
with patch( with patch(
"homeassistant.config.process_ha_config_upgrade" "homeassistant.config.process_ha_config_upgrade"
@ -617,7 +618,7 @@ def mock_process_ha_config_upgrade() -> Generator[Mock, None, None]:
@pytest.fixture @pytest.fixture
def mock_ensure_config_exists() -> Generator[AsyncMock, None, None]: def mock_ensure_config_exists() -> Generator[AsyncMock]:
"""Mock enable logging.""" """Mock enable logging."""
with patch( with patch(
"homeassistant.config.async_ensure_config_exists", return_value=True "homeassistant.config.async_ensure_config_exists", return_value=True
@ -1179,7 +1180,7 @@ async def test_bootstrap_empty_integrations(
@pytest.fixture(name="mock_mqtt_config_flow") @pytest.fixture(name="mock_mqtt_config_flow")
def mock_mqtt_config_flow_fixture() -> Generator[None, None, None]: def mock_mqtt_config_flow_fixture() -> Generator[None]:
"""Mock MQTT config flow.""" """Mock MQTT config flow."""
class MockConfigFlow: class MockConfigFlow:

View file

@ -3,7 +3,6 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from collections.abc import Generator
from datetime import timedelta from datetime import timedelta
from functools import cached_property from functools import cached_property
import logging import logging
@ -13,6 +12,7 @@ from unittest.mock import ANY, AsyncMock, Mock, patch
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from typing_extensions import Generator
from homeassistant import config_entries, data_entry_flow, loader from homeassistant import config_entries, data_entry_flow, loader
from homeassistant.components import dhcp from homeassistant.components import dhcp
@ -53,7 +53,7 @@ from tests.common import async_get_persistent_notifications
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_handlers() -> Generator[None, None, None]: def mock_handlers() -> Generator[None]:
"""Mock config flows.""" """Mock config flows."""
class MockFlowHandler(config_entries.ConfigFlow): class MockFlowHandler(config_entries.ConfigFlow):

View file

@ -1,6 +1,5 @@
"""Test Home Assistant yaml loader.""" """Test Home Assistant yaml loader."""
from collections.abc import Generator
import importlib import importlib
import io import io
import os import os
@ -10,6 +9,7 @@ import unittest
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
import pytest import pytest
from typing_extensions import Generator
import voluptuous as vol import voluptuous as vol
import yaml as pyyaml import yaml as pyyaml
@ -604,7 +604,7 @@ async def test_loading_actual_file_with_syntax_error(
@pytest.fixture @pytest.fixture
def mock_integration_frame() -> Generator[Mock, None, None]: def mock_integration_frame() -> Generator[Mock]:
"""Mock as if we're calling code from inside an integration.""" """Mock as if we're calling code from inside an integration."""
correct_frame = Mock( correct_frame = Mock(
filename="/home/paulus/homeassistant/components/hue/light.py", filename="/home/paulus/homeassistant/components/hue/light.py",