Fix Generator annotations in tests (2) (#119019)
This commit is contained in:
parent
27e8a4ed6f
commit
7195a21126
8 changed files with 19 additions and 21 deletions
|
@ -1,9 +1,9 @@
|
||||||
"""The tests for the notify demo platform."""
|
"""The tests for the notify demo platform."""
|
||||||
|
|
||||||
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 import notify
|
from homeassistant.components import notify
|
||||||
from homeassistant.components.demo import DOMAIN
|
from homeassistant.components.demo import DOMAIN
|
||||||
|
@ -16,7 +16,7 @@ from tests.common import MockConfigEntry, async_capture_events
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def notify_only() -> Generator[None, None]:
|
def notify_only() -> Generator[None]:
|
||||||
"""Enable only the notify platform."""
|
"""Enable only the notify platform."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM",
|
"homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM",
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"""Fixtures for tests."""
|
"""Fixtures for tests."""
|
||||||
|
|
||||||
from collections.abc import Generator
|
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from requests_mock import Mocker
|
from requests_mock import Mocker
|
||||||
|
from typing_extensions import Generator
|
||||||
|
|
||||||
from homeassistant.components.ecobee import ECOBEE_API_KEY, ECOBEE_REFRESH_TOKEN
|
from homeassistant.components.ecobee import ECOBEE_API_KEY, ECOBEE_REFRESH_TOKEN
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ def requests_mock_fixture(requests_mock: Mocker) -> None:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_ecobee() -> Generator[None, MagicMock]:
|
def mock_ecobee() -> Generator[MagicMock]:
|
||||||
"""Mock an Ecobee object."""
|
"""Mock an Ecobee object."""
|
||||||
ecobee = MagicMock()
|
ecobee = MagicMock()
|
||||||
ecobee.request_pin.return_value = True
|
ecobee.request_pin.return_value = True
|
||||||
|
|
|
@ -24,9 +24,7 @@ def is_allowed() -> bool:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_is_allowed_path(
|
def mock_is_allowed_path(hass: HomeAssistant, is_allowed: bool) -> Generator[MagicMock]:
|
||||||
hass: HomeAssistant, is_allowed: bool
|
|
||||||
) -> Generator[None, MagicMock]:
|
|
||||||
"""Mock is_allowed_path method."""
|
"""Mock is_allowed_path method."""
|
||||||
with patch.object(
|
with patch.object(
|
||||||
hass.config, "is_allowed_path", return_value=is_allowed
|
hass.config, "is_allowed_path", return_value=is_allowed
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Common fixtures for the Gardena Bluetooth tests."""
|
"""Common fixtures for the Gardena Bluetooth tests."""
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Callable, Coroutine
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ def mock_read_char_raw():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def scan_step(
|
async def scan_step(
|
||||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
) -> Generator[None, None, Callable[[], Awaitable[None]]]:
|
) -> Callable[[], Coroutine[Any, Any, None]]:
|
||||||
"""Step system time forward."""
|
"""Step system time forward."""
|
||||||
|
|
||||||
freezer.move_to("2023-01-01T01:00:00Z")
|
freezer.move_to("2023-01-01T01:00:00Z")
|
||||||
|
|
||||||
async def delay():
|
async def delay() -> None:
|
||||||
"""Trigger delay in system."""
|
"""Trigger delay in system."""
|
||||||
freezer.tick(delta=SCAN_INTERVAL)
|
freezer.tick(delta=SCAN_INTERVAL)
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
|
@ -69,7 +69,7 @@ async def scan_step(
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def mock_client(
|
def mock_client(
|
||||||
enable_bluetooth: None, scan_step, mock_read_char_raw: dict[str, Any]
|
enable_bluetooth: None, scan_step, mock_read_char_raw: dict[str, Any]
|
||||||
) -> None:
|
) -> Generator[Mock]:
|
||||||
"""Auto mock bluetooth."""
|
"""Auto mock bluetooth."""
|
||||||
|
|
||||||
client = Mock(spec_set=Client)
|
client = Mock(spec_set=Client)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""The tests for the MQTT component."""
|
"""The tests for the MQTT component."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Generator
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
@ -16,6 +15,7 @@ from unittest.mock import ANY, MagicMock, Mock, call, mock_open, patch
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import paho.mqtt.client as paho_mqtt
|
import paho.mqtt.client as paho_mqtt
|
||||||
import pytest
|
import pytest
|
||||||
|
from typing_extensions import Generator
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
|
@ -118,7 +118,7 @@ def record_calls(recorded_calls: list[ReceiveMessage]) -> MessageCallbackType:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client_debug_log() -> Generator[None, None]:
|
def client_debug_log() -> Generator[None]:
|
||||||
"""Set the mqtt client log level to DEBUG."""
|
"""Set the mqtt client log level to DEBUG."""
|
||||||
logger = logging.getLogger("mqtt_client_tests_debug")
|
logger = logging.getLogger("mqtt_client_tests_debug")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
"""The tests for the JSON MQTT device tracker platform."""
|
"""The tests for the JSON MQTT device tracker platform."""
|
||||||
|
|
||||||
from collections.abc import Generator
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from typing_extensions import AsyncGenerator
|
||||||
|
|
||||||
from homeassistant.components.device_tracker.legacy import (
|
from homeassistant.components.device_tracker.legacy import (
|
||||||
DOMAIN as DT_DOMAIN,
|
DOMAIN as DT_DOMAIN,
|
||||||
|
@ -34,7 +34,7 @@ LOCATION_MESSAGE_INCOMPLETE = {"longitude": 2.0}
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def setup_comp(
|
async def setup_comp(
|
||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||||
) -> Generator[None, None, None]:
|
) -> AsyncGenerator[None]:
|
||||||
"""Initialize components."""
|
"""Initialize components."""
|
||||||
yaml_devices = hass.config.path(YAML_DEVICES)
|
yaml_devices = hass.config.path(YAML_DEVICES)
|
||||||
yield
|
yield
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"""Configure tests for the OpenSky integration."""
|
"""Configure tests for the OpenSky integration."""
|
||||||
|
|
||||||
from collections.abc import Generator
|
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from python_opensky import StatesResponse
|
from python_opensky import StatesResponse
|
||||||
|
from typing_extensions import AsyncGenerator, Generator
|
||||||
|
|
||||||
from homeassistant.components.opensky.const import (
|
from homeassistant.components.opensky.const import (
|
||||||
CONF_ALTITUDE,
|
CONF_ALTITUDE,
|
||||||
|
@ -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.opensky.async_setup_entry",
|
"homeassistant.components.opensky.async_setup_entry",
|
||||||
|
@ -87,7 +87,7 @@ def mock_config_entry_authenticated() -> MockConfigEntry:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def opensky_client() -> Generator[AsyncMock, None, None]:
|
async def opensky_client() -> AsyncGenerator[AsyncMock]:
|
||||||
"""Mock the OpenSky client."""
|
"""Mock the OpenSky client."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
"""Tests for the Rain Bird config flow."""
|
"""Tests for the Rain Bird config flow."""
|
||||||
|
|
||||||
from collections.abc import Generator
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from typing_extensions import AsyncGenerator
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.rainbird import DOMAIN
|
from homeassistant.components.rainbird import DOMAIN
|
||||||
|
@ -46,7 +46,7 @@ async def config_entry_data() -> None:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def mock_setup() -> Generator[Mock, None, None]:
|
async def mock_setup() -> AsyncGenerator[AsyncMock]:
|
||||||
"""Fixture for patching out integration setup."""
|
"""Fixture for patching out integration setup."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
|
Loading…
Add table
Reference in a new issue