Enable Ruff PT001 (#86730)

pull/86738/head
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
"E", # pycodestyle
"F", # pyflakes/autoflake
"T20", # flake8-print
"W", # pycodestyle
"UP", # pyupgrade
"PGH004", # Use specific rule codes when using noqa
"PT001", # Use @pytest.fixture without parentheses
"T20", # flake8-print
"UP", # pyupgrade
"W", # pycodestyle
]
ignore = [
@ -268,6 +269,9 @@ ignore = [
"UP024", # Replace aliased errors with `OSError`
]
[tool.ruff.flake8-pytest-style]
fixture-parentheses = false
[tool.ruff.per-file-ignores]
# 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
@pytest.fixture()
@pytest.fixture
def api_discovery_items():
"""Additional Apidiscovery items."""
return {}

View File

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

View File

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

View File

@ -13,7 +13,7 @@ from homeassistant.helpers.entity import EntityCategory
from tests.common import async_fire_time_changed, mock_registry
@pytest.fixture()
@pytest.fixture
def cloud_stub():
"""Stub the cloud."""
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
@pytest.fixture()
@pytest.fixture
def cloud_with_prefs(cloud_prefs):
"""Return a cloud mock with prefs."""
return Mock(client=Mock(prefs=cloud_prefs))

View File

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

View File

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

View File

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

View File

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

View File

@ -141,13 +141,13 @@ class FakeHarmonyClient:
self._callbacks.disconnect(None)
@pytest.fixture()
@pytest.fixture
def harmony_client():
"""Create the FakeHarmonyClient instance."""
return FakeHarmonyClient()
@pytest.fixture()
@pytest.fixture
def mock_hc(harmony_client):
"""Patch the real HarmonyClient with initialization side effect."""
@ -158,7 +158,7 @@ def mock_hc(harmony_client):
yield fake
@pytest.fixture()
@pytest.fixture
def mock_write_config():
"""Patches write_config_file to remove side effects."""
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"}
@pytest.fixture()
@pytest.fixture
def extra_os_info():
"""Extra os/info."""
return {}
@pytest.fixture()
@pytest.fixture
def os_info(extra_os_info):
"""Mock os/info."""
return {

View File

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

View File

@ -20,7 +20,7 @@ def iid_storage(hass):
yield AccessoryIIDStorage(hass, "")
@pytest.fixture()
@pytest.fixture
def run_driver(hass, event_loop, iid_storage):
"""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
@pytest.fixture()
@pytest.fixture
def mock_fireplace_finder_none() -> Generator[None, MagicMock, None]:
"""Mock fireplace finder."""
mock_found_fireplaces = Mock()
@ -26,7 +26,7 @@ def mock_fireplace_finder_none() -> Generator[None, MagicMock, None]:
yield mock_found_fireplaces
@pytest.fixture()
@pytest.fixture
def mock_fireplace_finder_single() -> Generator[None, MagicMock, None]:
"""Mock fireplace finder."""
mock_found_fireplaces = Mock()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,7 +48,7 @@ def get_config_entry_with_auth(hass: HomeAssistant) -> ConfigEntry:
return config_entry_with_auth
@pytest.fixture()
@pytest.fixture
def system_get_info() -> Generator[SystemInfo, None, None]:
"""Fixture for SFRBox.system_get_info."""
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
@pytest.fixture()
@pytest.fixture
def dsl_get_info() -> Generator[DslInfo, None, None]:
"""Fixture for SFRBox.dsl_get_info."""
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."""
@pytest.fixture()
@pytest.fixture
async def mock_connected_snooz(hass: HomeAssistant):
"""Mock a Snooz configuration entry and device."""

View File

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

View File

@ -8,7 +8,7 @@ from .common import ComponentFactory
from tests.components.light.conftest import mock_light_profiles # noqa: F401
@pytest.fixture()
@pytest.fixture
def vera_component_factory():
"""Return a factory for initializing the vera component."""
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
@pytest.fixture()
@pytest.fixture
def component_factory(
hass: HomeAssistant,
hass_client_no_auth,

View File

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