From ed9fd2c643de1f7b5a8276c63946c2fd58146247 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 1 Jun 2025 15:31:37 +0200 Subject: [PATCH] Use async_load_fixture in async test functions (b-i) (#145714) * Use async_load_fixture in async test functions (b-i) * Adjust --- tests/components/blueprint/test_importer.py | 6 ++-- .../components/bluetooth/test_base_scanner.py | 4 +-- tests/components/bluetooth/test_manager.py | 8 +++-- tests/components/bring/test_diagnostics.py | 10 ++++-- tests/components/bring/test_init.py | 10 +++--- tests/components/bring/test_sensor.py | 12 ++++--- tests/components/bring/test_todo.py | 10 ++++-- tests/components/cast/test_helpers.py | 13 ++++--- tests/components/cast/test_media_player.py | 5 +-- .../color_extractor/test_service.py | 8 ++--- tests/components/devialet/test_diagnostics.py | 23 +++++++++---- tests/components/efergy/__init__.py | 28 +++++++-------- .../electrasmart/test_config_flow.py | 26 +++++++++----- tests/components/foobot/test_sensor.py | 6 ++-- .../fully_kiosk/test_config_flow.py | 4 +-- tests/components/fully_kiosk/test_init.py | 6 ++-- tests/components/gios/__init__.py | 8 ++--- tests/components/gios/test_config_flow.py | 18 +++++++--- tests/components/gios/test_init.py | 8 ++--- tests/components/gios/test_sensor.py | 6 ++-- tests/components/github/common.py | 8 ++--- tests/components/github/test_diagnostics.py | 6 ++-- tests/components/github/test_sensor.py | 6 ++-- tests/components/goalzero/__init__.py | 6 ++-- tests/components/goalzero/test_switch.py | 8 ++--- tests/components/google_mail/conftest.py | 7 ++-- .../google_mail/test_config_flow.py | 17 +++++++--- tests/components/google_mail/test_sensor.py | 7 ++-- .../google_tasks/test_config_flow.py | 7 ++-- tests/components/habitica/conftest.py | 34 +++++++++---------- .../components/habitica/test_binary_sensor.py | 4 +-- tests/components/habitica/test_button.py | 12 +++---- tests/components/habitica/test_image.py | 4 +-- tests/components/habitica/test_services.py | 4 +-- tests/components/habitica/test_todo.py | 8 +++-- .../homeassistant_alerts/test_init.py | 24 ++++++------- tests/components/homekit/test_iidmanager.py | 14 +++++--- .../husqvarna_automower/test_config_flow.py | 4 +-- tests/components/insteon/test_api_config.py | 5 +-- tests/components/ipp/conftest.py | 5 +-- 40 files changed, 240 insertions(+), 169 deletions(-) diff --git a/tests/components/blueprint/test_importer.py b/tests/components/blueprint/test_importer.py index c61be9e2b32..cccbaa3db3e 100644 --- a/tests/components/blueprint/test_importer.py +++ b/tests/components/blueprint/test_importer.py @@ -6,11 +6,11 @@ from pathlib import Path import pytest from syrupy.assertion import SnapshotAssertion -from homeassistant.components.blueprint import importer +from homeassistant.components.blueprint import DOMAIN, importer from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from tests.common import load_fixture +from tests.common import async_load_fixture, load_fixture from tests.test_util.aiohttp import AiohttpClientMocker @@ -161,7 +161,7 @@ async def test_fetch_blueprint_from_github_gist_url( """Test fetching blueprint from url.""" aioclient_mock.get( "https://api.github.com/gists/e717ce85dd0d2f1bdcdfc884ea25a344", - text=load_fixture("blueprint/github_gist.json"), + text=await async_load_fixture(hass, "github_gist.json", DOMAIN), ) url = "https://gist.github.com/balloob/e717ce85dd0d2f1bdcdfc884ea25a344" diff --git a/tests/components/bluetooth/test_base_scanner.py b/tests/components/bluetooth/test_base_scanner.py index acd630863d2..25dc1b9738d 100644 --- a/tests/components/bluetooth/test_base_scanner.py +++ b/tests/components/bluetooth/test_base_scanner.py @@ -41,7 +41,7 @@ from . import ( patch_bluetooth_time, ) -from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture +from tests.common import MockConfigEntry, async_fire_time_changed, async_load_fixture @pytest.mark.parametrize("name_2", [None, "w"]) @@ -313,7 +313,7 @@ async def test_restore_history_remote_adapter( """Test we can restore history for a remote adapter.""" data = hass_storage[storage.REMOTE_SCANNER_STORAGE_KEY] = json_loads( - load_fixture("bluetooth.remote_scanners", bluetooth.DOMAIN) + await async_load_fixture(hass, "bluetooth.remote_scanners", bluetooth.DOMAIN) ) now = time.time() timestamps = data["data"]["atom-bluetooth-proxy-ceaac4"][ diff --git a/tests/components/bluetooth/test_manager.py b/tests/components/bluetooth/test_manager.py index bf773b69a99..7488aa6e33c 100644 --- a/tests/components/bluetooth/test_manager.py +++ b/tests/components/bluetooth/test_manager.py @@ -63,7 +63,7 @@ from tests.common import ( MockModule, async_call_logger_set_level, async_fire_time_changed, - load_fixture, + async_load_fixture, mock_integration, ) @@ -453,7 +453,7 @@ async def test_restore_history_from_dbus_and_remote_adapters( address = "AA:BB:CC:CC:CC:FF" data = hass_storage[storage.REMOTE_SCANNER_STORAGE_KEY] = json_loads( - load_fixture("bluetooth.remote_scanners", bluetooth.DOMAIN) + await async_load_fixture(hass, "bluetooth.remote_scanners", bluetooth.DOMAIN) ) now = time.time() timestamps = data["data"]["atom-bluetooth-proxy-ceaac4"][ @@ -495,7 +495,9 @@ async def test_restore_history_from_dbus_and_corrupted_remote_adapters( address = "AA:BB:CC:CC:CC:FF" data = hass_storage[storage.REMOTE_SCANNER_STORAGE_KEY] = json_loads( - load_fixture("bluetooth.remote_scanners.corrupt", bluetooth.DOMAIN) + await async_load_fixture( + hass, "bluetooth.remote_scanners.corrupt", bluetooth.DOMAIN + ) ) now = time.time() timestamps = data["data"]["atom-bluetooth-proxy-ceaac4"][ diff --git a/tests/components/bring/test_diagnostics.py b/tests/components/bring/test_diagnostics.py index c4b8defca82..ea2656c0aa0 100644 --- a/tests/components/bring/test_diagnostics.py +++ b/tests/components/bring/test_diagnostics.py @@ -9,7 +9,7 @@ from syrupy.assertion import SnapshotAssertion from homeassistant.components.bring.const import DOMAIN from homeassistant.core import HomeAssistant -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.typing import ClientSessionGenerator @@ -24,8 +24,12 @@ async def test_diagnostics( ) -> None: """Test diagnostics.""" mock_bring_client.get_list.side_effect = [ - BringItemsResponse.from_json(load_fixture("items.json", DOMAIN)), - BringItemsResponse.from_json(load_fixture("items2.json", DOMAIN)), + BringItemsResponse.from_json( + await async_load_fixture(hass, "items.json", DOMAIN) + ), + BringItemsResponse.from_json( + await async_load_fixture(hass, "items2.json", DOMAIN) + ), ] bring_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(bring_config_entry.entry_id) diff --git a/tests/components/bring/test_init.py b/tests/components/bring/test_init.py index 7f235ea505c..60ae68755ff 100644 --- a/tests/components/bring/test_init.py +++ b/tests/components/bring/test_init.py @@ -21,7 +21,7 @@ from homeassistant.helpers import device_registry as dr from .conftest import UUID -from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture +from tests.common import MockConfigEntry, async_fire_time_changed, async_load_fixture async def setup_integration( @@ -240,7 +240,7 @@ async def test_purge_devices( ) mock_bring_client.load_lists.return_value = BringListResponse.from_json( - load_fixture("lists2.json", DOMAIN) + await async_load_fixture(hass, "lists2.json", DOMAIN) ) freezer.tick(timedelta(seconds=90)) @@ -265,7 +265,7 @@ async def test_create_devices( """Test create device entry for new lists.""" list_uuid = "b4776778-7f6c-496e-951b-92a35d3db0dd" mock_bring_client.load_lists.return_value = BringListResponse.from_json( - load_fixture("lists2.json", DOMAIN) + await async_load_fixture(hass, "lists2.json", DOMAIN) ) await setup_integration(hass, bring_config_entry) @@ -279,7 +279,7 @@ async def test_create_devices( ) mock_bring_client.load_lists.return_value = BringListResponse.from_json( - load_fixture("lists.json", DOMAIN) + await async_load_fixture(hass, "lists.json", DOMAIN) ) freezer.tick(timedelta(seconds=90)) async_fire_time_changed(hass) @@ -310,7 +310,7 @@ async def test_coordinator_update_intervals( mock_bring_client.get_activity.reset_mock() mock_bring_client.load_lists.return_value = BringListResponse.from_json( - load_fixture("lists2.json", DOMAIN) + await async_load_fixture(hass, "lists2.json", DOMAIN) ) freezer.tick(timedelta(seconds=90)) async_fire_time_changed(hass) diff --git a/tests/components/bring/test_sensor.py b/tests/components/bring/test_sensor.py index f704debcea9..977aa90d8d7 100644 --- a/tests/components/bring/test_sensor.py +++ b/tests/components/bring/test_sensor.py @@ -13,7 +13,7 @@ from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -from tests.common import MockConfigEntry, load_fixture, snapshot_platform +from tests.common import MockConfigEntry, async_load_fixture, snapshot_platform @pytest.fixture(autouse=True) @@ -36,8 +36,12 @@ async def test_setup( """Snapshot test states of sensor platform.""" mock_bring_client.get_list.side_effect = [ - BringItemsResponse.from_json(load_fixture("items.json", DOMAIN)), - BringItemsResponse.from_json(load_fixture("items2.json", DOMAIN)), + BringItemsResponse.from_json( + await async_load_fixture(hass, "items.json", DOMAIN) + ), + BringItemsResponse.from_json( + await async_load_fixture(hass, "items2.json", DOMAIN) + ), ] bring_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(bring_config_entry.entry_id) @@ -68,7 +72,7 @@ async def test_list_access_states( """Snapshot test states of list access sensor.""" mock_bring_client.get_list.return_value = BringItemsResponse.from_json( - load_fixture(f"{fixture}.json", DOMAIN) + await async_load_fixture(hass, f"{fixture}.json", DOMAIN) ) bring_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(bring_config_entry.entry_id) diff --git a/tests/components/bring/test_todo.py b/tests/components/bring/test_todo.py index 9df7b892db8..3d4bbaf10db 100644 --- a/tests/components/bring/test_todo.py +++ b/tests/components/bring/test_todo.py @@ -22,7 +22,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er -from tests.common import MockConfigEntry, load_fixture, snapshot_platform +from tests.common import MockConfigEntry, async_load_fixture, snapshot_platform @pytest.fixture(autouse=True) @@ -45,8 +45,12 @@ async def test_todo( ) -> None: """Snapshot test states of todo platform.""" mock_bring_client.get_list.side_effect = [ - BringItemsResponse.from_json(load_fixture("items.json", DOMAIN)), - BringItemsResponse.from_json(load_fixture("items2.json", DOMAIN)), + BringItemsResponse.from_json( + await async_load_fixture(hass, "items.json", DOMAIN) + ), + BringItemsResponse.from_json( + await async_load_fixture(hass, "items2.json", DOMAIN) + ), ] bring_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(bring_config_entry.entry_id) diff --git a/tests/components/cast/test_helpers.py b/tests/components/cast/test_helpers.py index 84914db2b3a..2f38a79c777 100644 --- a/tests/components/cast/test_helpers.py +++ b/tests/components/cast/test_helpers.py @@ -3,6 +3,7 @@ from aiohttp import client_exceptions import pytest +from homeassistant.components.cast.const import DOMAIN from homeassistant.components.cast.helpers import ( PlaylistError, PlaylistItem, @@ -11,7 +12,7 @@ from homeassistant.components.cast.helpers import ( ) from homeassistant.core import HomeAssistant -from tests.common import load_fixture +from tests.common import async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker @@ -40,7 +41,9 @@ async def test_hls_playlist_supported( ) -> None: """Test playlist parsing of HLS playlist.""" headers = {"content-type": content_type} - aioclient_mock.get(url, text=load_fixture(fixture, "cast"), headers=headers) + aioclient_mock.get( + url, text=await async_load_fixture(hass, fixture, DOMAIN), headers=headers + ) with pytest.raises(PlaylistSupported): await parse_playlist(hass, url) @@ -108,7 +111,9 @@ async def test_parse_playlist( ) -> None: """Test playlist parsing of HLS playlist.""" headers = {"content-type": content_type} - aioclient_mock.get(url, text=load_fixture(fixture, "cast"), headers=headers) + aioclient_mock.get( + url, text=await async_load_fixture(hass, fixture, DOMAIN), headers=headers + ) playlist = await parse_playlist(hass, url) assert expected_playlist == playlist @@ -132,7 +137,7 @@ async def test_parse_bad_playlist( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, url, fixture ) -> None: """Test playlist parsing of HLS playlist.""" - aioclient_mock.get(url, text=load_fixture(fixture, "cast")) + aioclient_mock.get(url, text=await async_load_fixture(hass, fixture, DOMAIN)) with pytest.raises(PlaylistError): await parse_playlist(hass, url) diff --git a/tests/components/cast/test_media_player.py b/tests/components/cast/test_media_player.py index 386b9270571..c56904f1c48 100644 --- a/tests/components/cast/test_media_player.py +++ b/tests/components/cast/test_media_player.py @@ -18,6 +18,7 @@ import yarl from homeassistant.components import media_player, tts from homeassistant.components.cast import media_player as cast from homeassistant.components.cast.const import ( + DOMAIN, SIGNAL_HASS_CAST_SHOW_VIEW, HomeAssistantControllerData, ) @@ -45,7 +46,7 @@ from homeassistant.setup import async_setup_component from tests.common import ( MockConfigEntry, assert_setup_component, - load_fixture, + async_load_fixture, mock_platform, ) from tests.components.media_player import common @@ -1348,7 +1349,7 @@ async def test_entity_play_media_playlist( ) -> None: """Test playing media.""" entity_id = "media_player.speaker" - aioclient_mock.get(url, text=load_fixture(fixture, "cast")) + aioclient_mock.get(url, text=await async_load_fixture(hass, fixture, DOMAIN)) await async_process_ha_core_config( hass, diff --git a/tests/components/color_extractor/test_service.py b/tests/components/color_extractor/test_service.py index 3f920b7dee2..e46e5843210 100644 --- a/tests/components/color_extractor/test_service.py +++ b/tests/components/color_extractor/test_service.py @@ -27,7 +27,7 @@ from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from homeassistant.util import color as color_util -from tests.common import load_fixture +from tests.common import async_load_fixture, load_fixture from tests.test_util.aiohttp import AiohttpClientMocker LIGHT_ENTITY = "light.kitchen_lights" @@ -145,7 +145,7 @@ async def test_url_success( aioclient_mock.get( url=service_data[ATTR_URL], content=base64.b64decode( - load_fixture("color_extractor/color_extractor_url.txt") + await async_load_fixture(hass, "color_extractor_url.txt", DOMAIN) ), ) @@ -233,9 +233,7 @@ async def test_url_error( @patch( "builtins.open", mock_open( - read_data=base64.b64decode( - load_fixture("color_extractor/color_extractor_file.txt") - ) + read_data=base64.b64decode(load_fixture("color_extractor_file.txt", DOMAIN)) ), create=True, ) diff --git a/tests/components/devialet/test_diagnostics.py b/tests/components/devialet/test_diagnostics.py index 6bf643ce682..4bf74d11460 100644 --- a/tests/components/devialet/test_diagnostics.py +++ b/tests/components/devialet/test_diagnostics.py @@ -2,11 +2,12 @@ import json +from homeassistant.components.devialet.const import DOMAIN from homeassistant.core import HomeAssistant from . import setup_integration -from tests.common import load_fixture +from tests.common import async_load_fixture from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import ClientSessionGenerator @@ -22,12 +23,20 @@ async def test_diagnostics( assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == { "is_available": True, - "general_info": json.loads(load_fixture("general_info.json", "devialet")), - "sources": json.loads(load_fixture("sources.json", "devialet")), - "source_state": json.loads(load_fixture("source_state.json", "devialet")), - "volume": json.loads(load_fixture("volume.json", "devialet")), - "night_mode": json.loads(load_fixture("night_mode.json", "devialet")), - "equalizer": json.loads(load_fixture("equalizer.json", "devialet")), + "general_info": json.loads( + await async_load_fixture(hass, "general_info.json", DOMAIN) + ), + "sources": json.loads(await async_load_fixture(hass, "sources.json", DOMAIN)), + "source_state": json.loads( + await async_load_fixture(hass, "source_state.json", DOMAIN) + ), + "volume": json.loads(await async_load_fixture(hass, "volume.json", DOMAIN)), + "night_mode": json.loads( + await async_load_fixture(hass, "night_mode.json", DOMAIN) + ), + "equalizer": json.loads( + await async_load_fixture(hass, "equalizer.json", DOMAIN) + ), "source_list": [ "Airplay", "Bluetooth", diff --git a/tests/components/efergy/__init__.py b/tests/components/efergy/__init__.py index 36efa77cf45..5dc6a6ddd90 100644 --- a/tests/components/efergy/__init__.py +++ b/tests/components/efergy/__init__.py @@ -9,7 +9,7 @@ from homeassistant.const import CONF_API_KEY from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker TOKEN = "9p6QGJ7dpZfO3fqPTBk1fyEmjV1cGoLT" @@ -63,57 +63,57 @@ async def mock_responses( return aioclient_mock.get( f"{base_url}getStatus?token={token}", - text=load_fixture("efergy/status.json"), + text=await async_load_fixture(hass, "status.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getInstant?token={token}", - text=load_fixture("efergy/instant.json"), + text=await async_load_fixture(hass, "instant.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getEnergy?period=day", - text=load_fixture("efergy/daily_energy.json"), + text=await async_load_fixture(hass, "daily_energy.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getEnergy?period=week", - text=load_fixture("efergy/weekly_energy.json"), + text=await async_load_fixture(hass, "weekly_energy.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getEnergy?period=month", - text=load_fixture("efergy/monthly_energy.json"), + text=await async_load_fixture(hass, "monthly_energy.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getEnergy?period=year", - text=load_fixture("efergy/yearly_energy.json"), + text=await async_load_fixture(hass, "yearly_energy.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getBudget?token={token}", - text=load_fixture("efergy/budget.json"), + text=await async_load_fixture(hass, "budget.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getCost?period=day", - text=load_fixture("efergy/daily_cost.json"), + text=await async_load_fixture(hass, "daily_cost.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getCost?period=week", - text=load_fixture("efergy/weekly_cost.json"), + text=await async_load_fixture(hass, "weekly_cost.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getCost?period=month", - text=load_fixture("efergy/monthly_cost.json"), + text=await async_load_fixture(hass, "monthly_cost.json", DOMAIN), ) aioclient_mock.get( f"{base_url}getCost?period=year", - text=load_fixture("efergy/yearly_cost.json"), + text=await async_load_fixture(hass, "yearly_cost.json", DOMAIN), ) if token == TOKEN: aioclient_mock.get( f"{base_url}getCurrentValuesSummary?token={token}", - text=load_fixture("efergy/current_values_single.json"), + text=await async_load_fixture(hass, "current_values_single.json", DOMAIN), ) else: aioclient_mock.get( f"{base_url}getCurrentValuesSummary?token={token}", - text=load_fixture("efergy/current_values_multi.json"), + text=await async_load_fixture(hass, "current_values_multi.json", DOMAIN), ) diff --git a/tests/components/electrasmart/test_config_flow.py b/tests/components/electrasmart/test_config_flow.py index 6b943014cbc..500377fb702 100644 --- a/tests/components/electrasmart/test_config_flow.py +++ b/tests/components/electrasmart/test_config_flow.py @@ -13,13 +13,15 @@ from homeassistant.components.electrasmart.const import ( from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType -from tests.common import load_fixture +from tests.common import async_load_fixture async def test_form(hass: HomeAssistant) -> None: """Test user config.""" - mock_generate_token = loads(load_fixture("generate_token_response.json", DOMAIN)) + mock_generate_token = loads( + await async_load_fixture(hass, "generate_token_response.json", DOMAIN) + ) with patch( "electrasmart.api.ElectraAPI.generate_new_token", return_value=mock_generate_token, @@ -47,8 +49,12 @@ async def test_form(hass: HomeAssistant) -> None: async def test_one_time_password(hass: HomeAssistant) -> None: """Test one time password.""" - mock_generate_token = loads(load_fixture("generate_token_response.json", DOMAIN)) - mock_otp_response = loads(load_fixture("otp_response.json", DOMAIN)) + mock_generate_token = loads( + await async_load_fixture(hass, "generate_token_response.json", DOMAIN) + ) + mock_otp_response = loads( + await async_load_fixture(hass, "otp_response.json", DOMAIN) + ) with ( patch( "electrasmart.api.ElectraAPI.generate_new_token", @@ -78,7 +84,9 @@ async def test_one_time_password(hass: HomeAssistant) -> None: async def test_one_time_password_api_error(hass: HomeAssistant) -> None: """Test one time password.""" - mock_generate_token = loads(load_fixture("generate_token_response.json", DOMAIN)) + mock_generate_token = loads( + await async_load_fixture(hass, "generate_token_response.json", DOMAIN) + ) with ( patch( "electrasmart.api.ElectraAPI.generate_new_token", @@ -124,7 +132,7 @@ async def test_invalid_phone_number(hass: HomeAssistant) -> None: """Test invalid phone number.""" mock_invalid_phone_number_response = loads( - load_fixture("invalid_phone_number_response.json", DOMAIN) + await async_load_fixture(hass, "invalid_phone_number_response.json", DOMAIN) ) with patch( @@ -147,9 +155,11 @@ async def test_invalid_auth(hass: HomeAssistant) -> None: """Test invalid auth.""" mock_generate_token_response = loads( - load_fixture("generate_token_response.json", DOMAIN) + await async_load_fixture(hass, "generate_token_response.json", DOMAIN) + ) + mock_invalid_otp_response = loads( + await async_load_fixture(hass, "invalid_otp_response.json", DOMAIN) ) - mock_invalid_otp_response = loads(load_fixture("invalid_otp_response.json", DOMAIN)) with ( patch( diff --git a/tests/components/foobot/test_sensor.py b/tests/components/foobot/test_sensor.py index d5461ae71c7..d9d80191075 100644 --- a/tests/components/foobot/test_sensor.py +++ b/tests/components/foobot/test_sensor.py @@ -19,7 +19,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady from homeassistant.setup import async_setup_component -from tests.common import load_fixture +from tests.common import async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker VALID_CONFIG = { @@ -35,11 +35,11 @@ async def test_default_setup( """Test the default setup.""" aioclient_mock.get( re.compile("api.foobot.io/v2/owner/.*"), - text=load_fixture("devices.json", "foobot"), + text=await async_load_fixture(hass, "devices.json", "foobot"), ) aioclient_mock.get( re.compile("api.foobot.io/v2/device/.*"), - text=load_fixture("data.json", "foobot"), + text=await async_load_fixture(hass, "data.json", "foobot"), ) assert await async_setup_component(hass, sensor.DOMAIN, {"sensor": VALID_CONFIG}) await hass.async_block_till_done() diff --git a/tests/components/fully_kiosk/test_config_flow.py b/tests/components/fully_kiosk/test_config_flow.py index 4ce393a417d..2948796f38d 100644 --- a/tests/components/fully_kiosk/test_config_flow.py +++ b/tests/components/fully_kiosk/test_config_flow.py @@ -20,7 +20,7 @@ from homeassistant.data_entry_flow import FlowResultType from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from homeassistant.helpers.service_info.mqtt import MqttServiceInfo -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture async def test_user_flow( @@ -220,7 +220,7 @@ async def test_mqtt_discovery_flow( mock_setup_entry: AsyncMock, ) -> None: """Test MQTT discovery configuration flow.""" - payload = load_fixture("mqtt-discovery-deviceinfo.json", DOMAIN) + payload = await async_load_fixture(hass, "mqtt-discovery-deviceinfo.json", DOMAIN) result = await hass.config_entries.flow.async_init( DOMAIN, diff --git a/tests/components/fully_kiosk/test_init.py b/tests/components/fully_kiosk/test_init.py index f3fb945c8f0..9a095329829 100644 --- a/tests/components/fully_kiosk/test_init.py +++ b/tests/components/fully_kiosk/test_init.py @@ -19,7 +19,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture async def test_load_unload_config_entry( @@ -74,10 +74,10 @@ async def _load_config( ) as client_mock: client = client_mock.return_value client.getDeviceInfo.return_value = json.loads( - load_fixture(device_info_fixture, DOMAIN) + await async_load_fixture(hass, device_info_fixture, DOMAIN) ) client.getSettings.return_value = json.loads( - load_fixture("listsettings.json", DOMAIN) + await async_load_fixture(hass, "listsettings.json", DOMAIN) ) config_entry.add_to_hass(hass) diff --git a/tests/components/gios/__init__.py b/tests/components/gios/__init__.py index 07dbd6502b4..49388428805 100644 --- a/tests/components/gios/__init__.py +++ b/tests/components/gios/__init__.py @@ -6,7 +6,7 @@ from unittest.mock import patch from homeassistant.components.gios.const import DOMAIN from homeassistant.core import HomeAssistant -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture STATIONS = [ {"id": 123, "stationName": "Test Name 1", "gegrLat": "99.99", "gegrLon": "88.88"}, @@ -26,9 +26,9 @@ async def init_integration( entry_id="86129426118ae32020417a53712d6eef", ) - indexes = json.loads(load_fixture("gios/indexes.json")) - station = json.loads(load_fixture("gios/station.json")) - sensors = json.loads(load_fixture("gios/sensors.json")) + indexes = json.loads(await async_load_fixture(hass, "indexes.json", DOMAIN)) + station = json.loads(await async_load_fixture(hass, "station.json", DOMAIN)) + sensors = json.loads(await async_load_fixture(hass, "sensors.json", DOMAIN)) if incomplete_data: indexes["stIndexLevel"]["indexLevelName"] = "foo" sensors["pm10"]["values"][0]["value"] = None diff --git a/tests/components/gios/test_config_flow.py b/tests/components/gios/test_config_flow.py index 3764c52a810..ee783ba57e3 100644 --- a/tests/components/gios/test_config_flow.py +++ b/tests/components/gios/test_config_flow.py @@ -14,7 +14,7 @@ from homeassistant.data_entry_flow import FlowResultType from . import STATIONS -from tests.common import load_fixture +from tests.common import async_load_fixture CONFIG = { CONF_NAME: "Foo", @@ -58,7 +58,9 @@ async def test_invalid_sensor_data(hass: HomeAssistant) -> None: ), patch( "homeassistant.components.gios.coordinator.Gios._get_station", - return_value=json.loads(load_fixture("gios/station.json")), + return_value=json.loads( + await async_load_fixture(hass, "station.json", DOMAIN) + ), ), patch( "homeassistant.components.gios.coordinator.Gios._get_sensor", @@ -106,15 +108,21 @@ async def test_create_entry(hass: HomeAssistant) -> None: ), patch( "homeassistant.components.gios.coordinator.Gios._get_station", - return_value=json.loads(load_fixture("gios/station.json")), + return_value=json.loads( + await async_load_fixture(hass, "station.json", DOMAIN) + ), ), patch( "homeassistant.components.gios.coordinator.Gios._get_all_sensors", - return_value=json.loads(load_fixture("gios/sensors.json")), + return_value=json.loads( + await async_load_fixture(hass, "sensors.json", DOMAIN) + ), ), patch( "homeassistant.components.gios.coordinator.Gios._get_indexes", - return_value=json.loads(load_fixture("gios/indexes.json")), + return_value=json.loads( + await async_load_fixture(hass, "indexes.json", DOMAIN) + ), ), ): flow = config_flow.GiosFlowHandler() diff --git a/tests/components/gios/test_init.py b/tests/components/gios/test_init.py index bf954d48548..9c7f7270ca4 100644 --- a/tests/components/gios/test_init.py +++ b/tests/components/gios/test_init.py @@ -12,7 +12,7 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er from . import STATIONS, init_integration -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture async def test_async_setup_entry(hass: HomeAssistant) -> None: @@ -71,9 +71,9 @@ async def test_migrate_device_and_config_entry( }, ) - indexes = json.loads(load_fixture("gios/indexes.json")) - station = json.loads(load_fixture("gios/station.json")) - sensors = json.loads(load_fixture("gios/sensors.json")) + indexes = json.loads(await async_load_fixture(hass, "indexes.json", DOMAIN)) + station = json.loads(await async_load_fixture(hass, "station.json", DOMAIN)) + sensors = json.loads(await async_load_fixture(hass, "sensors.json", DOMAIN)) with ( patch( diff --git a/tests/components/gios/test_sensor.py b/tests/components/gios/test_sensor.py index fd343d16525..b4e03dd7488 100644 --- a/tests/components/gios/test_sensor.py +++ b/tests/components/gios/test_sensor.py @@ -17,7 +17,7 @@ from homeassistant.util.dt import utcnow from . import init_integration -from tests.common import async_fire_time_changed, load_fixture, snapshot_platform +from tests.common import async_fire_time_changed, async_load_fixture, snapshot_platform async def test_sensor( @@ -32,8 +32,8 @@ async def test_sensor( async def test_availability(hass: HomeAssistant) -> None: """Ensure that we mark the entities unavailable correctly when service causes an error.""" - indexes = json.loads(load_fixture("gios/indexes.json")) - sensors = json.loads(load_fixture("gios/sensors.json")) + indexes = json.loads(await async_load_fixture(hass, "indexes.json", DOMAIN)) + sensors = json.loads(await async_load_fixture(hass, "sensors.json", DOMAIN)) await init_integration(hass) diff --git a/tests/components/github/common.py b/tests/components/github/common.py index 5007496c9fe..bf48c313adc 100644 --- a/tests/components/github/common.py +++ b/tests/components/github/common.py @@ -8,7 +8,7 @@ from homeassistant.components.github.const import CONF_REPOSITORIES, DOMAIN from homeassistant.config_entries import ConfigEntryState 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 AiohttpClientMocker MOCK_ACCESS_TOKEN = "gho_16C7e42F292c6912E7710c838347Ae178B4a" @@ -22,12 +22,12 @@ async def setup_github_integration( add_entry_to_hass: bool = True, ) -> None: """Mock setting up the integration.""" - headers = json.loads(load_fixture("base_headers.json", DOMAIN)) + headers = json.loads(await async_load_fixture(hass, "base_headers.json", DOMAIN)) for idx, repository in enumerate(mock_config_entry.options[CONF_REPOSITORIES]): aioclient_mock.get( f"https://api.github.com/repos/{repository}", json={ - **json.loads(load_fixture("repository.json", DOMAIN)), + **json.loads(await async_load_fixture(hass, "repository.json", DOMAIN)), "full_name": repository, "id": idx, }, @@ -40,7 +40,7 @@ async def setup_github_integration( ) aioclient_mock.post( "https://api.github.com/graphql", - json=json.loads(load_fixture("graphql.json", DOMAIN)), + json=json.loads(await async_load_fixture(hass, "graphql.json", DOMAIN)), headers=headers, ) if add_entry_to_hass: diff --git a/tests/components/github/test_diagnostics.py b/tests/components/github/test_diagnostics.py index 806a0ae33cc..2bf8e4ae1b5 100644 --- a/tests/components/github/test_diagnostics.py +++ b/tests/components/github/test_diagnostics.py @@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant from .common import setup_github_integration -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import ClientSessionGenerator @@ -30,13 +30,13 @@ async def test_entry_diagnostics( mock_config_entry, options={CONF_REPOSITORIES: ["home-assistant/core"]}, ) - response_json = json.loads(load_fixture("graphql.json", DOMAIN)) + response_json = json.loads(await async_load_fixture(hass, "graphql.json", DOMAIN)) response_json["data"]["repository"]["full_name"] = "home-assistant/core" aioclient_mock.post( "https://api.github.com/graphql", json=response_json, - headers=json.loads(load_fixture("base_headers.json", DOMAIN)), + headers=json.loads(await async_load_fixture(hass, "base_headers.json", DOMAIN)), ) aioclient_mock.get( "https://api.github.com/rate_limit", diff --git a/tests/components/github/test_sensor.py b/tests/components/github/test_sensor.py index b0eaed3ae0e..ada663d941f 100644 --- a/tests/components/github/test_sensor.py +++ b/tests/components/github/test_sensor.py @@ -10,7 +10,7 @@ from homeassistant.util import dt as dt_util from .common import TEST_REPOSITORY -from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture +from tests.common import MockConfigEntry, async_fire_time_changed, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker TEST_SENSOR_ENTITY = "sensor.octocat_hello_world_latest_release" @@ -27,9 +27,9 @@ async def test_sensor_updates_with_empty_release_array( state = hass.states.get(TEST_SENSOR_ENTITY) assert state.state == "v1.0.0" - response_json = json.loads(load_fixture("graphql.json", DOMAIN)) + response_json = json.loads(await async_load_fixture(hass, "graphql.json", DOMAIN)) response_json["data"]["repository"]["release"] = None - headers = json.loads(load_fixture("base_headers.json", DOMAIN)) + headers = json.loads(await async_load_fixture(hass, "base_headers.json", DOMAIN)) aioclient_mock.clear_requests() aioclient_mock.get( diff --git a/tests/components/goalzero/__init__.py b/tests/components/goalzero/__init__.py index 7d86f638fc2..1e7f40cc20a 100644 --- a/tests/components/goalzero/__init__.py +++ b/tests/components/goalzero/__init__.py @@ -8,7 +8,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker HOST = "1.2.3.4" @@ -66,11 +66,11 @@ async def async_init_integration( base_url = f"http://{HOST}/" aioclient_mock.get( f"{base_url}state", - text=load_fixture("goalzero/state_data.json"), + text=await async_load_fixture(hass, "state_data.json", DOMAIN), ) aioclient_mock.get( f"{base_url}sysinfo", - text=load_fixture("goalzero/info_data.json"), + text=await async_load_fixture(hass, "info_data.json", DOMAIN), ) if not skip_setup: diff --git a/tests/components/goalzero/test_switch.py b/tests/components/goalzero/test_switch.py index b784cff05aa..d6faa7518a9 100644 --- a/tests/components/goalzero/test_switch.py +++ b/tests/components/goalzero/test_switch.py @@ -1,6 +1,6 @@ """Switch tests for the Goalzero integration.""" -from homeassistant.components.goalzero.const import DEFAULT_NAME +from homeassistant.components.goalzero.const import DEFAULT_NAME, DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, @@ -13,7 +13,7 @@ from homeassistant.core import HomeAssistant from . import async_init_integration -from tests.common import load_fixture +from tests.common import async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker @@ -29,7 +29,7 @@ async def test_switches_states( assert hass.states.get(entity_id).state == STATE_OFF aioclient_mock.post( "http://1.2.3.4/state", - text=load_fixture("goalzero/state_change.json"), + text=await async_load_fixture(hass, "state_change.json", DOMAIN), ) await hass.services.async_call( SWITCH_DOMAIN, @@ -41,7 +41,7 @@ async def test_switches_states( aioclient_mock.clear_requests() aioclient_mock.post( "http://1.2.3.4/state", - text=load_fixture("goalzero/state_data.json"), + text=await async_load_fixture(hass, "state_data.json", DOMAIN), ) await hass.services.async_call( SWITCH_DOMAIN, diff --git a/tests/components/google_mail/conftest.py b/tests/components/google_mail/conftest.py index 7e63282d181..3336d905bc1 100644 --- a/tests/components/google_mail/conftest.py +++ b/tests/components/google_mail/conftest.py @@ -16,7 +16,7 @@ from homeassistant.components.google_mail.const import DOMAIN from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker type ComponentSetup = Callable[[], Awaitable[None]] @@ -112,7 +112,10 @@ async def mock_setup_integration( "httplib2.Http.request", return_value=( Response({}), - bytes(load_fixture("google_mail/get_vacation.json"), encoding="UTF-8"), + bytes( + await async_load_fixture(hass, "get_vacation.json", DOMAIN), + encoding="UTF-8", + ), ), ): assert await async_setup_component(hass, DOMAIN, {}) diff --git a/tests/components/google_mail/test_config_flow.py b/tests/components/google_mail/test_config_flow.py index 1e933c8932a..8b8aaa57871 100644 --- a/tests/components/google_mail/test_config_flow.py +++ b/tests/components/google_mail/test_config_flow.py @@ -13,7 +13,7 @@ from homeassistant.helpers import config_entry_oauth2_flow from .conftest import CLIENT_ID, GOOGLE_AUTH_URI, GOOGLE_TOKEN_URI, SCOPES, TITLE -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import ClientSessionGenerator @@ -54,7 +54,10 @@ async def test_full_flow( "httplib2.Http.request", return_value=( Response({}), - bytes(load_fixture("google_mail/get_profile.json"), encoding="UTF-8"), + bytes( + await async_load_fixture(hass, "get_profile.json", DOMAIN), + encoding="UTF-8", + ), ), ), ): @@ -152,7 +155,10 @@ async def test_reauth( "httplib2.Http.request", return_value=( Response({}), - bytes(load_fixture(f"google_mail/{fixture}.json"), encoding="UTF-8"), + bytes( + await async_load_fixture(hass, f"{fixture}.json", DOMAIN), + encoding="UTF-8", + ), ), ), ): @@ -208,7 +214,10 @@ async def test_already_configured( "httplib2.Http.request", return_value=( Response({}), - bytes(load_fixture("google_mail/get_profile.json"), encoding="UTF-8"), + bytes( + await async_load_fixture(hass, "get_profile.json", DOMAIN), + encoding="UTF-8", + ), ), ): result = await hass.config_entries.flow.async_configure(result["flow_id"]) diff --git a/tests/components/google_mail/test_sensor.py b/tests/components/google_mail/test_sensor.py index e9dd2da85de..3b88cb327ed 100644 --- a/tests/components/google_mail/test_sensor.py +++ b/tests/components/google_mail/test_sensor.py @@ -16,7 +16,7 @@ from homeassistant.util import dt as dt_util from .conftest import SENSOR, TOKEN, ComponentSetup -from tests.common import async_fire_time_changed, load_fixture +from tests.common import async_fire_time_changed, async_load_fixture @pytest.mark.parametrize( @@ -41,7 +41,10 @@ async def test_sensors( "httplib2.Http.request", return_value=( Response({}), - bytes(load_fixture(f"google_mail/{fixture}.json"), encoding="UTF-8"), + bytes( + await async_load_fixture(hass, f"{fixture}.json", DOMAIN), + encoding="UTF-8", + ), ), ): next_update = dt_util.utcnow() + timedelta(minutes=15) diff --git a/tests/components/google_tasks/test_config_flow.py b/tests/components/google_tasks/test_config_flow.py index f8ccc5e048f..ae765d0ab79 100644 --- a/tests/components/google_tasks/test_config_flow.py +++ b/tests/components/google_tasks/test_config_flow.py @@ -17,7 +17,7 @@ from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from homeassistant.helpers import config_entry_oauth2_flow -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import ClientSessionGenerator @@ -145,7 +145,10 @@ async def test_api_not_enabled( "homeassistant.components.google_tasks.config_flow.build", side_effect=HttpError( Response({"status": "403"}), - bytes(load_fixture("google_tasks/api_not_enabled_response.json"), "utf-8"), + bytes( + await async_load_fixture(hass, "api_not_enabled_response.json", DOMAIN), + "utf-8", + ), ), ): result = await hass.config_entries.flow.async_configure(result["flow_id"]) diff --git a/tests/components/habitica/conftest.py b/tests/components/habitica/conftest.py index fa2b65af6c3..80e09d823cc 100644 --- a/tests/components/habitica/conftest.py +++ b/tests/components/habitica/conftest.py @@ -1,6 +1,6 @@ """Tests for the habitica component.""" -from collections.abc import Generator +from collections.abc import AsyncGenerator, Generator from unittest.mock import AsyncMock, MagicMock, patch from uuid import UUID @@ -32,7 +32,7 @@ from homeassistant.components.habitica.const import CONF_API_USER, DEFAULT_URL, from homeassistant.const import CONF_API_KEY, CONF_URL from homeassistant.core import HomeAssistant -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture, load_fixture ERROR_RESPONSE = HabiticaErrorResponse(success=False, error="error", message="reason") ERROR_NOT_AUTHORIZED = NotAuthorizedError(error=ERROR_RESPONSE, headers={}) @@ -75,7 +75,7 @@ def mock_get_tasks(task_type: TaskFilter | None = None) -> HabiticaTasksResponse @pytest.fixture(name="habitica") -async def mock_habiticalib() -> Generator[AsyncMock]: +async def mock_habiticalib(hass: HomeAssistant) -> AsyncGenerator[AsyncMock]: """Mock habiticalib.""" with ( @@ -89,24 +89,24 @@ async def mock_habiticalib() -> Generator[AsyncMock]: client = mock_client.return_value client.login.return_value = HabiticaLoginResponse.from_json( - load_fixture("login.json", DOMAIN) + await async_load_fixture(hass, "login.json", DOMAIN) ) client.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture("user.json", DOMAIN) + await async_load_fixture(hass, "user.json", DOMAIN) ) client.cast_skill.return_value = HabiticaCastSkillResponse.from_json( - load_fixture("cast_skill_response.json", DOMAIN) + await async_load_fixture(hass, "cast_skill_response.json", DOMAIN) ) client.toggle_sleep.return_value = HabiticaSleepResponse( success=True, data=True ) client.update_score.return_value = HabiticaUserResponse.from_json( - load_fixture("score_with_drop.json", DOMAIN) + await async_load_fixture(hass, "score_with_drop.json", DOMAIN) ) client.get_group_members.return_value = HabiticaGroupMembersResponse.from_json( - load_fixture("party_members.json", DOMAIN) + await async_load_fixture(hass, "party_members.json", DOMAIN) ) for func in ( "leave_quest", @@ -117,20 +117,20 @@ async def mock_habiticalib() -> Generator[AsyncMock]: "accept_quest", ): getattr(client, func).return_value = HabiticaQuestResponse.from_json( - load_fixture("party_quest.json", DOMAIN) + await async_load_fixture(hass, "party_quest.json", DOMAIN) ) client.get_content.return_value = HabiticaContentResponse.from_json( - load_fixture("content.json", DOMAIN) + await async_load_fixture(hass, "content.json", DOMAIN) ) client.get_tasks.side_effect = mock_get_tasks client.update_score.return_value = HabiticaScoreResponse.from_json( - load_fixture("score_with_drop.json", DOMAIN) + await async_load_fixture(hass, "score_with_drop.json", DOMAIN) ) client.update_task.return_value = HabiticaTaskResponse.from_json( - load_fixture("task.json", DOMAIN) + await async_load_fixture(hass, "task.json", DOMAIN) ) client.create_task.return_value = HabiticaTaskResponse.from_json( - load_fixture("task.json", DOMAIN) + await async_load_fixture(hass, "task.json", DOMAIN) ) client.delete_task.return_value = HabiticaResponse.from_dict( {"data": {}, "success": True} @@ -143,17 +143,17 @@ async def mock_habiticalib() -> Generator[AsyncMock]: ) client.get_user_anonymized.return_value = ( HabiticaUserAnonymizedResponse.from_json( - load_fixture("anonymized.json", DOMAIN) + await async_load_fixture(hass, "anonymized.json", DOMAIN) ) ) client.update_task.return_value = HabiticaTaskResponse.from_json( - load_fixture("task.json", DOMAIN) + await async_load_fixture(hass, "task.json", DOMAIN) ) client.create_tag.return_value = HabiticaTagResponse.from_json( - load_fixture("create_tag.json", DOMAIN) + await async_load_fixture(hass, "create_tag.json", DOMAIN) ) client.create_task.return_value = HabiticaTaskResponse.from_json( - load_fixture("task.json", DOMAIN) + await async_load_fixture(hass, "task.json", DOMAIN) ) yield client diff --git a/tests/components/habitica/test_binary_sensor.py b/tests/components/habitica/test_binary_sensor.py index 80acc92385f..7fe7a116c7b 100644 --- a/tests/components/habitica/test_binary_sensor.py +++ b/tests/components/habitica/test_binary_sensor.py @@ -13,7 +13,7 @@ from homeassistant.const import STATE_OFF, STATE_ON, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -from tests.common import MockConfigEntry, load_fixture, snapshot_platform +from tests.common import MockConfigEntry, async_load_fixture, snapshot_platform @pytest.fixture(autouse=True) @@ -62,7 +62,7 @@ async def test_pending_quest_states( """Test states of pending quest sensor.""" habitica.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture(f"{fixture}.json", DOMAIN) + await async_load_fixture(hass, f"{fixture}.json", DOMAIN) ) config_entry.add_to_hass(hass) diff --git a/tests/components/habitica/test_button.py b/tests/components/habitica/test_button.py index dc1a155b541..6e7ccbd3424 100644 --- a/tests/components/habitica/test_button.py +++ b/tests/components/habitica/test_button.py @@ -23,7 +23,7 @@ from .conftest import ERROR_BAD_REQUEST, ERROR_NOT_AUTHORIZED, ERROR_TOO_MANY_RE from tests.common import ( MockConfigEntry, async_fire_time_changed, - load_fixture, + async_load_fixture, snapshot_platform, ) @@ -58,7 +58,7 @@ async def test_buttons( """Test button entities.""" habitica.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture(f"{fixture}.json", DOMAIN) + await async_load_fixture(hass, f"{fixture}.json", DOMAIN) ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -167,7 +167,7 @@ async def test_button_press( """Test button press method.""" habitica.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture(f"{fixture}.json", DOMAIN) + await async_load_fixture(hass, f"{fixture}.json", DOMAIN) ) config_entry.add_to_hass(hass) @@ -321,7 +321,7 @@ async def test_button_unavailable( """Test buttons are unavailable if conditions are not met.""" habitica.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture(f"{fixture}.json", DOMAIN) + await async_load_fixture(hass, f"{fixture}.json", DOMAIN) ) config_entry.add_to_hass(hass) @@ -355,7 +355,7 @@ async def test_class_change( ] habitica.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture("wizard_fixture.json", DOMAIN) + await async_load_fixture(hass, "wizard_fixture.json", DOMAIN) ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -367,7 +367,7 @@ async def test_class_change( assert hass.states.get(skill) habitica.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture("healer_fixture.json", DOMAIN) + await async_load_fixture(hass, "healer_fixture.json", DOMAIN) ) freezer.tick(timedelta(seconds=60)) async_fire_time_changed(hass) diff --git a/tests/components/habitica/test_image.py b/tests/components/habitica/test_image.py index 17089f57bd7..42a87d21a8a 100644 --- a/tests/components/habitica/test_image.py +++ b/tests/components/habitica/test_image.py @@ -18,7 +18,7 @@ from homeassistant.config_entries import ConfigEntryState from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture +from tests.common import MockConfigEntry, async_fire_time_changed, async_load_fixture from tests.typing import ClientSessionGenerator @@ -81,7 +81,7 @@ async def test_image_platform( ) habitica.get_user.return_value = HabiticaUserResponse.from_json( - load_fixture("rogue_fixture.json", DOMAIN) + await async_load_fixture(hass, "rogue_fixture.json", DOMAIN) ) freezer.tick(timedelta(seconds=60)) diff --git a/tests/components/habitica/test_services.py b/tests/components/habitica/test_services.py index 774593fa0f6..0e2a99ce215 100644 --- a/tests/components/habitica/test_services.py +++ b/tests/components/habitica/test_services.py @@ -89,7 +89,7 @@ from .conftest import ( ERROR_TOO_MANY_REQUESTS, ) -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture REQUEST_EXCEPTION_MSG = "Unable to connect to Habitica: reason" RATE_LIMIT_EXCEPTION_MSG = "Rate limit exceeded, try again in 5 seconds" @@ -1111,7 +1111,7 @@ async def test_update_reward( task_id = "5e2ea1df-f6e6-4ba3-bccb-97c5ec63e99b" habitica.update_task.return_value = HabiticaTaskResponse.from_json( - load_fixture("task.json", DOMAIN) + await async_load_fixture(hass, "task.json", DOMAIN) ) await hass.services.async_call( DOMAIN, diff --git a/tests/components/habitica/test_todo.py b/tests/components/habitica/test_todo.py index 3457af78403..0761ce19712 100644 --- a/tests/components/habitica/test_todo.py +++ b/tests/components/habitica/test_todo.py @@ -37,7 +37,7 @@ from .conftest import ERROR_NOT_FOUND, ERROR_TOO_MANY_REQUESTS from tests.common import ( MockConfigEntry, async_get_persistent_notifications, - load_fixture, + async_load_fixture, snapshot_platform, ) from tests.typing import WebSocketGenerator @@ -642,7 +642,7 @@ async def test_move_todo_item( ) -> None: """Test move todo items.""" reorder_response = HabiticaTaskOrderResponse.from_json( - load_fixture(fixture, DOMAIN) + await async_load_fixture(hass, fixture, DOMAIN) ) habitica.reorder_task.return_value = reorder_response config_entry.add_to_hass(hass) @@ -788,7 +788,9 @@ async def test_next_due_date( dailies_entity = "todo.test_user_dailies" habitica.get_tasks.side_effect = [ - HabiticaTasksResponse.from_json(load_fixture(fixture, DOMAIN)), + HabiticaTasksResponse.from_json( + await async_load_fixture(hass, fixture, DOMAIN) + ), HabiticaTasksResponse.from_dict({"success": True, "data": []}), ] diff --git a/tests/components/homeassistant_alerts/test_init.py b/tests/components/homeassistant_alerts/test_init.py index 0a38778bbee..2dd3b4b1e4a 100644 --- a/tests/components/homeassistant_alerts/test_init.py +++ b/tests/components/homeassistant_alerts/test_init.py @@ -21,7 +21,7 @@ from homeassistant.core import HomeAssistant from homeassistant.setup import ATTR_COMPONENT, async_setup_component from homeassistant.util import dt as dt_util -from tests.common import async_fire_time_changed, load_fixture +from tests.common import async_fire_time_changed, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import WebSocketGenerator @@ -108,7 +108,7 @@ async def test_alerts( aioclient_mock.clear_requests() aioclient_mock.get( "https://alerts.home-assistant.io/alerts.json", - text=load_fixture("alerts_1.json", "homeassistant_alerts"), + text=await async_load_fixture(hass, "alerts_1.json", DOMAIN), ) for alert in expected_alerts: stub_alert(aioclient_mock, alert[0]) @@ -159,7 +159,7 @@ async def test_alerts( "breaks_in_ha_version": None, "created": ANY, "dismissed_version": None, - "domain": "homeassistant_alerts", + "domain": DOMAIN, "ignored": False, "is_fixable": False, "issue_id": f"{alert_id}.markdown_{integration}", @@ -305,7 +305,7 @@ async def test_alerts_refreshed_on_component_load( aioclient_mock.clear_requests() aioclient_mock.get( "https://alerts.home-assistant.io/alerts.json", - text=load_fixture("alerts_1.json", "homeassistant_alerts"), + text=await async_load_fixture(hass, "alerts_1.json", DOMAIN), ) for alert in initial_alerts: stub_alert(aioclient_mock, alert[0]) @@ -342,7 +342,7 @@ async def test_alerts_refreshed_on_component_load( "breaks_in_ha_version": None, "created": ANY, "dismissed_version": None, - "domain": "homeassistant_alerts", + "domain": DOMAIN, "ignored": False, "is_fixable": False, "issue_id": f"{alert}.markdown_{integration}", @@ -391,7 +391,7 @@ async def test_alerts_refreshed_on_component_load( "breaks_in_ha_version": None, "created": ANY, "dismissed_version": None, - "domain": "homeassistant_alerts", + "domain": DOMAIN, "ignored": False, "is_fixable": False, "issue_id": f"{alert}.markdown_{integration}", @@ -438,7 +438,7 @@ async def test_bad_alerts( expected_alerts: list[tuple[str, str]], ) -> None: """Test creating issues based on alerts.""" - fixture_content = load_fixture(fixture, "homeassistant_alerts") + fixture_content = await async_load_fixture(hass, fixture, DOMAIN) aioclient_mock.clear_requests() aioclient_mock.get( "https://alerts.home-assistant.io/alerts.json", @@ -472,7 +472,7 @@ async def test_bad_alerts( "breaks_in_ha_version": None, "created": ANY, "dismissed_version": None, - "domain": "homeassistant_alerts", + "domain": DOMAIN, "ignored": False, "is_fixable": False, "issue_id": f"{alert_id}.markdown_{integration}", @@ -589,7 +589,7 @@ async def test_alerts_change( expected_alerts_2: list[tuple[str, str]], ) -> None: """Test creating issues based on alerts.""" - fixture_1_content = load_fixture(fixture_1, "homeassistant_alerts") + fixture_1_content = await async_load_fixture(hass, fixture_1, DOMAIN) aioclient_mock.clear_requests() aioclient_mock.get( "https://alerts.home-assistant.io/alerts.json", @@ -633,7 +633,7 @@ async def test_alerts_change( "breaks_in_ha_version": None, "created": ANY, "dismissed_version": None, - "domain": "homeassistant_alerts", + "domain": DOMAIN, "ignored": False, "is_fixable": False, "issue_id": f"{alert_id}.markdown_{integration}", @@ -650,7 +650,7 @@ async def test_alerts_change( ] ) - fixture_2_content = load_fixture(fixture_2, "homeassistant_alerts") + fixture_2_content = await async_load_fixture(hass, fixture_2, DOMAIN) aioclient_mock.clear_requests() aioclient_mock.get( "https://alerts.home-assistant.io/alerts.json", @@ -672,7 +672,7 @@ async def test_alerts_change( "breaks_in_ha_version": None, "created": ANY, "dismissed_version": None, - "domain": "homeassistant_alerts", + "domain": DOMAIN, "ignored": False, "is_fixable": False, "issue_id": f"{alert_id}.markdown_{integration}", diff --git a/tests/components/homekit/test_iidmanager.py b/tests/components/homekit/test_iidmanager.py index 39d2dda8237..592b229f95a 100644 --- a/tests/components/homekit/test_iidmanager.py +++ b/tests/components/homekit/test_iidmanager.py @@ -12,7 +12,7 @@ from homeassistant.core import HomeAssistant from homeassistant.util.json import json_loads from homeassistant.util.uuid import random_uuid_hex -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture async def test_iid_generation_and_restore( @@ -108,8 +108,8 @@ async def test_iid_migration_to_v2( hass: HomeAssistant, iid_storage, hass_storage: dict[str, Any] ) -> None: """Test iid storage migration.""" - v1_iids = json_loads(load_fixture("iids_v1", DOMAIN)) - v2_iids = json_loads(load_fixture("iids_v2", DOMAIN)) + v1_iids = json_loads(await async_load_fixture(hass, "iids_v1", DOMAIN)) + v2_iids = json_loads(await async_load_fixture(hass, "iids_v2", DOMAIN)) hass_storage["homekit.v1.iids"] = v1_iids hass_storage["homekit.v2.iids"] = v2_iids @@ -132,8 +132,12 @@ async def test_iid_migration_to_v2_with_underscore( hass: HomeAssistant, iid_storage, hass_storage: dict[str, Any] ) -> None: """Test iid storage migration with underscore.""" - v1_iids = json_loads(load_fixture("iids_v1_with_underscore", DOMAIN)) - v2_iids = json_loads(load_fixture("iids_v2_with_underscore", DOMAIN)) + v1_iids = json_loads( + await async_load_fixture(hass, "iids_v1_with_underscore", DOMAIN) + ) + v2_iids = json_loads( + await async_load_fixture(hass, "iids_v2_with_underscore", DOMAIN) + ) hass_storage["homekit.v1_with_underscore.iids"] = v1_iids hass_storage["homekit.v2_with_underscore.iids"] = v2_iids diff --git a/tests/components/husqvarna_automower/test_config_flow.py b/tests/components/husqvarna_automower/test_config_flow.py index d91078d80a2..9c5c040d456 100644 --- a/tests/components/husqvarna_automower/test_config_flow.py +++ b/tests/components/husqvarna_automower/test_config_flow.py @@ -20,7 +20,7 @@ from homeassistant.helpers import config_entry_oauth2_flow from . import setup_integration from .const import CLIENT_ID, USER_ID -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import ClientSessionGenerator @@ -84,7 +84,7 @@ async def test_full_flow( ) aioclient_mock.get( f"{API_BASE_URL}/{AutomowerEndpoint.mowers}", - text=load_fixture(fixture, DOMAIN), + text=await async_load_fixture(hass, fixture, DOMAIN), exc=exception, ) with ( diff --git a/tests/components/insteon/test_api_config.py b/tests/components/insteon/test_api_config.py index 9c85ca6a706..9d38b70c850 100644 --- a/tests/components/insteon/test_api_config.py +++ b/tests/components/insteon/test_api_config.py @@ -10,6 +10,7 @@ from homeassistant.components.insteon.const import ( CONF_HUB_VERSION, CONF_OVERRIDE, CONF_X10, + DOMAIN, ) from homeassistant.core import HomeAssistant @@ -24,7 +25,7 @@ from .mock_connection import mock_failed_connection, mock_successful_connection from .mock_devices import MockDevices from .mock_setup import async_mock_setup -from tests.common import load_fixture +from tests.common import async_load_fixture from tests.typing import WebSocketGenerator @@ -404,7 +405,7 @@ async def test_get_broken_links( ws_client, _, _, _ = await async_mock_setup(hass, hass_ws_client) devices = MockDevices() await devices.async_load() - aldb_data = json.loads(load_fixture("insteon/aldb_data.json")) + aldb_data = json.loads(await async_load_fixture(hass, "aldb_data.json", DOMAIN)) devices.fill_aldb("33.33.33", aldb_data) await asyncio.sleep(1) with patch.object(insteon.api.config, "devices", devices): diff --git a/tests/components/ipp/conftest.py b/tests/components/ipp/conftest.py index 9a47cc3c355..54b8ed60452 100644 --- a/tests/components/ipp/conftest.py +++ b/tests/components/ipp/conftest.py @@ -17,7 +17,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant -from tests.common import MockConfigEntry, load_fixture +from tests.common import MockConfigEntry, async_load_fixture @pytest.fixture @@ -49,6 +49,7 @@ def mock_setup_entry() -> Generator[AsyncMock]: @pytest.fixture async def mock_printer( + hass: HomeAssistant, request: pytest.FixtureRequest, ) -> Printer: """Return the mocked printer.""" @@ -56,7 +57,7 @@ async def mock_printer( if hasattr(request, "param") and request.param: fixture = request.param - return Printer.from_dict(json.loads(load_fixture(fixture))) + return Printer.from_dict(json.loads(await async_load_fixture(hass, fixture))) @pytest.fixture