Convert alexa test fixtures to async (#142054)

This commit is contained in:
Erik Montnemery 2025-04-02 11:00:13 +02:00 committed by GitHub
parent 6b45b0f522
commit e02a6f2f19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 108 additions and 120 deletions

View File

@ -1,6 +1,5 @@
"""The tests for the Alexa component.""" """The tests for the Alexa component."""
from asyncio import AbstractEventLoop
import datetime import datetime
from http import HTTPStatus from http import HTTPStatus
@ -24,13 +23,11 @@ NPR_NEWS_MP3_URL = "https://pd.npr.org/anon.npr-mp3/npr/news/newscast.mp3"
@pytest.fixture @pytest.fixture
def alexa_client( async def alexa_client(
event_loop: AbstractEventLoop,
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
) -> TestClient: ) -> TestClient:
"""Initialize a Home Assistant server for testing this module.""" """Initialize a Home Assistant server for testing this module."""
loop = event_loop
@callback @callback
def mock_service(call): def mock_service(call):
@ -38,8 +35,7 @@ def alexa_client(
hass.services.async_register("test", "alexa", mock_service) hass.services.async_register("test", "alexa", mock_service)
assert loop.run_until_complete( assert await async_setup_component(
async_setup_component(
hass, hass,
alexa.DOMAIN, alexa.DOMAIN,
{ {
@ -68,8 +64,7 @@ def alexa_client(
}, },
}, },
) )
) return await hass_client()
return loop.run_until_complete(hass_client())
def _flash_briefing_req(client, briefing_id, password="pass%2Fabc"): def _flash_briefing_req(client, briefing_id, password="pass%2Fabc"):

View File

@ -1,6 +1,5 @@
"""The tests for the Alexa component.""" """The tests for the Alexa component."""
from asyncio import AbstractEventLoop
from http import HTTPStatus from http import HTTPStatus
import json import json
@ -30,13 +29,11 @@ NPR_NEWS_MP3_URL = "https://pd.npr.org/anon.npr-mp3/npr/news/newscast.mp3"
@pytest.fixture @pytest.fixture
def alexa_client( async def alexa_client(
event_loop: AbstractEventLoop,
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
) -> TestClient: ) -> TestClient:
"""Initialize a Home Assistant server for testing this module.""" """Initialize a Home Assistant server for testing this module."""
loop = event_loop
@callback @callback
def mock_service(call): def mock_service(call):
@ -44,8 +41,7 @@ def alexa_client(
hass.services.async_register("test", "alexa", mock_service) hass.services.async_register("test", "alexa", mock_service)
assert loop.run_until_complete( assert await async_setup_component(
async_setup_component(
hass, hass,
alexa.DOMAIN, alexa.DOMAIN,
{ {
@ -54,9 +50,7 @@ def alexa_client(
"alexa": {}, "alexa": {},
}, },
) )
) assert await async_setup_component(
assert loop.run_until_complete(
async_setup_component(
hass, hass,
"intent_script", "intent_script",
{ {
@ -132,8 +126,7 @@ def alexa_client(
} }
}, },
) )
) return await hass_client()
return loop.run_until_complete(hass_client())
def _intent_req(client, data=None): def _intent_req(client, data=None):