Remove deprecated event_loop fixtures in tests (#109048)
parent
dbc568cd53
commit
030727b078
|
@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
async def test_config_setup(hass: HomeAssistant, event_loop) -> None:
|
async def test_config_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test it sets up hassbian."""
|
"""Test it sets up hassbian."""
|
||||||
await async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
assert "config" in hass.config.components
|
assert "config" in hass.config.components
|
||||||
|
|
|
@ -40,7 +40,7 @@ class FidoClientMockError(FidoClientMock):
|
||||||
raise PyFidoError("Fake Error")
|
raise PyFidoError("Fake Error")
|
||||||
|
|
||||||
|
|
||||||
async def test_fido_sensor(event_loop, hass: HomeAssistant) -> None:
|
async def test_fido_sensor(hass: HomeAssistant) -> None:
|
||||||
"""Test the Fido number sensor."""
|
"""Test the Fido number sensor."""
|
||||||
with patch("homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock):
|
with patch("homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock):
|
||||||
config = {
|
config = {
|
||||||
|
|
|
@ -116,7 +116,7 @@ def mock_dev_track(mock_device_tracker_conf):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def geofency_client(event_loop, hass, hass_client_no_auth):
|
async def geofency_client(hass, hass_client_no_auth):
|
||||||
"""Geofency mock client (unauthenticated)."""
|
"""Geofency mock client (unauthenticated)."""
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
@ -129,7 +129,7 @@ async def geofency_client(event_loop, hass, hass_client_no_auth):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def setup_zones(event_loop, hass):
|
async def setup_zones(hass):
|
||||||
"""Set up Zone config in HA."""
|
"""Set up Zone config in HA."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -25,7 +25,7 @@ def mock_dev_track(mock_device_tracker_conf):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def gpslogger_client(event_loop, hass, hass_client_no_auth):
|
async def gpslogger_client(hass, hass_client_no_auth):
|
||||||
"""Mock client for GPSLogger (unauthenticated)."""
|
"""Mock client for GPSLogger (unauthenticated)."""
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||||
|
@ -37,7 +37,7 @@ async def gpslogger_client(event_loop, hass, hass_client_no_auth):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def setup_zones(event_loop, hass):
|
async def setup_zones(hass):
|
||||||
"""Set up Zone config in HA."""
|
"""Set up Zone config in HA."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Test security filter middleware."""
|
"""Test security filter middleware."""
|
||||||
|
import asyncio
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
@ -75,7 +76,6 @@ async def test_bad_requests(
|
||||||
fail_on_query_string,
|
fail_on_query_string,
|
||||||
aiohttp_client: ClientSessionGenerator,
|
aiohttp_client: ClientSessionGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
event_loop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test request paths that should be filtered."""
|
"""Test request paths that should be filtered."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
|
@ -93,7 +93,7 @@ async def test_bad_requests(
|
||||||
man_params = ""
|
man_params = ""
|
||||||
|
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
resp = await event_loop.run_in_executor(
|
resp = await asyncio.get_running_loop().run_in_executor(
|
||||||
None,
|
None,
|
||||||
http.request,
|
http.request,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -126,7 +126,6 @@ async def test_bad_requests_with_unsafe_bytes(
|
||||||
fail_on_query_string,
|
fail_on_query_string,
|
||||||
aiohttp_client: ClientSessionGenerator,
|
aiohttp_client: ClientSessionGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
event_loop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test request with unsafe bytes in their URLs."""
|
"""Test request with unsafe bytes in their URLs."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
|
@ -144,7 +143,7 @@ async def test_bad_requests_with_unsafe_bytes(
|
||||||
man_params = ""
|
man_params = ""
|
||||||
|
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
resp = await event_loop.run_in_executor(
|
resp = await asyncio.get_running_loop().run_in_executor(
|
||||||
None,
|
None,
|
||||||
http.request,
|
http.request,
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
@ -20,7 +20,7 @@ def mock_dev_track(mock_device_tracker_conf):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def locative_client(event_loop, hass, hass_client):
|
async def locative_client(hass, hass_client):
|
||||||
"""Locative mock client."""
|
"""Locative mock client."""
|
||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
|
@ -99,7 +99,7 @@ def test_validate_or_move_away_sqlite_database(
|
||||||
|
|
||||||
|
|
||||||
async def test_last_run_was_recently_clean(
|
async def test_last_run_was_recently_clean(
|
||||||
event_loop, async_setup_recorder_instance: RecorderInstanceGenerator, tmp_path: Path
|
async_setup_recorder_instance: RecorderInstanceGenerator, tmp_path: Path
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we can check if the last recorder run was recently clean."""
|
"""Test we can check if the last recorder run was recently clean."""
|
||||||
config = {
|
config = {
|
||||||
|
|
|
@ -25,7 +25,7 @@ def mock_dev_track(mock_device_tracker_conf):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="client")
|
@pytest.fixture(name="client")
|
||||||
async def traccar_client(event_loop, hass, hass_client_no_auth):
|
async def traccar_client(hass, hass_client_no_auth):
|
||||||
"""Mock client for Traccar (unauthenticated)."""
|
"""Mock client for Traccar (unauthenticated)."""
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||||
|
@ -37,7 +37,7 @@ async def traccar_client(event_loop, hass, hass_client_no_auth):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def setup_zones(event_loop, hass):
|
async def setup_zones(hass):
|
||||||
"""Set up Zone config in HA."""
|
"""Set up Zone config in HA."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -517,14 +517,13 @@ def hass_fixture_setup() -> list[bool]:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def hass(
|
async def hass(
|
||||||
hass_fixture_setup: list[bool],
|
hass_fixture_setup: list[bool],
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
load_registries: bool,
|
load_registries: bool,
|
||||||
hass_storage: dict[str, Any],
|
hass_storage: dict[str, Any],
|
||||||
request: pytest.FixtureRequest,
|
request: pytest.FixtureRequest,
|
||||||
) -> AsyncGenerator[HomeAssistant, None]:
|
) -> AsyncGenerator[HomeAssistant, None]:
|
||||||
"""Create a test instance of Home Assistant."""
|
"""Create a test instance of Home Assistant."""
|
||||||
|
|
||||||
loop = event_loop
|
loop = asyncio.get_running_loop()
|
||||||
hass_fixture_setup.append(True)
|
hass_fixture_setup.append(True)
|
||||||
|
|
||||||
orig_tz = dt_util.DEFAULT_TIME_ZONE
|
orig_tz = dt_util.DEFAULT_TIME_ZONE
|
||||||
|
@ -577,12 +576,11 @@ async def hass(
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def stop_hass(
|
async def stop_hass() -> AsyncGenerator[None, None]:
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> AsyncGenerator[None, None]:
|
|
||||||
"""Make sure all hass are stopped."""
|
"""Make sure all hass are stopped."""
|
||||||
orig_hass = ha.HomeAssistant
|
orig_hass = ha.HomeAssistant
|
||||||
|
|
||||||
|
event_loop = asyncio.get_running_loop()
|
||||||
created = []
|
created = []
|
||||||
|
|
||||||
def mock_hass(*args):
|
def mock_hass(*args):
|
||||||
|
|
|
@ -480,7 +480,6 @@ async def test_setup_hass(
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
verbose = Mock()
|
verbose = Mock()
|
||||||
|
@ -530,7 +529,6 @@ async def test_setup_hass_takes_longer_than_log_slow_startup(
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
verbose = Mock()
|
verbose = Mock()
|
||||||
|
@ -569,7 +567,6 @@ async def test_setup_hass_invalid_yaml(
|
||||||
mock_mount_local_lib_path: AsyncMock,
|
mock_mount_local_lib_path: AsyncMock,
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -597,7 +594,6 @@ async def test_setup_hass_config_dir_nonexistent(
|
||||||
mock_mount_local_lib_path: AsyncMock,
|
mock_mount_local_lib_path: AsyncMock,
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
mock_ensure_config_exists.return_value = False
|
mock_ensure_config_exists.return_value = False
|
||||||
|
@ -624,7 +620,6 @@ async def test_setup_hass_recovery_mode(
|
||||||
mock_mount_local_lib_path: AsyncMock,
|
mock_mount_local_lib_path: AsyncMock,
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
with patch("homeassistant.components.browser.setup") as browser_setup, patch(
|
with patch("homeassistant.components.browser.setup") as browser_setup, patch(
|
||||||
|
@ -659,7 +654,6 @@ async def test_setup_hass_safe_mode(
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
with patch("homeassistant.components.browser.setup"), patch(
|
with patch("homeassistant.components.browser.setup"), patch(
|
||||||
|
@ -692,7 +686,6 @@ async def test_setup_hass_recovery_mode_and_safe_mode(
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
with patch("homeassistant.components.browser.setup"), patch(
|
with patch("homeassistant.components.browser.setup"), patch(
|
||||||
|
@ -725,7 +718,6 @@ async def test_setup_hass_invalid_core_config(
|
||||||
mock_mount_local_lib_path: AsyncMock,
|
mock_mount_local_lib_path: AsyncMock,
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test it works."""
|
"""Test it works."""
|
||||||
with patch("homeassistant.bootstrap.async_notify_setup_error") as mock_notify:
|
with patch("homeassistant.bootstrap.async_notify_setup_error") as mock_notify:
|
||||||
|
@ -765,7 +757,6 @@ async def test_setup_recovery_mode_if_no_frontend(
|
||||||
mock_mount_local_lib_path: AsyncMock,
|
mock_mount_local_lib_path: AsyncMock,
|
||||||
mock_ensure_config_exists: AsyncMock,
|
mock_ensure_config_exists: AsyncMock,
|
||||||
mock_process_ha_config_upgrade: Mock,
|
mock_process_ha_config_upgrade: Mock,
|
||||||
event_loop: asyncio.AbstractEventLoop,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we setup recovery mode if frontend didn't load."""
|
"""Test we setup recovery mode if frontend didn't load."""
|
||||||
verbose = Mock()
|
verbose = Mock()
|
||||||
|
|
|
@ -1747,9 +1747,7 @@ async def test_bad_timezone_raises_value_error(hass: HomeAssistant) -> None:
|
||||||
await hass.config.async_update(time_zone="not_a_timezone")
|
await hass.config.async_update(time_zone="not_a_timezone")
|
||||||
|
|
||||||
|
|
||||||
async def test_start_taking_too_long(
|
async def test_start_taking_too_long(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
event_loop, caplog: pytest.LogCaptureFixture
|
|
||||||
) -> None:
|
|
||||||
"""Test when async_start takes too long."""
|
"""Test when async_start takes too long."""
|
||||||
hass = ha.HomeAssistant("/test/ha-config")
|
hass = ha.HomeAssistant("/test/ha-config")
|
||||||
caplog.set_level(logging.WARNING)
|
caplog.set_level(logging.WARNING)
|
||||||
|
|
|
@ -33,7 +33,7 @@ async def session(hass):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def raising_session(event_loop):
|
async def raising_session():
|
||||||
"""Return an aioclient session that only fails."""
|
"""Return an aioclient session that only fails."""
|
||||||
return Mock(get=Mock(side_effect=aiohttp.ClientError))
|
return Mock(get=Mock(side_effect=aiohttp.ClientError))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue