Use TypeVar defaults for Generator (#120921)

* Use TypeVar defaults for Generator

* Code review
This commit is contained in:
Marc Mueller 2024-07-01 14:02:54 +02:00 committed by GitHub
parent 4cc414fbf8
commit 414525503c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 25 additions and 27 deletions

View File

@ -1,7 +1,7 @@
"""Common fixtures for the APsystems Local API tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch
from APsystemsEZ1 import ReturnDeviceInfo, ReturnOutputData
import pytest
@ -23,7 +23,7 @@ def mock_setup_entry() -> Generator[AsyncMock]:
@pytest.fixture
def mock_apsystems() -> Generator[AsyncMock, None, None]:
def mock_apsystems() -> Generator[MagicMock]:
"""Mock APSystems lib."""
with (
patch(

View File

@ -2,7 +2,7 @@
from collections.abc import Generator
from datetime import datetime
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch
from aioaquacell import AquacellApi, Softener
import pytest
@ -19,7 +19,7 @@ from tests.common import MockConfigEntry, load_json_array_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.aquacell.async_setup_entry", return_value=True
@ -28,7 +28,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture
def mock_aquacell_api() -> Generator[AsyncMock, None, None]:
def mock_aquacell_api() -> Generator[MagicMock]:
"""Build a fixture for the Aquacell API that authenticates successfully and returns a single softener."""
with (
patch(

View File

@ -2,7 +2,7 @@
from collections.abc import Generator
from datetime import UTC, datetime
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch
from brother import BrotherSensors
import pytest
@ -87,7 +87,7 @@ def mock_setup_entry() -> Generator[AsyncMock]:
@pytest.fixture
def mock_unload_entry() -> Generator[AsyncMock, None, None]:
def mock_unload_entry() -> Generator[AsyncMock]:
"""Override async_unload_entry."""
with patch(
"homeassistant.components.brother.async_unload_entry", return_value=True
@ -96,7 +96,7 @@ def mock_unload_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture
def mock_brother_client() -> Generator[AsyncMock, None, None]:
def mock_brother_client() -> Generator[MagicMock]:
"""Mock Brother client."""
with (
patch("homeassistant.components.brother.Brother", autospec=True) as mock_client,

View File

@ -16,9 +16,7 @@ pytestmark = [pytest.mark.usefixtures("init_integration")]
@pytest.fixture
def mock_device_execute_response(
data: dict[str, Any],
) -> Generator[dict[str, Any], None, None]:
def mock_device_execute_response(data: dict[str, Any]) -> Generator[dict[str, Any]]:
"""Mock the device execute function response."""
response = {

View File

@ -1,6 +1,6 @@
"""Test the Everything but the Kitchen Sink config flow."""
from collections.abc import AsyncGenerator
from collections.abc import Generator
from unittest.mock import patch
import pytest
@ -15,7 +15,7 @@ from tests.common import MockConfigEntry
@pytest.fixture
async def no_platforms() -> AsyncGenerator[None, None]:
def no_platforms() -> Generator[None]:
"""Don't enable any platforms."""
with patch(
"homeassistant.components.kitchen_sink.COMPONENTS_WITH_DEMO_PLATFORM",

View File

@ -1,7 +1,7 @@
"""Fixtures for Music Player Daemon integration tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
@ -22,7 +22,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry."""
with patch(
"homeassistant.components.mpd.async_setup_entry", return_value=True
@ -31,7 +31,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture
def mock_mpd_client() -> Generator[AsyncMock, None, None]:
def mock_mpd_client() -> Generator[MagicMock]:
"""Return a mock for Music Player Daemon client."""
with patch(

View File

@ -14,7 +14,7 @@ from tests.common import MockConfigEntry
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.otp.async_setup_entry", return_value=True
@ -23,7 +23,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture
def mock_pyotp() -> Generator[MagicMock, None, None]:
def mock_pyotp() -> Generator[MagicMock]:
"""Mock a pyotp."""
with (
patch(

View File

@ -1,7 +1,7 @@
"""Fixtures for pyLoad integration tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch
from pyloadapi.types import LoginResponse, StatusServerResponse
import pytest
@ -72,7 +72,7 @@ def pyload_config() -> ConfigType:
@pytest.fixture
def mock_pyloadapi() -> Generator[AsyncMock, None, None]:
def mock_pyloadapi() -> Generator[MagicMock]:
"""Mock PyLoadAPI."""
with (
patch(

View File

@ -1,6 +1,6 @@
"""The tests for the button component."""
from collections.abc import AsyncGenerator
from collections.abc import Generator
from unittest.mock import AsyncMock, call, patch
from pyloadapi import CannotConnect, InvalidAuth
@ -26,7 +26,7 @@ API_CALL = {
@pytest.fixture(autouse=True)
async def button_only() -> AsyncGenerator[None, None]:
def button_only() -> Generator[None]:
"""Enable only the button platform."""
with patch(
"homeassistant.components.pyload.PLATFORMS",

View File

@ -1,6 +1,6 @@
"""Tests for the pyLoad Sensors."""
from collections.abc import AsyncGenerator
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from freezegun.api import FrozenDateTimeFactory
@ -22,7 +22,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_plat
@pytest.fixture(autouse=True)
async def sensor_only() -> AsyncGenerator[None, None]:
def sensor_only() -> Generator[None]:
"""Enable only the sensor platform."""
with patch(
"homeassistant.components.pyload.PLATFORMS",

View File

@ -1,6 +1,6 @@
"""Tests for the pyLoad Switches."""
from collections.abc import AsyncGenerator
from collections.abc import Generator
from unittest.mock import AsyncMock, call, patch
from pyloadapi import CannotConnect, InvalidAuth
@ -38,7 +38,7 @@ API_CALL = {
@pytest.fixture(autouse=True)
async def switch_only() -> AsyncGenerator[None, None]:
def switch_only() -> Generator[None]:
"""Enable only the switch platform."""
with patch(
"homeassistant.components.pyload.PLATFORMS",

View File

@ -60,7 +60,7 @@ def mock_solarlog_connector():
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.solarlog.async_setup_entry", return_value=True