mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fail on unused ignore_translations fixture (#128422)
* Fail on unused ignore_translations fixture * Cleanup melcloud * Use pytest.fail * Cleanup tplink * Cleanup matter
This commit is contained in:
parent
a14cb13194
commit
84b2c74057
@ -48,18 +48,6 @@ NAME = "Name"
|
|||||||
TEST_DOMAIN = "fake_integration"
|
TEST_DOMAIN = "fake_integration"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def ignore_translations() -> list[str]:
|
|
||||||
"""Ignore specific translations.
|
|
||||||
|
|
||||||
We can ignore translations for the fake_integration we are testing with.
|
|
||||||
"""
|
|
||||||
return [
|
|
||||||
f"component.{TEST_DOMAIN}.config.abort.missing_configuration",
|
|
||||||
f"component.{TEST_DOMAIN}.config.abort.missing_credentials",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def authorization_server() -> AuthorizationServer:
|
async def authorization_server() -> AuthorizationServer:
|
||||||
"""Fixture AuthorizationServer for mock application_credentials integration."""
|
"""Fixture AuthorizationServer for mock application_credentials integration."""
|
||||||
@ -435,6 +423,10 @@ async def test_import_named_credential(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"ignore_translations",
|
||||||
|
["component.fake_integration.config.abort.missing_credentials"],
|
||||||
|
)
|
||||||
async def test_config_flow_no_credentials(hass: HomeAssistant) -> None:
|
async def test_config_flow_no_credentials(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow base case with no credentials registered."""
|
"""Test config flow base case with no credentials registered."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -444,6 +436,10 @@ async def test_config_flow_no_credentials(hass: HomeAssistant) -> None:
|
|||||||
assert result.get("reason") == "missing_credentials"
|
assert result.get("reason") == "missing_credentials"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"ignore_translations",
|
||||||
|
["component.fake_integration.config.abort.missing_credentials"],
|
||||||
|
)
|
||||||
async def test_config_flow_other_domain(
|
async def test_config_flow_other_domain(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
ws_client: ClientFixture,
|
ws_client: ClientFixture,
|
||||||
@ -571,6 +567,10 @@ async def test_config_flow_multiple_entries(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"ignore_translations",
|
||||||
|
["component.fake_integration.config.abort.missing_credentials"],
|
||||||
|
)
|
||||||
async def test_config_flow_create_delete_credential(
|
async def test_config_flow_create_delete_credential(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
ws_client: ClientFixture,
|
ws_client: ClientFixture,
|
||||||
@ -616,6 +616,10 @@ async def test_config_flow_with_config_credential(
|
|||||||
assert result["data"].get("auth_implementation") == TEST_DOMAIN
|
assert result["data"].get("auth_implementation") == TEST_DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"ignore_translations",
|
||||||
|
["component.fake_integration.config.abort.missing_configuration"],
|
||||||
|
)
|
||||||
@pytest.mark.parametrize("mock_application_credentials_integration", [None])
|
@pytest.mark.parametrize("mock_application_credentials_integration", [None])
|
||||||
async def test_import_without_setup(hass: HomeAssistant, config_credential) -> None:
|
async def test_import_without_setup(hass: HomeAssistant, config_credential) -> None:
|
||||||
"""Test import of credentials without setting up the integration."""
|
"""Test import of credentials without setting up the integration."""
|
||||||
@ -631,6 +635,10 @@ async def test_import_without_setup(hass: HomeAssistant, config_credential) -> N
|
|||||||
assert result.get("reason") == "missing_configuration"
|
assert result.get("reason") == "missing_configuration"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"ignore_translations",
|
||||||
|
["component.fake_integration.config.abort.missing_configuration"],
|
||||||
|
)
|
||||||
@pytest.mark.parametrize("mock_application_credentials_integration", [None])
|
@pytest.mark.parametrize("mock_application_credentials_integration", [None])
|
||||||
async def test_websocket_without_platform(
|
async def test_websocket_without_platform(
|
||||||
hass: HomeAssistant, ws_client: ClientFixture
|
hass: HomeAssistant, ws_client: ClientFixture
|
||||||
|
@ -468,7 +468,7 @@ def supervisor_client() -> Generator[AsyncMock]:
|
|||||||
|
|
||||||
async def _ensure_translation_exists(
|
async def _ensure_translation_exists(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
ignore_translations: list[str],
|
ignore_translations: dict[str, StoreInfo],
|
||||||
category: str,
|
category: str,
|
||||||
component: str,
|
component: str,
|
||||||
key: str,
|
key: str,
|
||||||
@ -476,6 +476,7 @@ async def _ensure_translation_exists(
|
|||||||
"""Raise if translation doesn't exist."""
|
"""Raise if translation doesn't exist."""
|
||||||
full_key = f"component.{component}.{category}.{key}"
|
full_key = f"component.{component}.{category}.{key}"
|
||||||
if full_key in ignore_translations:
|
if full_key in ignore_translations:
|
||||||
|
ignore_translations[full_key] = "used"
|
||||||
return
|
return
|
||||||
|
|
||||||
translations = await async_get_translations(hass, "en", category, [component])
|
translations = await async_get_translations(hass, "en", category, [component])
|
||||||
@ -497,14 +498,14 @@ async def _ensure_translation_exists(
|
|||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
raise ValueError(
|
pytest.fail(
|
||||||
f"Translation not found for {component}: `{category}.{key}`. "
|
f"Translation not found for {component}: `{category}.{key}`. "
|
||||||
f"Please add to homeassistant/components/{component}/strings.json"
|
f"Please add to homeassistant/components/{component}/strings.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ignore_translations() -> list[str]:
|
def ignore_translations() -> str | list[str]:
|
||||||
"""Ignore specific translations.
|
"""Ignore specific translations.
|
||||||
|
|
||||||
Override or parametrize this fixture with a fixture that returns,
|
Override or parametrize this fixture with a fixture that returns,
|
||||||
@ -514,8 +515,12 @@ def ignore_translations() -> list[str]:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def check_config_translations(ignore_translations: list[str]) -> Generator[None]:
|
def check_config_translations(ignore_translations: str | list[str]) -> Generator[None]:
|
||||||
"""Ensure config_flow translations are available."""
|
"""Ensure config_flow translations are available."""
|
||||||
|
if not isinstance(ignore_translations, list):
|
||||||
|
ignore_translations = [ignore_translations]
|
||||||
|
|
||||||
|
_ignore_translations = {k: "unused" for k in ignore_translations}
|
||||||
_original = FlowManager._async_handle_step
|
_original = FlowManager._async_handle_step
|
||||||
|
|
||||||
async def _async_handle_step(
|
async def _async_handle_step(
|
||||||
@ -535,7 +540,7 @@ def check_config_translations(ignore_translations: list[str]) -> Generator[None]
|
|||||||
):
|
):
|
||||||
await _ensure_translation_exists(
|
await _ensure_translation_exists(
|
||||||
flow.hass,
|
flow.hass,
|
||||||
ignore_translations,
|
_ignore_translations,
|
||||||
category,
|
category,
|
||||||
component,
|
component,
|
||||||
f"abort.{result["reason"]}",
|
f"abort.{result["reason"]}",
|
||||||
@ -548,3 +553,10 @@ def check_config_translations(ignore_translations: list[str]) -> Generator[None]
|
|||||||
_async_handle_step,
|
_async_handle_step,
|
||||||
):
|
):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
unused_ignore = [k for k, v in _ignore_translations.items() if v == "unused"]
|
||||||
|
if unused_ignore:
|
||||||
|
pytest.fail(
|
||||||
|
f"Unused ignore translations: {', '.join(unused_ignore)}. "
|
||||||
|
"Please remove them from the ignore_translations fixture."
|
||||||
|
)
|
||||||
|
@ -827,10 +827,6 @@ async def test_addon_running(
|
|||||||
assert setup_entry.call_count == 1
|
assert setup_entry.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize( # Remove when translations fixed
|
|
||||||
"ignore_translations",
|
|
||||||
["component.matter.config.abort.cannot_connect"],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
(
|
(
|
||||||
"discovery_info",
|
"discovery_info",
|
||||||
|
@ -98,15 +98,6 @@ async def test_form_errors(
|
|||||||
assert result["reason"] == reason
|
assert result["reason"] == reason
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize( # Remove when translations fixed
|
|
||||||
"ignore_translations",
|
|
||||||
[
|
|
||||||
[
|
|
||||||
"component.melcloud.config.abort.cannot_connect",
|
|
||||||
"component.melcloud.config.abort.invalid_auth",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("error", "message"),
|
("error", "message"),
|
||||||
[
|
[
|
||||||
|
@ -1348,10 +1348,6 @@ async def test_reauth_errors(
|
|||||||
assert result3["reason"] == "reauth_successful"
|
assert result3["reason"] == "reauth_successful"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize( # Remove when translations fixed
|
|
||||||
"ignore_translations",
|
|
||||||
["component.tplink.config.abort.cannot_connect"],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("error_type", "expected_flow"),
|
("error_type", "expected_flow"),
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user