mirror of
https://github.com/home-assistant/core.git
synced 2025-04-19 14:57:52 +00:00
Fix some tests
This commit is contained in:
parent
1420f03b93
commit
df1454b1fe
@ -199,7 +199,7 @@ async def async_get_media_source_audio(
|
||||
)
|
||||
return await manager.async_get_tts_audio(cache_key)
|
||||
|
||||
token = media_source_id.partition("/")[2]
|
||||
token = media_source_id.split("/")[-1]
|
||||
if (stream := manager.token_to_stream.get(token)) is None:
|
||||
raise Unresolvable("Token from media source not found")
|
||||
|
||||
|
@ -83,7 +83,7 @@
|
||||
dict({
|
||||
'data': dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22james_earl_jones%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
@ -180,7 +180,7 @@
|
||||
dict({
|
||||
'data': dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22Arnold+Schwarzenegger%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
@ -277,7 +277,7 @@
|
||||
dict({
|
||||
'data': dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22Arnold+Schwarzenegger%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
@ -398,7 +398,7 @@
|
||||
dict({
|
||||
'data': dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22james_earl_jones%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
|
@ -79,7 +79,7 @@
|
||||
# name: test_audio_pipeline.6
|
||||
dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22james_earl_jones%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
@ -168,7 +168,7 @@
|
||||
# name: test_audio_pipeline_debug.6
|
||||
dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22james_earl_jones%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
@ -269,7 +269,7 @@
|
||||
# name: test_audio_pipeline_with_enhancements.6
|
||||
dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22james_earl_jones%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
@ -380,7 +380,7 @@
|
||||
# name: test_audio_pipeline_with_wake_word_no_timeout.8
|
||||
dict({
|
||||
'tts_output': dict({
|
||||
'media_id': "media-source://tts/test?message=Sorry,+I+couldn't+understand+that&language=en-US&tts_options=%7B%22voice%22:%22james_earl_jones%22%7D",
|
||||
'media_id': 'media-source://tts/temporary/test_token.mp3',
|
||||
'mime_type': 'audio/mpeg',
|
||||
'url': '/api/tts_proxy/test_token.mp3',
|
||||
}),
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
from http import HTTPStatus
|
||||
import re
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import media_source
|
||||
from homeassistant.components import media_source, tts
|
||||
from homeassistant.components.media_player import BrowseError
|
||||
from homeassistant.components.tts.media_source import (
|
||||
MediaSourceOptions,
|
||||
@ -304,7 +304,31 @@ async def test_generate_media_source_id_and_media_source_id_to_kwargs(
|
||||
}
|
||||
|
||||
|
||||
async def test_stream_media_sources(hass: HomeAssistant) -> None:
|
||||
async def test_stream_media_sources(hass: HomeAssistant, setup_media_source) -> None:
|
||||
"""Test ResultStream as media sources."""
|
||||
assert await async_setup_component(hass, "tts", {})
|
||||
stream = tts.ResultStream(
|
||||
token="mock-token.flac",
|
||||
extension="flac",
|
||||
content_type="audio/flac",
|
||||
engine="test",
|
||||
use_file_cache=True,
|
||||
language="en",
|
||||
options={},
|
||||
_manager=None,
|
||||
)
|
||||
hass.data[tts.DATA_TTS_MANAGER].token_to_stream[stream.token] = stream
|
||||
assert stream.media_source_id == "media-source://tts/temporary/mock-token.flac"
|
||||
|
||||
# media-source://tts/temporary/AT1BH2ZsWHipW0pCy0cm7w.mp3
|
||||
assert await media_source.async_resolve_media(
|
||||
hass, stream.media_source_id, None
|
||||
) == media_source.PlayMedia(url=stream.url, mime_type=stream.content_type)
|
||||
|
||||
async def async_stream_result():
|
||||
yield b"test"
|
||||
|
||||
with patch.object(stream, "async_stream_result", async_stream_result):
|
||||
assert await tts.async_get_media_source_audio(hass, stream.media_source_id) == (
|
||||
stream.extension,
|
||||
b"test",
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user