Fix Generator annotations in tests (2) (#119019)

This commit is contained in:
Marc Mueller 2024-06-07 08:34:38 +02:00 committed by GitHub
parent 27e8a4ed6f
commit 7195a21126
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 19 additions and 21 deletions

View file

@ -1,9 +1,9 @@
"""The tests for the notify demo platform."""
from collections.abc import Generator
from unittest.mock import patch
import pytest
from typing_extensions import Generator
from homeassistant.components import notify
from homeassistant.components.demo import DOMAIN
@ -16,7 +16,7 @@ from tests.common import MockConfigEntry, async_capture_events
@pytest.fixture
def notify_only() -> Generator[None, None]:
def notify_only() -> Generator[None]:
"""Enable only the notify platform."""
with patch(
"homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM",

View file

@ -1,10 +1,10 @@
"""Fixtures for tests."""
from collections.abc import Generator
from unittest.mock import MagicMock, patch
import pytest
from requests_mock import Mocker
from typing_extensions import Generator
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
def mock_ecobee() -> Generator[None, MagicMock]:
def mock_ecobee() -> Generator[MagicMock]:
"""Mock an Ecobee object."""
ecobee = MagicMock()
ecobee.request_pin.return_value = True

View file

@ -24,9 +24,7 @@ def is_allowed() -> bool:
@pytest.fixture
def mock_is_allowed_path(
hass: HomeAssistant, is_allowed: bool
) -> Generator[None, MagicMock]:
def mock_is_allowed_path(hass: HomeAssistant, is_allowed: bool) -> Generator[MagicMock]:
"""Mock is_allowed_path method."""
with patch.object(
hass.config, "is_allowed_path", return_value=is_allowed

View file

@ -1,6 +1,6 @@
"""Common fixtures for the Gardena Bluetooth tests."""
from collections.abc import Awaitable, Callable
from collections.abc import Callable, Coroutine
from typing import Any
from unittest.mock import AsyncMock, Mock, patch
@ -52,12 +52,12 @@ def mock_read_char_raw():
@pytest.fixture
async def scan_step(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> Generator[None, None, Callable[[], Awaitable[None]]]:
) -> Callable[[], Coroutine[Any, Any, None]]:
"""Step system time forward."""
freezer.move_to("2023-01-01T01:00:00Z")
async def delay():
async def delay() -> None:
"""Trigger delay in system."""
freezer.tick(delta=SCAN_INTERVAL)
async_fire_time_changed(hass)
@ -69,7 +69,7 @@ async def scan_step(
@pytest.fixture(autouse=True)
def mock_client(
enable_bluetooth: None, scan_step, mock_read_char_raw: dict[str, Any]
) -> None:
) -> Generator[Mock]:
"""Auto mock bluetooth."""
client = Mock(spec_set=Client)

View file

@ -1,7 +1,6 @@
"""The tests for the MQTT component."""
import asyncio
from collections.abc import Generator
from copy import deepcopy
from datetime import datetime, timedelta
from functools import partial
@ -16,6 +15,7 @@ from unittest.mock import ANY, MagicMock, Mock, call, mock_open, patch
from freezegun.api import FrozenDateTimeFactory
import paho.mqtt.client as paho_mqtt
import pytest
from typing_extensions import Generator
import voluptuous as vol
from homeassistant.components import mqtt
@ -118,7 +118,7 @@ def record_calls(recorded_calls: list[ReceiveMessage]) -> MessageCallbackType:
@pytest.fixture
def client_debug_log() -> Generator[None, None]:
def client_debug_log() -> Generator[None]:
"""Set the mqtt client log level to DEBUG."""
logger = logging.getLogger("mqtt_client_tests_debug")
logger.setLevel(logging.DEBUG)

View file

@ -1,12 +1,12 @@
"""The tests for the JSON MQTT device tracker platform."""
from collections.abc import Generator
import json
import logging
import os
from unittest.mock import patch
import pytest
from typing_extensions import AsyncGenerator
from homeassistant.components.device_tracker.legacy import (
DOMAIN as DT_DOMAIN,
@ -34,7 +34,7 @@ LOCATION_MESSAGE_INCOMPLETE = {"longitude": 2.0}
@pytest.fixture(autouse=True)
async def setup_comp(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> Generator[None, None, None]:
) -> AsyncGenerator[None]:
"""Initialize components."""
yaml_devices = hass.config.path(YAML_DEVICES)
yield

View file

@ -1,10 +1,10 @@
"""Configure tests for the OpenSky integration."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
from python_opensky import StatesResponse
from typing_extensions import AsyncGenerator, Generator
from homeassistant.components.opensky.const import (
CONF_ALTITUDE,
@ -23,7 +23,7 @@ from tests.common import MockConfigEntry, load_json_object_fixture
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.opensky.async_setup_entry",
@ -87,7 +87,7 @@ def mock_config_entry_authenticated() -> MockConfigEntry:
@pytest.fixture
async def opensky_client() -> Generator[AsyncMock, None, None]:
async def opensky_client() -> AsyncGenerator[AsyncMock]:
"""Mock the OpenSky client."""
with (
patch(

View file

@ -1,11 +1,11 @@
"""Tests for the Rain Bird config flow."""
from collections.abc import Generator
from http import HTTPStatus
from typing import Any
from unittest.mock import Mock, patch
from unittest.mock import AsyncMock, Mock, patch
import pytest
from typing_extensions import AsyncGenerator
from homeassistant import config_entries
from homeassistant.components.rainbird import DOMAIN
@ -46,7 +46,7 @@ async def config_entry_data() -> None:
@pytest.fixture(autouse=True)
async def mock_setup() -> Generator[Mock, None, None]:
async def mock_setup() -> AsyncGenerator[AsyncMock]:
"""Fixture for patching out integration setup."""
with patch(