Enable Ruff PT001 (#86730)

This commit is contained in:
Franck Nijhof 2023-01-26 18:05:05 +01:00 committed by GitHub
parent 7ed9967245
commit 62dcbe5258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 53 additions and 49 deletions

View File

@ -246,10 +246,11 @@ select = [
"D", # docstrings "D", # docstrings
"E", # pycodestyle "E", # pycodestyle
"F", # pyflakes/autoflake "F", # pyflakes/autoflake
"T20", # flake8-print
"W", # pycodestyle
"UP", # pyupgrade
"PGH004", # Use specific rule codes when using noqa "PGH004", # Use specific rule codes when using noqa
"PT001", # Use @pytest.fixture without parentheses
"T20", # flake8-print
"UP", # pyupgrade
"W", # pycodestyle
] ]
ignore = [ ignore = [
@ -268,6 +269,9 @@ ignore = [
"UP024", # Replace aliased errors with `OSError` "UP024", # Replace aliased errors with `OSError`
] ]
[tool.ruff.flake8-pytest-style]
fixture-parentheses = false
[tool.ruff.per-file-ignores] [tool.ruff.per-file-ignores]
# TODO: these files have functions that are too complex, but flake8's and ruff's # TODO: these files have functions that are too complex, but flake8's and ruff's

View File

@ -157,7 +157,7 @@ def default_request_fixture(respx_mock):
yield __mock_default_requests yield __mock_default_requests
@pytest.fixture() @pytest.fixture
def api_discovery_items(): def api_discovery_items():
"""Additional Apidiscovery items.""" """Additional Apidiscovery items."""
return {} return {}

View File

@ -25,7 +25,7 @@ API_DISCOVERY_LIGHT_CONTROL = {
} }
@pytest.fixture() @pytest.fixture
def light_control_items(): def light_control_items():
"""Available lights.""" """Available lights."""
return [ return [

View File

@ -6,7 +6,7 @@ import pychromecast
import pytest import pytest
@pytest.fixture() @pytest.fixture
def get_multizone_status_mock(): def get_multizone_status_mock():
"""Mock pychromecast dial.""" """Mock pychromecast dial."""
mock = MagicMock(spec_set=pychromecast.dial.get_multizone_status) mock = MagicMock(spec_set=pychromecast.dial.get_multizone_status)
@ -14,32 +14,32 @@ def get_multizone_status_mock():
return mock return mock
@pytest.fixture() @pytest.fixture
def get_cast_type_mock(): def get_cast_type_mock():
"""Mock pychromecast dial.""" """Mock pychromecast dial."""
mock = MagicMock(spec_set=pychromecast.dial.get_cast_type) mock = MagicMock(spec_set=pychromecast.dial.get_cast_type)
return mock return mock
@pytest.fixture() @pytest.fixture
def castbrowser_mock(): def castbrowser_mock():
"""Mock pychromecast CastBrowser.""" """Mock pychromecast CastBrowser."""
return MagicMock(spec=pychromecast.discovery.CastBrowser) return MagicMock(spec=pychromecast.discovery.CastBrowser)
@pytest.fixture() @pytest.fixture
def mz_mock(): def mz_mock():
"""Mock pychromecast MultizoneManager.""" """Mock pychromecast MultizoneManager."""
return MagicMock(spec_set=pychromecast.controllers.multizone.MultizoneManager) return MagicMock(spec_set=pychromecast.controllers.multizone.MultizoneManager)
@pytest.fixture() @pytest.fixture
def quick_play_mock(): def quick_play_mock():
"""Mock pychromecast quick_play.""" """Mock pychromecast quick_play."""
return MagicMock() return MagicMock()
@pytest.fixture() @pytest.fixture
def get_chromecast_mock(): def get_chromecast_mock():
"""Mock pychromecast get_chromecast_from_cast_info.""" """Mock pychromecast get_chromecast_from_cast_info."""
return MagicMock() return MagicMock()

View File

@ -13,7 +13,7 @@ from homeassistant.helpers.entity import EntityCategory
from tests.common import async_fire_time_changed, mock_registry from tests.common import async_fire_time_changed, mock_registry
@pytest.fixture() @pytest.fixture
def cloud_stub(): def cloud_stub():
"""Stub the cloud.""" """Stub the cloud."""
return Mock(is_logged_in=True, subscription_expired=False) return Mock(is_logged_in=True, subscription_expired=False)

View File

@ -8,7 +8,7 @@ import voluptuous as vol
from homeassistant.components.cloud import const, tts from homeassistant.components.cloud import const, tts
@pytest.fixture() @pytest.fixture
def cloud_with_prefs(cloud_prefs): def cloud_with_prefs(cloud_prefs):
"""Return a cloud mock with prefs.""" """Return a cloud mock with prefs."""
return Mock(client=Mock(prefs=cloud_prefs)) return Mock(client=Mock(prefs=cloud_prefs))

View File

@ -8,7 +8,7 @@ from .const import DISCOVERY_INFO, IP
from .mock import MockDevice from .mock import MockDevice
@pytest.fixture() @pytest.fixture
def mock_device(): def mock_device():
"""Mock connecting to a devolo home network device.""" """Mock connecting to a devolo home network device."""
device = MockDevice(ip=IP) device = MockDevice(ip=IP)

View File

@ -48,13 +48,13 @@ def create_entry(hass: HomeAssistant) -> MockConfigEntry:
return entry return entry
@pytest.fixture() @pytest.fixture
def config_entry(hass: HomeAssistant) -> MockConfigEntry: def config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Add config entry in Home Assistant.""" """Add config entry in Home Assistant."""
return create_entry(hass) return create_entry(hass)
@pytest.fixture() @pytest.fixture
def config_entry_with_uid(hass: HomeAssistant) -> MockConfigEntry: def config_entry_with_uid(hass: HomeAssistant) -> MockConfigEntry:
"""Add config entry with unique ID in Home Assistant.""" """Add config entry with unique ID in Home Assistant."""
config_entry = create_entry(hass) config_entry = create_entry(hass)
@ -62,7 +62,7 @@ def config_entry_with_uid(hass: HomeAssistant) -> MockConfigEntry:
return config_entry return config_entry
@pytest.fixture() @pytest.fixture
def mocked_plug() -> MagicMock: def mocked_plug() -> MagicMock:
"""Create mocked plug device.""" """Create mocked plug device."""
mocked_plug = MagicMock() mocked_plug = MagicMock()
@ -74,7 +74,7 @@ def mocked_plug() -> MagicMock:
return mocked_plug return mocked_plug
@pytest.fixture() @pytest.fixture
def mocked_plug_no_auth(mocked_plug: MagicMock) -> MagicMock: def mocked_plug_no_auth(mocked_plug: MagicMock) -> MagicMock:
"""Create mocked unauthenticated plug device.""" """Create mocked unauthenticated plug device."""
mocked_plug = deepcopy(mocked_plug) mocked_plug = deepcopy(mocked_plug)

View File

@ -5,14 +5,14 @@ from unittest.mock import patch
import pytest import pytest
@pytest.fixture() @pytest.fixture
def mock_get_stations(): def mock_get_stations():
"""Mock aioeafm.get_stations.""" """Mock aioeafm.get_stations."""
with patch("homeassistant.components.eafm.config_flow.get_stations") as patched: with patch("homeassistant.components.eafm.config_flow.get_stations") as patched:
yield patched yield patched
@pytest.fixture() @pytest.fixture
def mock_get_station(): def mock_get_station():
"""Mock aioeafm.get_station.""" """Mock aioeafm.get_station."""
with patch("homeassistant.components.eafm.sensor.get_station") as patched: with patch("homeassistant.components.eafm.sensor.get_station") as patched:

View File

@ -79,7 +79,7 @@ def fc_data_mock():
return MOCK_FB_SERVICES return MOCK_FB_SERVICES
@pytest.fixture() @pytest.fixture
def fc_class_mock(fc_data): def fc_class_mock(fc_data):
"""Fixture that sets up a mocked FritzConnection class.""" """Fixture that sets up a mocked FritzConnection class."""
with patch( with patch(
@ -89,7 +89,7 @@ def fc_class_mock(fc_data):
yield result yield result
@pytest.fixture() @pytest.fixture
def fh_class_mock(): def fh_class_mock():
"""Fixture that sets up a mocked FritzHosts class.""" """Fixture that sets up a mocked FritzHosts class."""
with patch( with patch(

View File

@ -141,13 +141,13 @@ class FakeHarmonyClient:
self._callbacks.disconnect(None) self._callbacks.disconnect(None)
@pytest.fixture() @pytest.fixture
def harmony_client(): def harmony_client():
"""Create the FakeHarmonyClient instance.""" """Create the FakeHarmonyClient instance."""
return FakeHarmonyClient() return FakeHarmonyClient()
@pytest.fixture() @pytest.fixture
def mock_hc(harmony_client): def mock_hc(harmony_client):
"""Patch the real HarmonyClient with initialization side effect.""" """Patch the real HarmonyClient with initialization side effect."""
@ -158,7 +158,7 @@ def mock_hc(harmony_client):
yield fake yield fake
@pytest.fixture() @pytest.fixture
def mock_write_config(): def mock_write_config():
"""Patches write_config_file to remove side effects.""" """Patches write_config_file to remove side effects."""
with patch( with patch(

View File

@ -25,13 +25,13 @@ from tests.common import MockConfigEntry, async_fire_time_changed
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"} MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
@pytest.fixture() @pytest.fixture
def extra_os_info(): def extra_os_info():
"""Extra os/info.""" """Extra os/info."""
return {} return {}
@pytest.fixture() @pytest.fixture
def os_info(extra_os_info): def os_info(extra_os_info):
"""Mock os/info.""" """Mock os/info."""
return { return {

View File

@ -12,7 +12,7 @@ CLIENT_SECRET = "5678"
SUBSCRIPTION_KEY = "12345678901234567890123456789012" SUBSCRIPTION_KEY = "12345678901234567890123456789012"
@pytest.fixture() @pytest.fixture
def mock_config_entry(): def mock_config_entry():
"""Return a fake config entry. """Return a fake config entry.
@ -40,7 +40,7 @@ def mock_config_entry():
) )
@pytest.fixture() @pytest.fixture
def mock_modules(): def mock_modules():
"""Return the full set of mock modules.""" """Return the full set of mock modules."""
plant = HomePlusPlant( plant = HomePlusPlant(

View File

@ -20,7 +20,7 @@ def iid_storage(hass):
yield AccessoryIIDStorage(hass, "") yield AccessoryIIDStorage(hass, "")
@pytest.fixture() @pytest.fixture
def run_driver(hass, event_loop, iid_storage): def run_driver(hass, event_loop, iid_storage):
"""Return a custom AccessoryDriver instance for HomeKit accessory init. """Return a custom AccessoryDriver instance for HomeKit accessory init.

View File

@ -15,7 +15,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
yield mock_setup yield mock_setup
@pytest.fixture() @pytest.fixture
def mock_fireplace_finder_none() -> Generator[None, MagicMock, None]: def mock_fireplace_finder_none() -> Generator[None, MagicMock, None]:
"""Mock fireplace finder.""" """Mock fireplace finder."""
mock_found_fireplaces = Mock() mock_found_fireplaces = Mock()
@ -26,7 +26,7 @@ def mock_fireplace_finder_none() -> Generator[None, MagicMock, None]:
yield mock_found_fireplaces yield mock_found_fireplaces
@pytest.fixture() @pytest.fixture
def mock_fireplace_finder_single() -> Generator[None, MagicMock, None]: def mock_fireplace_finder_single() -> Generator[None, MagicMock, None]:
"""Mock fireplace finder.""" """Mock fireplace finder."""
mock_found_fireplaces = Mock() mock_found_fireplaces = Mock()

View File

@ -64,7 +64,7 @@ async def hass_(recorder_mock, hass):
return hass return hass
@pytest.fixture() @pytest.fixture
def set_utc(hass): def set_utc(hass):
"""Set timezone to UTC.""" """Set timezone to UTC."""
hass.config.set_time_zone("UTC") hass.config.set_time_zone("UTC")

View File

@ -47,7 +47,7 @@ from tests.components.recorder.common import (
) )
@pytest.fixture() @pytest.fixture
def set_utc(hass): def set_utc(hass):
"""Set timezone to UTC.""" """Set timezone to UTC."""
hass.config.set_time_zone("UTC") hass.config.set_time_zone("UTC")

View File

@ -19,7 +19,7 @@ CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"
@pytest.fixture() @pytest.fixture
async def mock_impl(hass): async def mock_impl(hass):
"""Mock implementation.""" """Mock implementation."""
await async_setup_component(hass, DOMAIN, {}) await async_setup_component(hass, DOMAIN, {})

View File

@ -5,7 +5,7 @@ from datapoint.exceptions import APIException
import pytest import pytest
@pytest.fixture() @pytest.fixture
def mock_simple_manager_fail(): def mock_simple_manager_fail():
"""Mock datapoint Manager with default values for testing in config_flow.""" """Mock datapoint Manager with default values for testing in config_flow."""
with patch("datapoint.Manager") as mock_manager: with patch("datapoint.Manager") as mock_manager:

View File

@ -6,7 +6,7 @@ import pytest
from .const import DEFAULT_FORECAST, DEFAULT_OBSERVATION from .const import DEFAULT_FORECAST, DEFAULT_OBSERVATION
@pytest.fixture() @pytest.fixture
def mock_simple_nws(): def mock_simple_nws():
"""Mock pynws SimpleNWS with default values.""" """Mock pynws SimpleNWS with default values."""
with patch("homeassistant.components.nws.SimpleNWS") as mock_nws: with patch("homeassistant.components.nws.SimpleNWS") as mock_nws:
@ -23,7 +23,7 @@ def mock_simple_nws():
yield mock_nws yield mock_nws
@pytest.fixture() @pytest.fixture
def mock_simple_nws_config(): def mock_simple_nws_config():
"""Mock pynws SimpleNWS with default values in config_flow.""" """Mock pynws SimpleNWS with default values in config_flow."""
with patch("homeassistant.components.nws.config_flow.SimpleNWS") as mock_nws: with patch("homeassistant.components.nws.config_flow.SimpleNWS") as mock_nws:
@ -34,7 +34,7 @@ def mock_simple_nws_config():
yield mock_nws yield mock_nws
@pytest.fixture() @pytest.fixture
def no_sensor(): def no_sensor():
"""Remove sensors.""" """Remove sensors."""
with patch( with patch(
@ -43,7 +43,7 @@ def no_sensor():
yield mock_setup_entry yield mock_setup_entry
@pytest.fixture() @pytest.fixture
def no_weather(): def no_weather():
"""Remove weather.""" """Remove weather."""
with patch( with patch(

View File

@ -54,7 +54,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
yield mock_setup yield mock_setup
@pytest.fixture() @pytest.fixture
def mock_smile_config_flow() -> Generator[None, MagicMock, None]: def mock_smile_config_flow() -> Generator[None, MagicMock, None]:
"""Return a mocked Smile client.""" """Return a mocked Smile client."""
with patch( with patch(

View File

@ -48,7 +48,7 @@ def get_config_entry_with_auth(hass: HomeAssistant) -> ConfigEntry:
return config_entry_with_auth return config_entry_with_auth
@pytest.fixture() @pytest.fixture
def system_get_info() -> Generator[SystemInfo, None, None]: def system_get_info() -> Generator[SystemInfo, None, None]:
"""Fixture for SFRBox.system_get_info.""" """Fixture for SFRBox.system_get_info."""
system_info = SystemInfo(**json.loads(load_fixture("system_getInfo.json", DOMAIN))) system_info = SystemInfo(**json.loads(load_fixture("system_getInfo.json", DOMAIN)))
@ -59,7 +59,7 @@ def system_get_info() -> Generator[SystemInfo, None, None]:
yield system_info yield system_info
@pytest.fixture() @pytest.fixture
def dsl_get_info() -> Generator[DslInfo, None, None]: def dsl_get_info() -> Generator[DslInfo, None, None]:
"""Fixture for SFRBox.dsl_get_info.""" """Fixture for SFRBox.dsl_get_info."""
dsl_info = DslInfo(**json.loads(load_fixture("dsl_getInfo.json", DOMAIN))) dsl_info = DslInfo(**json.loads(load_fixture("dsl_getInfo.json", DOMAIN)))

View File

@ -13,7 +13,7 @@ def mock_bluetooth(enable_bluetooth):
"""Auto mock bluetooth.""" """Auto mock bluetooth."""
@pytest.fixture() @pytest.fixture
async def mock_connected_snooz(hass: HomeAssistant): async def mock_connected_snooz(hass: HomeAssistant):
"""Mock a Snooz configuration entry and device.""" """Mock a Snooz configuration entry and device."""

View File

@ -59,7 +59,7 @@ class WorkerSync:
self._original(stream_state) self._original(stream_state)
@pytest.fixture() @pytest.fixture
def stream_worker_sync(hass): def stream_worker_sync(hass):
"""Patch StreamOutput to allow test to synchronize worker stream end.""" """Patch StreamOutput to allow test to synchronize worker stream end."""
sync = WorkerSync() sync = WorkerSync()
@ -138,7 +138,7 @@ class HLSSync:
return await self._original_part_recv(output) return await self._original_part_recv(output)
@pytest.fixture() @pytest.fixture
def hls_sync(): def hls_sync():
"""Patch HLSOutput to allow test to synchronize playlist requests and responses.""" """Patch HLSOutput to allow test to synchronize playlist requests and responses."""
sync = HLSSync() sync = HLSSync()

View File

@ -8,7 +8,7 @@ from .common import ComponentFactory
from tests.components.light.conftest import mock_light_profiles # noqa: F401 from tests.components.light.conftest import mock_light_profiles # noqa: F401
@pytest.fixture() @pytest.fixture
def vera_component_factory(): def vera_component_factory():
"""Return a factory for initializing the vera component.""" """Return a factory for initializing the vera component."""
with patch("pyvera.VeraController") as vera_controller_class_mock: with patch("pyvera.VeraController") as vera_controller_class_mock:

View File

@ -11,7 +11,7 @@ from .common import ComponentFactory
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@pytest.fixture() @pytest.fixture
def component_factory( def component_factory(
hass: HomeAssistant, hass: HomeAssistant,
hass_client_no_auth, hass_client_no_auth,

View File

@ -82,7 +82,7 @@ def com_port(device="/dev/ttyUSB1234"):
return port return port
@pytest.fixture() @pytest.fixture
def mock_connect_zigpy_app() -> Generator[None, None, None]: def mock_connect_zigpy_app() -> Generator[None, None, None]:
"""Mock the radio connection.""" """Mock the radio connection."""