From 54c20d5d5a654f114d2abb0df32c01a6733e2f4c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:52:51 +0200 Subject: [PATCH] Use async_load_fixture in remaining tests (#146021) --- tests/components/hassio/test_backup.py | 8 +++++--- .../test_config_flow.py | 6 ++++-- tests/components/nexia/test_switch.py | 2 +- tests/components/nexia/util.py | 19 ++++++++++--------- tests/components/nuki/__init__.py | 14 +++++++++----- tests/components/overkiz/test_diagnostics.py | 10 +++++++--- .../components/switchbot_cloud/test_sensor.py | 6 ++++-- tests/components/youless/__init__.py | 16 +++++++++++----- 8 files changed, 51 insertions(+), 30 deletions(-) diff --git a/tests/components/hassio/test_backup.py b/tests/components/hassio/test_backup.py index 4bf420e6b0d..ed1a6e312d3 100644 --- a/tests/components/hassio/test_backup.py +++ b/tests/components/hassio/test_backup.py @@ -54,7 +54,7 @@ from homeassistant.setup import async_setup_component from .test_init import MOCK_ENVIRON -from tests.common import load_json_object_fixture, mock_platform +from tests.common import async_load_json_object_fixture, mock_platform from tests.typing import ClientSessionGenerator, WebSocketGenerator TEST_BACKUP = supervisor_backups.Backup( @@ -1018,8 +1018,10 @@ async def test_reader_writer_create_addon_folder_error( supervisor_client.jobs.get_job.side_effect = [ TEST_JOB_NOT_DONE, supervisor_jobs.Job.from_dict( - load_json_object_fixture( - "backup_done_with_addon_folder_errors.json", DOMAIN + ( + await async_load_json_object_fixture( + hass, "backup_done_with_addon_folder_errors.json", DOMAIN + ) )["data"] ), ] diff --git a/tests/components/hunterdouglas_powerview/test_config_flow.py b/tests/components/hunterdouglas_powerview/test_config_flow.py index 5a48e08e5db..f3946365630 100644 --- a/tests/components/hunterdouglas_powerview/test_config_flow.py +++ b/tests/components/hunterdouglas_powerview/test_config_flow.py @@ -15,7 +15,7 @@ from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo from .const import DHCP_DATA, DISCOVERY_DATA, HOMEKIT_DATA, MOCK_SERIAL -from tests.common import MockConfigEntry, load_json_object_fixture +from tests.common import MockConfigEntry, async_load_json_object_fixture @pytest.mark.usefixtures("mock_hunterdouglas_hub") @@ -330,7 +330,9 @@ async def test_form_unsupported_device( # Simulate a gen 3 secondary hub with patch( "homeassistant.components.hunterdouglas_powerview.util.Hub.request_raw_data", - return_value=load_json_object_fixture("gen3/gateway/secondary.json", DOMAIN), + return_value=await async_load_json_object_fixture( + hass, "gen3/gateway/secondary.json", DOMAIN + ), ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], diff --git a/tests/components/nexia/test_switch.py b/tests/components/nexia/test_switch.py index e532201f01e..8f83c25cec0 100644 --- a/tests/components/nexia/test_switch.py +++ b/tests/components/nexia/test_switch.py @@ -29,7 +29,7 @@ async def test_nexia_sensor_switch( hass: HomeAssistant, freezer: FrozenDateTimeFactory ) -> None: """Test NexiaRoomIQSensorSwitch.""" - await async_init_integration(hass, house_fixture="nexia/sensors_xl1050_house.json") + await async_init_integration(hass, house_fixture="sensors_xl1050_house.json") sw1_id = f"{Platform.SWITCH}.center_nativezone_include_center" sw1 = {ATTR_ENTITY_ID: sw1_id} sw2_id = f"{Platform.SWITCH}.center_nativezone_include_upstairs" diff --git a/tests/components/nexia/util.py b/tests/components/nexia/util.py index d9f0f59b719..b70020b4c4c 100644 --- a/tests/components/nexia/util.py +++ b/tests/components/nexia/util.py @@ -9,7 +9,7 @@ from homeassistant.components.nexia.const import DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.test_util.aiohttp import mock_aiohttp_client @@ -18,13 +18,13 @@ async def async_init_integration( skip_setup: bool = False, exception: Exception | None = None, *, - house_fixture="nexia/mobile_houses_123456.json", + house_fixture="mobile_houses_123456.json", ) -> MockConfigEntry: """Set up the nexia integration in Home Assistant.""" - session_fixture = "nexia/session_123456.json" - sign_in_fixture = "nexia/sign_in.json" - set_fan_speed_fixture = "nexia/set_fan_speed_2293892.json" + session_fixture = "session_123456.json" + sign_in_fixture = "sign_in.json" + set_fan_speed_fixture = "set_fan_speed_2293892.json" with ( mock_aiohttp_client() as mock_session, patch("nexia.home.load_or_create_uuid", return_value=uuid.uuid4()), @@ -40,19 +40,20 @@ async def async_init_integration( ) else: mock_session.post( - nexia.API_MOBILE_SESSION_URL, text=load_fixture(session_fixture) + nexia.API_MOBILE_SESSION_URL, + text=await async_load_fixture(hass, session_fixture, DOMAIN), ) mock_session.get( nexia.API_MOBILE_HOUSES_URL.format(house_id=123456), - text=load_fixture(house_fixture), + text=await async_load_fixture(hass, house_fixture, DOMAIN), ) mock_session.post( nexia.API_MOBILE_ACCOUNTS_SIGN_IN_URL, - text=load_fixture(sign_in_fixture), + text=await async_load_fixture(hass, sign_in_fixture, DOMAIN), ) mock_session.post( "https://www.mynexia.com/mobile/xxl_thermostats/2293892/fan_speed", - text=load_fixture(set_fan_speed_fixture), + text=await async_load_fixture(hass, set_fan_speed_fixture, DOMAIN), ) entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/nuki/__init__.py b/tests/components/nuki/__init__.py index d100e4b628e..4f5728003fc 100644 --- a/tests/components/nuki/__init__.py +++ b/tests/components/nuki/__init__.py @@ -9,8 +9,8 @@ from .mock import MOCK_INFO, setup_nuki_integration from tests.common import ( MockConfigEntry, - load_json_array_fixture, - load_json_object_fixture, + async_load_json_array_fixture, + async_load_json_object_fixture, ) @@ -21,15 +21,19 @@ async def init_integration(hass: HomeAssistant) -> MockConfigEntry: mock.get("http://1.1.1.1:8080/info", json=MOCK_INFO) mock.get( "http://1.1.1.1:8080/list", - json=load_json_array_fixture("list.json", DOMAIN), + json=await async_load_json_array_fixture(hass, "list.json", DOMAIN), ) mock.get( "http://1.1.1.1:8080/callback/list", - json=load_json_object_fixture("callback_list.json", DOMAIN), + json=await async_load_json_object_fixture( + hass, "callback_list.json", DOMAIN + ), ) mock.get( "http://1.1.1.1:8080/callback/add", - json=load_json_object_fixture("callback_add.json", DOMAIN), + json=await async_load_json_object_fixture( + hass, "callback_add.json", DOMAIN + ), ) entry = await setup_nuki_integration(hass) await hass.config_entries.async_setup(entry.entry_id) diff --git a/tests/components/overkiz/test_diagnostics.py b/tests/components/overkiz/test_diagnostics.py index e052818daee..f6f7a7c3953 100644 --- a/tests/components/overkiz/test_diagnostics.py +++ b/tests/components/overkiz/test_diagnostics.py @@ -8,7 +8,7 @@ from homeassistant.components.overkiz.const import DOMAIN from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr -from tests.common import MockConfigEntry, load_json_object_fixture +from tests.common import MockConfigEntry, async_load_json_object_fixture from tests.components.diagnostics import ( get_diagnostics_for_config_entry, get_diagnostics_for_device, @@ -23,7 +23,9 @@ async def test_diagnostics( snapshot: SnapshotAssertion, ) -> None: """Test diagnostics.""" - diagnostic_data = load_json_object_fixture("overkiz/setup_tahoma_switch.json") + diagnostic_data = await async_load_json_object_fixture( + hass, "setup_tahoma_switch.json", DOMAIN + ) with patch.multiple( "pyoverkiz.client.OverkizClient", @@ -44,7 +46,9 @@ async def test_device_diagnostics( snapshot: SnapshotAssertion, ) -> None: """Test device diagnostics.""" - diagnostic_data = load_json_object_fixture("overkiz/setup_tahoma_switch.json") + diagnostic_data = await async_load_json_object_fixture( + hass, "setup_tahoma_switch.json", DOMAIN + ) device = device_registry.async_get_device( identifiers={(DOMAIN, "rts://****-****-6867/16756006")} diff --git a/tests/components/switchbot_cloud/test_sensor.py b/tests/components/switchbot_cloud/test_sensor.py index 0927e3cf1ea..440e71f3124 100644 --- a/tests/components/switchbot_cloud/test_sensor.py +++ b/tests/components/switchbot_cloud/test_sensor.py @@ -12,7 +12,7 @@ from homeassistant.helpers import entity_registry as er from . import configure_integration -from tests.common import load_json_object_fixture, snapshot_platform +from tests.common import async_load_json_object_fixture, snapshot_platform async def test_meter( @@ -33,7 +33,9 @@ async def test_meter( hubDeviceId="test-hub-id", ), ] - mock_get_status.return_value = load_json_object_fixture("meter_status.json", DOMAIN) + mock_get_status.return_value = await async_load_json_object_fixture( + hass, "meter_status.json", DOMAIN + ) with patch("homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.SENSOR]): entry = await configure_integration(hass) diff --git a/tests/components/youless/__init__.py b/tests/components/youless/__init__.py index 03db24cb7f7..d6cc5769060 100644 --- a/tests/components/youless/__init__.py +++ b/tests/components/youless/__init__.py @@ -8,8 +8,8 @@ from homeassistant.core import HomeAssistant from tests.common import ( MockConfigEntry, - load_json_array_fixture, - load_json_object_fixture, + async_load_json_array_fixture, + async_load_json_object_fixture, ) @@ -18,16 +18,22 @@ async def init_component(hass: HomeAssistant) -> MockConfigEntry: with requests_mock.Mocker() as mock: mock.get( "http://1.1.1.1/d", - json=load_json_object_fixture("device.json", youless.DOMAIN), + json=await async_load_json_object_fixture( + hass, "device.json", youless.DOMAIN + ), ) mock.get( "http://1.1.1.1/e", - json=load_json_array_fixture("enologic.json", youless.DOMAIN), + json=await async_load_json_array_fixture( + hass, "enologic.json", youless.DOMAIN + ), headers={"Content-Type": "application/json"}, ) mock.get( "http://1.1.1.1/f", - json=load_json_object_fixture("phase.json", youless.DOMAIN), + json=await async_load_json_object_fixture( + hass, "phase.json", youless.DOMAIN + ), headers={"Content-Type": "application/json"}, )