Use async_load_fixture in async test functions (b-i) (#145714)

* Use async_load_fixture in async test functions (b-i)

* Adjust
This commit is contained in:
epenet 2025-06-01 15:31:37 +02:00 committed by GitHub
parent a007e8dc26
commit ed9fd2c643
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
40 changed files with 240 additions and 169 deletions

View File

@ -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"

View File

@ -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"][

View File

@ -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"][

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -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,
)

View File

@ -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",

View File

@ -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),
)

View File

@ -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(

View File

@ -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()

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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(

View File

@ -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)

View File

@ -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:

View File

@ -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",

View File

@ -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(

View File

@ -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:

View File

@ -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,

View File

@ -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, {})

View File

@ -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"])

View File

@ -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)

View File

@ -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"])

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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))

View File

@ -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,

View File

@ -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": []}),
]

View File

@ -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}",

View File

@ -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

View File

@ -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 (

View File

@ -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):

View File

@ -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