From 69a46d400253fad3d4457d5febd2c4e7042d16b6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:21:19 +0200 Subject: [PATCH] Adjust pylint plugin for components fixtures (#90217) * Adjust pylint plugin for components fixtures * Adjust components * Use MagicMock * Adjust * Use None --- pylint/plugins/hass_enforce_type_hints.py | 1 + tests/components/airzone/test_sensor.py | 4 +--- tests/components/conftest.py | 12 ++++++------ tests/components/goalzero/test_sensor.py | 3 +-- tests/components/gree/test_switch.py | 11 ++++++----- tests/components/homekit_controller/test_sensor.py | 4 ++-- tests/components/kostal_plenticore/test_number.py | 11 +++++------ tests/components/litterrobot/test_binary_sensor.py | 4 ++-- tests/components/oralb/test_sensor.py | 7 +++++-- tests/components/powerwall/test_sensor.py | 4 +++- tests/components/qnap_qsw/test_binary_sensor.py | 4 +--- tests/components/qnap_qsw/test_sensor.py | 4 +--- tests/components/radarr/test_sensor.py | 3 +-- tests/components/sensibo/test_binary_sensor.py | 4 ++-- tests/components/sensibo/test_climate.py | 12 ++++++------ tests/components/sensibo/test_number.py | 6 +++--- tests/components/sensibo/test_sensor.py | 4 ++-- tests/components/sonarr/test_sensor.py | 4 ++-- tests/components/switchbot/test_sensor.py | 5 ++++- tests/components/unifi/test_sensor.py | 4 ++-- tests/components/unifiprotect/test_sensor.py | 7 +++---- 21 files changed, 59 insertions(+), 59 deletions(-) diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index f25b8db84af..ba0a511c571 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -104,6 +104,7 @@ _TEST_FIXTURES: dict[str, list[str] | str] = { "enable_statistics": "bool", "enable_schema_validation": "bool", "entity_registry": "EntityRegistry", + "entity_registry_enabled_by_default": "None", "freezer": "FrozenDateTimeFactory", "hass_access_token": "str", "hass_admin_credential": "Credentials", diff --git a/tests/components/airzone/test_sensor.py b/tests/components/airzone/test_sensor.py index 151ee7c42fb..1e7d335a46f 100644 --- a/tests/components/airzone/test_sensor.py +++ b/tests/components/airzone/test_sensor.py @@ -1,14 +1,12 @@ """The sensor tests for the Airzone platform.""" -from unittest.mock import AsyncMock - from homeassistant.core import HomeAssistant from .util import async_init_integration async def test_airzone_create_sensors( - hass: HomeAssistant, entity_registry_enabled_by_default: AsyncMock + hass: HomeAssistant, entity_registry_enabled_by_default: None ) -> None: """Test creation of sensors.""" diff --git a/tests/components/conftest.py b/tests/components/conftest.py index 6cad53aea72..d57ef9768a0 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -1,12 +1,12 @@ """Fixtures for component testing.""" from collections.abc import Generator -from unittest.mock import AsyncMock, patch +from unittest.mock import patch import pytest @pytest.fixture(scope="session", autouse=True) -def patch_zeroconf_multiple_catcher(): +def patch_zeroconf_multiple_catcher() -> Generator[None, None, None]: """Patch zeroconf wrapper that detects if multiple instances are used.""" with patch( "homeassistant.components.zeroconf.install_multiple_zeroconf_catcher", @@ -16,7 +16,7 @@ def patch_zeroconf_multiple_catcher(): @pytest.fixture(autouse=True) -def prevent_io(): +def prevent_io() -> Generator[None, None, None]: """Fixture to prevent certain I/O from happening.""" with patch( "homeassistant.components.http.ban.load_yaml_config_file", @@ -25,10 +25,10 @@ def prevent_io(): @pytest.fixture -def entity_registry_enabled_by_default() -> Generator[AsyncMock, None, None]: +def entity_registry_enabled_by_default() -> Generator[None, None, None]: """Test fixture that ensures all entities are enabled in the registry.""" with patch( "homeassistant.helpers.entity.Entity.entity_registry_enabled_default", return_value=True, - ) as mock_entity_registry_enabled_by_default: - yield mock_entity_registry_enabled_by_default + ): + yield diff --git a/tests/components/goalzero/test_sensor.py b/tests/components/goalzero/test_sensor.py index 5c979b7d84d..47fbb29915b 100644 --- a/tests/components/goalzero/test_sensor.py +++ b/tests/components/goalzero/test_sensor.py @@ -1,5 +1,4 @@ """Sensor tests for the Goalzero integration.""" -from unittest.mock import AsyncMock from homeassistant.components.goalzero.const import DEFAULT_NAME from homeassistant.components.sensor import ( @@ -29,7 +28,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker async def test_sensors( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, ) -> None: """Test we get sensor data.""" await async_init_integration(hass, aioclient_mock) diff --git a/tests/components/gree/test_switch.py b/tests/components/gree/test_switch.py index 85b9a41caff..58c740b8591 100644 --- a/tests/components/gree/test_switch.py +++ b/tests/components/gree/test_switch.py @@ -1,4 +1,5 @@ """Tests for gree component.""" + from greeclimate.exceptions import DeviceTimeoutError import pytest @@ -54,7 +55,7 @@ async def test_health_mode_disabled_by_default(hass): ], ) async def test_send_switch_on( - hass: HomeAssistant, entity, entity_registry_enabled_by_default + hass: HomeAssistant, entity, entity_registry_enabled_by_default: None ) -> None: """Test for sending power on command to the device.""" await async_setup_gree(hass) @@ -82,7 +83,7 @@ async def test_send_switch_on( ], ) async def test_send_switch_on_device_timeout( - hass: HomeAssistant, device, entity, entity_registry_enabled_by_default + hass: HomeAssistant, device, entity, entity_registry_enabled_by_default: None ) -> None: """Test for sending power on command to the device with a device timeout.""" device().push_state_update.side_effect = DeviceTimeoutError @@ -112,7 +113,7 @@ async def test_send_switch_on_device_timeout( ], ) async def test_send_switch_off( - hass: HomeAssistant, entity, entity_registry_enabled_by_default + hass: HomeAssistant, entity, entity_registry_enabled_by_default: None ) -> None: """Test for sending power on command to the device.""" await async_setup_gree(hass) @@ -140,7 +141,7 @@ async def test_send_switch_off( ], ) async def test_send_switch_toggle( - hass: HomeAssistant, entity, entity_registry_enabled_by_default + hass: HomeAssistant, entity, entity_registry_enabled_by_default: None ) -> None: """Test for sending power on command to the device.""" await async_setup_gree(hass) @@ -193,7 +194,7 @@ async def test_send_switch_toggle( ], ) async def test_entity_name( - hass: HomeAssistant, entity, name, entity_registry_enabled_by_default + hass: HomeAssistant, entity, name, entity_registry_enabled_by_default: None ) -> None: """Test for name property.""" await async_setup_gree(hass) diff --git a/tests/components/homekit_controller/test_sensor.py b/tests/components/homekit_controller/test_sensor.py index c801ab91f74..6c9ad008703 100644 --- a/tests/components/homekit_controller/test_sensor.py +++ b/tests/components/homekit_controller/test_sensor.py @@ -364,7 +364,7 @@ def test_thread_status_to_str() -> None: async def test_rssi_sensor( hass: HomeAssistant, utcnow, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, enable_bluetooth: None, ) -> None: """Test an rssi sensor.""" @@ -389,7 +389,7 @@ async def test_rssi_sensor( async def test_migrate_rssi_sensor_unique_id( hass: HomeAssistant, utcnow, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, enable_bluetooth: None, ) -> None: """Test an rssi sensor unique id migration.""" diff --git a/tests/components/kostal_plenticore/test_number.py b/tests/components/kostal_plenticore/test_number.py index a1eb778a1c0..beabd8fe669 100644 --- a/tests/components/kostal_plenticore/test_number.py +++ b/tests/components/kostal_plenticore/test_number.py @@ -1,5 +1,4 @@ """Test Kostal Plenticore number.""" - from collections.abc import Generator from datetime import timedelta from unittest.mock import patch @@ -90,7 +89,7 @@ async def test_setup_all_entries( mock_config_entry: MockConfigEntry, mock_plenticore_client: ApiClient, mock_get_setting_values: list, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, ) -> None: """Test if all available entries are setup.""" @@ -109,7 +108,7 @@ async def test_setup_no_entries( mock_config_entry: MockConfigEntry, mock_plenticore_client: ApiClient, mock_get_setting_values: list, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, ) -> None: """Test that no entries are setup if Plenticore does not provide data.""" @@ -130,7 +129,7 @@ async def test_number_has_value( mock_config_entry: MockConfigEntry, mock_plenticore_client: ApiClient, mock_get_setting_values: list, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, ) -> None: """Test if number has a value if data is provided on update.""" @@ -155,7 +154,7 @@ async def test_number_is_unavailable( mock_config_entry: MockConfigEntry, mock_plenticore_client: ApiClient, mock_get_setting_values: list, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, ) -> None: """Test if number is unavailable if no data is provided on update.""" @@ -176,7 +175,7 @@ async def test_set_value( mock_config_entry: MockConfigEntry, mock_plenticore_client: ApiClient, mock_get_setting_values: list, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, ) -> None: """Test if a new value could be set.""" diff --git a/tests/components/litterrobot/test_binary_sensor.py b/tests/components/litterrobot/test_binary_sensor.py index cbcdd447760..c6cfbff907e 100644 --- a/tests/components/litterrobot/test_binary_sensor.py +++ b/tests/components/litterrobot/test_binary_sensor.py @@ -1,5 +1,5 @@ """Test the Litter-Robot binary sensor entity.""" -from unittest.mock import AsyncMock, MagicMock +from unittest.mock import MagicMock import pytest @@ -17,7 +17,7 @@ from .conftest import setup_integration async def test_binary_sensors( hass: HomeAssistant, mock_account: MagicMock, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, ) -> None: """Tests binary sensors.""" await setup_integration(hass, mock_account, PLATFORM_DOMAIN) diff --git a/tests/components/oralb/test_sensor.py b/tests/components/oralb/test_sensor.py index d0772301400..8c7bacce234 100644 --- a/tests/components/oralb/test_sensor.py +++ b/tests/components/oralb/test_sensor.py @@ -1,4 +1,5 @@ """Test the OralB sensors.""" + from homeassistant.components.oralb.const import DOMAIN from homeassistant.const import ATTR_FRIENDLY_NAME from homeassistant.core import HomeAssistant @@ -16,7 +17,9 @@ from tests.components.bluetooth import ( ) -async def test_sensors(hass: HomeAssistant, entity_registry_enabled_by_default) -> None: +async def test_sensors( + hass: HomeAssistant, entity_registry_enabled_by_default: None +) -> None: """Test setting up creates the sensors.""" entry = MockConfigEntry( domain=DOMAIN, @@ -47,7 +50,7 @@ async def test_sensors(hass: HomeAssistant, entity_registry_enabled_by_default) async def test_sensors_io_series_4( - hass: HomeAssistant, entity_registry_enabled_by_default + hass: HomeAssistant, entity_registry_enabled_by_default: None ) -> None: """Test setting up creates the sensors with an io series 4.""" entry = MockConfigEntry( diff --git a/tests/components/powerwall/test_sensor.py b/tests/components/powerwall/test_sensor.py index c72a3ff6fed..a0d4d7f9e96 100644 --- a/tests/components/powerwall/test_sensor.py +++ b/tests/components/powerwall/test_sensor.py @@ -20,7 +20,9 @@ from .mocks import _mock_powerwall_with_fixtures from tests.common import MockConfigEntry -async def test_sensors(hass: HomeAssistant, entity_registry_enabled_by_default) -> None: +async def test_sensors( + hass: HomeAssistant, entity_registry_enabled_by_default: None +) -> None: """Test creation of the sensors.""" mock_powerwall = await _mock_powerwall_with_fixtures(hass) diff --git a/tests/components/qnap_qsw/test_binary_sensor.py b/tests/components/qnap_qsw/test_binary_sensor.py index f007f799349..47eb6a00ba7 100644 --- a/tests/components/qnap_qsw/test_binary_sensor.py +++ b/tests/components/qnap_qsw/test_binary_sensor.py @@ -1,7 +1,5 @@ """The binary sensor tests for the QNAP QSW platform.""" -from unittest.mock import AsyncMock - from homeassistant.components.qnap_qsw.const import ATTR_MESSAGE from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant @@ -12,7 +10,7 @@ from .util import async_init_integration async def test_qnap_qsw_create_binary_sensors( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, entity_registry: er.EntityRegistry, ) -> None: """Test creation of binary sensors.""" diff --git a/tests/components/qnap_qsw/test_sensor.py b/tests/components/qnap_qsw/test_sensor.py index 902f65d9258..673a607acdf 100644 --- a/tests/components/qnap_qsw/test_sensor.py +++ b/tests/components/qnap_qsw/test_sensor.py @@ -1,7 +1,5 @@ """The sensor tests for the QNAP QSW platform.""" -from unittest.mock import AsyncMock - from homeassistant.components.qnap_qsw.const import ATTR_MAX from homeassistant.core import HomeAssistant @@ -10,7 +8,7 @@ from .util import async_init_integration async def test_qnap_qsw_create_sensors( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, ) -> None: """Test creation of sensors.""" diff --git a/tests/components/radarr/test_sensor.py b/tests/components/radarr/test_sensor.py index 5c4ae3ea348..d3dde74dcbf 100644 --- a/tests/components/radarr/test_sensor.py +++ b/tests/components/radarr/test_sensor.py @@ -1,5 +1,4 @@ """The tests for Radarr sensor platform.""" -from unittest.mock import AsyncMock from homeassistant.components.sensor import SensorDeviceClass from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_UNIT_OF_MEASUREMENT @@ -13,7 +12,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker async def test_sensors( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, ) -> None: """Test for successfully setting up the Radarr platform.""" await setup_integration(hass, aioclient_mock) diff --git a/tests/components/sensibo/test_binary_sensor.py b/tests/components/sensibo/test_binary_sensor.py index 78d643eb749..d99dd2e8715 100644 --- a/tests/components/sensibo/test_binary_sensor.py +++ b/tests/components/sensibo/test_binary_sensor.py @@ -2,7 +2,7 @@ from __future__ import annotations from datetime import timedelta -from unittest.mock import AsyncMock, patch +from unittest.mock import patch from pysensibo.model import SensiboData import pytest @@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed async def test_binary_sensor( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData, diff --git a/tests/components/sensibo/test_climate.py b/tests/components/sensibo/test_climate.py index 268abc5f89b..be5b539fa06 100644 --- a/tests/components/sensibo/test_climate.py +++ b/tests/components/sensibo/test_climate.py @@ -2,7 +2,7 @@ from __future__ import annotations from datetime import datetime, timedelta -from unittest.mock import AsyncMock, patch +from unittest.mock import patch from pysensibo.model import SensiboData import pytest @@ -720,7 +720,7 @@ async def test_climate_no_fan_no_swing( async def test_climate_set_timer( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData, @@ -824,7 +824,7 @@ async def test_climate_set_timer( async def test_climate_pure_boost( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData, @@ -928,7 +928,7 @@ async def test_climate_pure_boost( async def test_climate_climate_react( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData, @@ -1091,7 +1091,7 @@ async def test_climate_climate_react( async def test_climate_climate_react_fahrenheit( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData, @@ -1234,7 +1234,7 @@ async def test_climate_climate_react_fahrenheit( async def test_climate_full_ac_state( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData, diff --git a/tests/components/sensibo/test_number.py b/tests/components/sensibo/test_number.py index c7a6a18616b..1f968355960 100644 --- a/tests/components/sensibo/test_number.py +++ b/tests/components/sensibo/test_number.py @@ -2,7 +2,7 @@ from __future__ import annotations from datetime import timedelta -from unittest.mock import AsyncMock, patch +from unittest.mock import patch from pysensibo.model import SensiboData import pytest @@ -23,7 +23,7 @@ from tests.common import async_fire_time_changed async def test_number( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData, @@ -53,7 +53,7 @@ async def test_number( async def test_number_set_value( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, get_data: SensiboData, ) -> None: diff --git a/tests/components/sensibo/test_sensor.py b/tests/components/sensibo/test_sensor.py index f84c7cf9005..8d3f705215c 100644 --- a/tests/components/sensibo/test_sensor.py +++ b/tests/components/sensibo/test_sensor.py @@ -2,7 +2,7 @@ from __future__ import annotations from datetime import timedelta -from unittest.mock import AsyncMock, patch +from unittest.mock import patch from pysensibo.model import SensiboData import pytest @@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed async def test_sensor( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, load_int: ConfigEntry, monkeypatch: pytest.pytest.MonkeyPatch, get_data: SensiboData, diff --git a/tests/components/sonarr/test_sensor.py b/tests/components/sonarr/test_sensor.py index c00236c54e6..9f27e593657 100644 --- a/tests/components/sonarr/test_sensor.py +++ b/tests/components/sonarr/test_sensor.py @@ -1,6 +1,6 @@ """Tests for the Sonarr sensor platform.""" from datetime import timedelta -from unittest.mock import AsyncMock, MagicMock, patch +from unittest.mock import MagicMock, patch from aiopyarr import ArrException import pytest @@ -25,7 +25,7 @@ async def test_sensors( hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_sonarr: MagicMock, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, ) -> None: """Test the creation and values of the sensors.""" registry = er.async_get(hass) diff --git a/tests/components/switchbot/test_sensor.py b/tests/components/switchbot/test_sensor.py index e801faf257c..80c85cdb601 100644 --- a/tests/components/switchbot/test_sensor.py +++ b/tests/components/switchbot/test_sensor.py @@ -1,4 +1,5 @@ """Test the switchbot sensors.""" + from homeassistant.components.sensor import ATTR_STATE_CLASS from homeassistant.components.switchbot.const import DOMAIN from homeassistant.const import ( @@ -18,7 +19,9 @@ from tests.common import MockConfigEntry from tests.components.bluetooth import inject_bluetooth_service_info -async def test_sensors(hass: HomeAssistant, entity_registry_enabled_by_default) -> None: +async def test_sensors( + hass: HomeAssistant, entity_registry_enabled_by_default: None +) -> None: """Test setting up creates the sensors.""" await async_setup_component(hass, DOMAIN, {}) inject_bluetooth_service_info(hass, WOHAND_SERVICE_INFO) diff --git a/tests/components/unifi/test_sensor.py b/tests/components/unifi/test_sensor.py index b4b82166269..bf7ba4d53c0 100644 --- a/tests/components/unifi/test_sensor.py +++ b/tests/components/unifi/test_sensor.py @@ -210,7 +210,7 @@ async def test_uptime_sensors( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_unifi_websocket, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, initial_uptime, event_uptime, new_uptime, @@ -296,7 +296,7 @@ async def test_remove_sensors( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_unifi_websocket, - entity_registry_enabled_by_default, + entity_registry_enabled_by_default: None, ) -> None: """Verify removing of clients work as expected.""" wired_client = { diff --git a/tests/components/unifiprotect/test_sensor.py b/tests/components/unifiprotect/test_sensor.py index 0d763e6f906..db7cdc801bf 100644 --- a/tests/components/unifiprotect/test_sensor.py +++ b/tests/components/unifiprotect/test_sensor.py @@ -1,9 +1,8 @@ """Test the UniFi Protect sensor platform.""" - from __future__ import annotations from datetime import datetime, timedelta -from unittest.mock import AsyncMock, Mock +from unittest.mock import Mock from pyunifiprotect.data import ( NVR, @@ -398,7 +397,7 @@ async def test_sensor_setup_camera( async def test_sensor_setup_camera_with_last_trip_time( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, ufp: MockUFPFixture, doorbell: Camera, fixed_now: datetime, @@ -474,7 +473,7 @@ async def test_sensor_update_alarm( async def test_sensor_update_alarm_with_last_trip_time( hass: HomeAssistant, - entity_registry_enabled_by_default: AsyncMock, + entity_registry_enabled_by_default: None, ufp: MockUFPFixture, sensor_all: Sensor, fixed_now: datetime,