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

View file

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

View file

@ -2,7 +2,7 @@
from collections.abc import Generator 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, MagicMock, patch
from brother import BrotherSensors from brother import BrotherSensors
import pytest import pytest
@ -87,7 +87,7 @@ def mock_setup_entry() -> Generator[AsyncMock]:
@pytest.fixture @pytest.fixture
def mock_unload_entry() -> Generator[AsyncMock, None, None]: def mock_unload_entry() -> Generator[AsyncMock]:
"""Override async_unload_entry.""" """Override async_unload_entry."""
with patch( with patch(
"homeassistant.components.brother.async_unload_entry", return_value=True "homeassistant.components.brother.async_unload_entry", return_value=True
@ -96,7 +96,7 @@ def mock_unload_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_brother_client() -> Generator[AsyncMock, None, None]: def mock_brother_client() -> Generator[MagicMock]:
"""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

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

View file

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

View file

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

View file

@ -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.otp.async_setup_entry", return_value=True "homeassistant.components.otp.async_setup_entry", return_value=True
@ -23,7 +23,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture @pytest.fixture
def mock_pyotp() -> Generator[MagicMock, None, None]: def mock_pyotp() -> Generator[MagicMock]:
"""Mock a pyotp.""" """Mock a pyotp."""
with ( with (
patch( patch(

View file

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

View file

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

View file

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

View file

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

View file

@ -60,7 +60,7 @@ def mock_solarlog_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.solarlog.async_setup_entry", return_value=True "homeassistant.components.solarlog.async_setup_entry", return_value=True