8000 Use async_load_fixture in remaining tests by epenet · Pull Request #146021 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Use async_load_fixture in remaining tests #146021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tests/components/hassio/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

from .test_init import MOCK_ENVIRON

from tests.common import load_json_object_fixture, mock_platform
from tests.common import async_load_json_object_fixture, mock_platform
from tests.typing import ClientSessionGenerator, WebSocketGenerator

TEST_BACKUP = supervisor_backups.Backup(
Expand Down Expand Up @@ -1018,8 +1018,10 @@ async def test_reader_writer_create_addon_folder_error(
supervisor_client.jobs.get_job.side_effect = [
TEST_JOB_NOT_DONE,
supervisor_jobs.Job.from_dict(
load_json_object_fixture(
"backup_done_with_addon_folder_errors.json", DOMAIN
(
await async_load_json_object_fixture(
hass, "backup_done_with_addon_folder_errors.json", DOMAIN
)
)["data"]
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from .const import DHCP_DATA, DISCOVERY_DATA, HOMEKIT_DATA, MOCK_SERIAL

from tests.common import MockConfigEntry, load_json_object_fixture
from tests.common import MockConfigEntry, async_load_json_object_fixture


@pytest.mark.usefixtures("mock_hunterdouglas_hub")
Expand Down Expand Up @@ -330,7 +330,9 @@ async def test_form_unsupported_device(
# Simulate a gen 3 secondary hub
with patch(
"homeassistant.components.hunterdouglas_powerview.util.Hub.request_raw_data",
return_value=load_json_object_fixture("gen3/gateway/secondary.json", DOMAIN),
return_value=await async_load_json_object_fixture(
hass, "gen3/gateway/secondary.json", DOMAIN
),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand Down
2 changes: 1 addition & 1 deletion tests/components/nexia/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def test_nexia_sensor_switch(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test NexiaRoomIQSensorSwitch."""
await async_init_integration(hass, house_fixture="nexia/sensors_xl1050_house.json")
await async_init_integration(hass, house_fixture="sensors_xl1050_house.json")
sw1_id = f"{Platform.SWITCH}.center_nativezone_include_center"
sw1 = {ATTR_ENTITY_ID: sw1_id}
sw2_id = f"{Platform.SWITCH}.center_nativezone_include_upstairs"
Expand Down
19 changes: 10 additions & 9 deletions tests/components/nexia/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry, load_fixture
from tests.common import MockConfigEntry, async_load_fixture
from tests.test_util.aiohttp import mock_aiohttp_client


Expand All @@ -18,13 +18,13 @@ async def async_init_integration(
skip_setup: bool = False,
exception: Exception | None = None,
*,
house_fixture="nexia/mobile_houses_123456.json",
house_fixture="mobile_houses_123456.json",
) -> MockConfigEntry:
"""Set up the nexia integration in Home Assistant."""

session_fixture = "nexia/session_123456.json"
sign_in_fixture = "nexia/sign_in.json"
set_fan_speed_fixture = "nexia/set_fan_speed_2293892.json"
session_fixture = "session_123456.json"
sign_in_fixture = "sign_in.json"
set_fan_speed_fixture = "set_fan_speed_2293892.json"
with (
mock_aiohttp_client() as mock_session,
patch("nexia.home.load_or_create_uuid", return_value=uuid.uuid4()),
Expand All @@ -40,19 +40,20 @@ async def _raise_exception(*args, **kwargs):
)
else:
mock_session.post(
nexia.API_MOBILE_SESSION_URL, text=load_fixture(session_fixture)
nexia.API_MOBILE_SESSION_URL,
text=await async_load_fixture(hass, session_fixture, DOMAIN),
)
mock_session.get(
nexia.API_MOBILE_HOUSES_URL.format(house_id=123456),
text=load_fixture(house_fixture),
text=await async_load_fixture(hass, house_fixture, DOMAIN),
)
mock_session.post(
nexia.API_MOBILE_ACCOUNTS_SIGN_IN_URL,
text=load_fixture(sign_in_fixture),
text=await async_load_fixture(hass, sign_in_fixture, DOMAIN),
)
mock_session.post(
"https://www.mynexia.com/mobile/xxl_thermostats/2293892/fan_speed",
text=load_fixture(set_fan_speed_fixture),
text=await async_load_fixture(hass, set_fan_speed_fixture, DOMAIN),
)
entry = MockConfigEntry(
domain=DOMAIN,
Expand Down
14 changes: 9 additions & 5 deletions tests/components/nuki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from tests.common import (
MockConfigEntry,
load_json_array_fixture,
load_json_object_fixture,
async_load_json_array_fixture,
async_load_json_object_fixture,
)


Expand All @@ -21,15 +21,19 @@ async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
mock.get("http://1.1.1.1:8080/info", json=MOCK_INFO)
mock.get(
"http://1.1.1.1:8080/list",
json=load_json_array_fixture("list.json", DOMAIN),
json=await async_load_json_array_fixture(hass, "list.json", DOMAIN),
)
mock.get(
"http://1.1.1.1:8080/callback/list",
json=load_json_object_fixture("callback_list.json", DOMAIN),
json=await async_load_json_object_fixture(
hass, "callback_list.json", DOMAIN
),
)
mock.get(
"http://1.1.1.1:8080/callback/add",
json=load_json_object_fixture("callback_add.json", DOMAIN),
json=await async_load_json_object_fixture(
hass, "callback_add.json", DOMAIN
),
)
entry = await setup_nuki_integration(hass)
await hass.config_entries.async_setup(entry.entry_id)
Expand Down
10 changes: 7 additions & 3 deletions tests/components/overkiz/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr

from tests.common import MockConfigEntry, load_json_object_fixture
from tests.common import MockConfigEntry, async_load_json_object_fixture
from tests.components.diagnostics import (
get_diagnostics_for_config_entry,
get_diagnostics_for_device,
Expand All @@ -23,7 +23,9 @@ async def test_diagnostics(
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics."""
diagnostic_data = load_json_object_fixture("overkiz/setup_tahoma_switch.json")
diagnostic_data = await async_load_json_object_fixture(
hass, "setup_tahoma_switch.json", DOMAIN
)

with patch.multiple(
"pyoverkiz.client.OverkizClient",
Expand All @@ -44,7 +46,9 @@ async def test_device_diagnostics(
snapshot: SnapshotAssertion,
) -> None:
"""Test device diagnostics."""
diagnostic_data = load_json_object_fixture("overkiz/setup_tahoma_switch.json")
diagnostic_data = await async_load_json_object_fixture(
hass, "setup_tahoma_switch.json", DOMAIN
)

device = device_registry.async_get_device(
identifiers={(DOMAIN, "rts://****-****-6867/16756006")}
Expand Down
6 changes: 4 additions & 2 deletions tests/components/switchbot_cloud/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from . import configure_integration

from tests.common import load_json_object_fixture, snapshot_platform
from tests.common import async_load_json_object_fixture, snapshot_platform


async def test_meter(
Expand All @@ -33,7 +33,9 @@ async def test_meter(
hubDeviceId="test-hub-id",
),
]
mock_get_status.return_value = load_json_object_fixture("meter_status.json", DOMAIN)
mock_get_status.return_value = await async_load_json_object_fixture(
hass, "meter_status.json", DOMAIN
)

with patch("homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.SENSOR]):
entry = await configure_integration(hass)
Expand Down
16 changes: 11 additions & 5 deletions tests/components/youless/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from tests.common import (
MockConfigEntry,
load_json_array_fixture,
load_json_object_fixture,
async_load_json_array_fixture,
async_load_json_object_fixture,
)


Expand All @@ -18,16 +18,22 @@ async def init_component(hass: HomeAssistant) -> MockConfigEntry:
with requests_mock.Mocker() as mock:
mock.get(
"http://1.1.1.1/d",
json=load_json_object_fixture("device.json", youless.DOMAIN),
json=await async_load_json_object_fixture(
hass, "device.json", youless.DOMAIN
),
)
mock.get(
"http://1.1.1.1/e",
json=load_json_array_fixture("enologic.json", youless.DOMAIN),
json=await async_load_json_array_fixture(
hass, "enologic.json", youless.DOMAIN
),
headers={"Content-Type": "application/json"},
)
mock.get(
"http://1.1.1.1/f",
json=load_json_object_fixture("phase.json", youless.DOMAIN),
json=await async_load_json_object_fixture(
hass, "phase.json", youless.DOMAIN
),
headers={"Content-Type": "application/json"},
)

Expand Down
Loading
0