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."""
from asyncio import AbstractEventLoop
import datetime
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
def alexa_client(
event_loop: AbstractEventLoop,
async def alexa_client(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
) -> TestClient:
"""Initialize a Home Assistant server for testing this module."""
loop = event_loop
@callback
def mock_service(call):
@ -38,8 +35,7 @@ def alexa_client(
hass.services.async_register("test", "alexa", mock_service)
assert loop.run_until_complete(
async_setup_component(
assert await async_setup_component(
hass,
alexa.DOMAIN,
{
@ -68,8 +64,7 @@ def alexa_client(
},
},
)
)
return loop.run_until_complete(hass_client())
return await hass_client()
def _flash_briefing_req(client, briefing_id, password="pass%2Fabc"):

View File

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