From 522f6a04b01c948f395a07220166a53b8225466f Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 8 Oct 2024 07:58:30 +0000 Subject: [PATCH] Be nicer about data translations --- tests/components/conftest.py | 39 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/components/conftest.py b/tests/components/conftest.py index df8567166c68e6..34a1e9fa390eb7 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -445,31 +445,34 @@ def supervisor_client() -> Generator[AsyncMock]: yield supervisor_client -_IGNORE_TRANSLATION_VIOLATIONS = { - # These data input have a step description and it would be redundant to add - # a separate description for the data input - "component.airvisual.config.step.user.data.type", - "component.ambient_network.config.step.user.data.location", - "component.axis.options.step.configure_stream.data.video_source", - "component.tesla_fleet.config.step.pick_implementation.data.implementation", -} - - async def _ensure_translation_exists( hass: HomeAssistant, category: str, component: str, key: str ) -> None: """Raise if translation doesn't exist.""" - full_key = f"component.{component}.{category}.{key}" - if full_key in _IGNORE_TRANSLATION_VIOLATIONS: + translations = await async_get_translations(hass, "en", category, [component]) + if f"component.{component}.{category}.{key}" in translations: return - translations = await async_get_translations(hass, "en", category, [component]) - if full_key not in translations: - raise ValueError( - f"Translation not found for {component}: `{category}.{key}`. " - f"Please add to homeassistant/components/{component}/strings.json " - "or add to _IGNORE_TRANSLATION_VIOLATIONS." + key_parts = key.split(".") + # Ignore step data translations if title or description exists + if ( + len(key_parts) >= 3 + and key_parts[0] == "step" + and key_parts[2] == "data" + and ( + f"component.{component}.{category}.{key_parts[0]}.{key_parts[1]}.description" + in translations + or f"component.{component}.{category}.{key_parts[0]}.{key_parts[1]}.title" + in translations ) + ): + return + + raise ValueError( + f"Translation not found for {component}: `{category}.{key}`. " + f"Please add to homeassistant/components/{component}/strings.json " + "or add to _IGNORE_TRANSLATION_VIOLATIONS." + ) @pytest.fixture(autouse=True)