Remove deprecated event_loop fixtures in tests (#109048)

pull/105955/head
Marc Mueller 2024-01-29 14:24:58 +01:00 committed by GitHub
parent dbc568cd53
commit 030727b078
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 18 additions and 32 deletions

View File

@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant
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."""
await async_setup_component(hass, "config", {})
assert "config" in hass.config.components

View File

@ -40,7 +40,7 @@ class FidoClientMockError(FidoClientMock):
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."""
with patch("homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock):
config = {

View File

@ -116,7 +116,7 @@ def mock_dev_track(mock_device_tracker_conf):
@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)."""
assert await async_setup_component(
@ -129,7 +129,7 @@ async def geofency_client(event_loop, hass, hass_client_no_auth):
@pytest.fixture(autouse=True)
async def setup_zones(event_loop, hass):
async def setup_zones(hass):
"""Set up Zone config in HA."""
assert await async_setup_component(
hass,

View File

@ -25,7 +25,7 @@ def mock_dev_track(mock_device_tracker_conf):
@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)."""
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)
async def setup_zones(event_loop, hass):
async def setup_zones(hass):
"""Set up Zone config in HA."""
assert await async_setup_component(
hass,

View File

@ -1,4 +1,5 @@
"""Test security filter middleware."""
import asyncio
from http import HTTPStatus
from aiohttp import web
@ -75,7 +76,6 @@ async def test_bad_requests(
fail_on_query_string,
aiohttp_client: ClientSessionGenerator,
caplog: pytest.LogCaptureFixture,
event_loop,
) -> None:
"""Test request paths that should be filtered."""
app = web.Application()
@ -93,7 +93,7 @@ async def test_bad_requests(
man_params = ""
http = urllib3.PoolManager()
resp = await event_loop.run_in_executor(
resp = await asyncio.get_running_loop().run_in_executor(
None,
http.request,
"GET",
@ -126,7 +126,6 @@ async def test_bad_requests_with_unsafe_bytes(
fail_on_query_string,
aiohttp_client: ClientSessionGenerator,
caplog: pytest.LogCaptureFixture,
event_loop,
) -> None:
"""Test request with unsafe bytes in their URLs."""
app = web.Application()
@ -144,7 +143,7 @@ async def test_bad_requests_with_unsafe_bytes(
man_params = ""
http = urllib3.PoolManager()
resp = await event_loop.run_in_executor(
resp = await asyncio.get_running_loop().run_in_executor(
None,
http.request,
"GET",

View File

@ -20,7 +20,7 @@ def mock_dev_track(mock_device_tracker_conf):
@pytest.fixture
async def locative_client(event_loop, hass, hass_client):
async def locative_client(hass, hass_client):
"""Locative mock client."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()

View File

@ -99,7 +99,7 @@ def test_validate_or_move_away_sqlite_database(
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:
"""Test we can check if the last recorder run was recently clean."""
config = {

View File

@ -25,7 +25,7 @@ def mock_dev_track(mock_device_tracker_conf):
@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)."""
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)
async def setup_zones(event_loop, hass):
async def setup_zones(hass):
"""Set up Zone config in HA."""
assert await async_setup_component(
hass,

View File

@ -517,14 +517,13 @@ def hass_fixture_setup() -> list[bool]:
@pytest.fixture
async def hass(
hass_fixture_setup: list[bool],
event_loop: asyncio.AbstractEventLoop,
load_registries: bool,
hass_storage: dict[str, Any],
request: pytest.FixtureRequest,
) -> AsyncGenerator[HomeAssistant, None]:
"""Create a test instance of Home Assistant."""
loop = event_loop
loop = asyncio.get_running_loop()
hass_fixture_setup.append(True)
orig_tz = dt_util.DEFAULT_TIME_ZONE
@ -577,12 +576,11 @@ async def hass(
@pytest.fixture
async def stop_hass(
event_loop: asyncio.AbstractEventLoop,
) -> AsyncGenerator[None, None]:
async def stop_hass() -> AsyncGenerator[None, None]:
"""Make sure all hass are stopped."""
orig_hass = ha.HomeAssistant
event_loop = asyncio.get_running_loop()
created = []
def mock_hass(*args):

View File

@ -480,7 +480,6 @@ async def test_setup_hass(
mock_ensure_config_exists: AsyncMock,
mock_process_ha_config_upgrade: Mock,
caplog: pytest.LogCaptureFixture,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
verbose = Mock()
@ -530,7 +529,6 @@ async def test_setup_hass_takes_longer_than_log_slow_startup(
mock_ensure_config_exists: AsyncMock,
mock_process_ha_config_upgrade: Mock,
caplog: pytest.LogCaptureFixture,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
verbose = Mock()
@ -569,7 +567,6 @@ async def test_setup_hass_invalid_yaml(
mock_mount_local_lib_path: AsyncMock,
mock_ensure_config_exists: AsyncMock,
mock_process_ha_config_upgrade: Mock,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
with patch(
@ -597,7 +594,6 @@ async def test_setup_hass_config_dir_nonexistent(
mock_mount_local_lib_path: AsyncMock,
mock_ensure_config_exists: AsyncMock,
mock_process_ha_config_upgrade: Mock,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
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_ensure_config_exists: AsyncMock,
mock_process_ha_config_upgrade: Mock,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
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_process_ha_config_upgrade: Mock,
caplog: pytest.LogCaptureFixture,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
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_process_ha_config_upgrade: Mock,
caplog: pytest.LogCaptureFixture,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
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_ensure_config_exists: AsyncMock,
mock_process_ha_config_upgrade: Mock,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
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_ensure_config_exists: AsyncMock,
mock_process_ha_config_upgrade: Mock,
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test we setup recovery mode if frontend didn't load."""
verbose = Mock()

View File

@ -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")
async def test_start_taking_too_long(
event_loop, caplog: pytest.LogCaptureFixture
) -> None:
async def test_start_taking_too_long(caplog: pytest.LogCaptureFixture) -> None:
"""Test when async_start takes too long."""
hass = ha.HomeAssistant("/test/ha-config")
caplog.set_level(logging.WARNING)

View File

@ -33,7 +33,7 @@ async def session(hass):
@pytest.fixture
async def raising_session(event_loop):
async def raising_session():
"""Return an aioclient session that only fails."""
return Mock(get=Mock(side_effect=aiohttp.ClientError))