From 2190054abfd231728a08674e7c2486e65bb61222 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 17 Sep 2024 16:11:03 +0200 Subject: [PATCH] Improve negative TTS test (#126126) --- tests/components/tts/test_media_source.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/components/tts/test_media_source.py b/tests/components/tts/test_media_source.py index 81bbfcfed8a..367b24dd4d0 100644 --- a/tests/components/tts/test_media_source.py +++ b/tests/components/tts/test_media_source.py @@ -1,6 +1,7 @@ """Tests for TTS media source.""" from http import HTTPStatus +import re from unittest.mock import MagicMock import pytest @@ -169,29 +170,34 @@ async def test_resolving( [(MSProvider(DEFAULT_LANG), MSEntity(DEFAULT_LANG))], ) @pytest.mark.parametrize( - "setup", + ("setup", "engine"), [ - "mock_setup", - "mock_config_entry_setup", + ("mock_setup", "test"), + ("mock_config_entry_setup", "tts.test"), ], indirect=["setup"], ) -async def test_resolving_errors(hass: HomeAssistant, setup: str) -> None: +async def test_resolving_errors(hass: HomeAssistant, setup: str, engine: str) -> None: """Test resolving.""" # No message added with pytest.raises(media_source.Unresolvable): await media_source.async_resolve_media(hass, "media-source://tts/test", None) # Non-existing provider - with pytest.raises(media_source.Unresolvable): + with pytest.raises( + media_source.Unresolvable, match="Provider non-existing not found" + ): await media_source.async_resolve_media( hass, "media-source://tts/non-existing?message=bla", None ) # Non-existing option - with pytest.raises(media_source.Unresolvable): + with pytest.raises( + media_source.Unresolvable, + match=re.escape("Invalid options found: ['non_existing_option']"), + ): await media_source.async_resolve_media( hass, - "media-source://tts/non-existing?message=bla&non_existing_option=bla", + f"media-source://tts/{engine}?message=bla&non_existing_option=bla", None, )