Public Access
feat: sync missing features from v0.49.x line to master
The v0.49.x tag line diverged from origin/master, leaving many features only accessible via tags but not on the master branch. New modules: - ci/cancel_superseded_runs.py — cancel superseded CI runs - ci/check_workflow_artifact_deps.py — validate artifact deps - ci/check_workflow_tofu_init.py — validate tofu init steps - tools/check_alert_rules.py — validate Prometheus alert rules - tools/check_ansible_set_fact_to_json.py — lint set_fact usage - tools/check_docker_init.py — validate Docker init scripts - utils/jinja.py — Jinja2 template utilities - utils/ui.py — UI/console utilities Modified modules: - distribute_molecule.py: add --include-roles/--exclude-roles - utils/api.py: add container.credentials for private registry auth - install_tools.py: retry ansible-galaxy on transient timeouts - setup_image.py: skip dep resolution with --no-deps - cli.py: register new commands - i18n.py: add new translation keys Also removes accidentally committed .vale/styles/Google/ files. Test results: 2195 passed, 100% coverage. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
d2aa4c6298
commit
bbb14c71e9
@@ -0,0 +1,100 @@
|
||||
"""Unit tests for devx.i18n."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
import devx.i18n as i18n_mod
|
||||
from devx.i18n import _, configure_i18n
|
||||
|
||||
|
||||
class TestTranslate:
|
||||
def test_returns_english_by_default(self) -> None:
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.delenv("DEVX_LANG", raising=False)
|
||||
assert _("Running tests") == "Running tests"
|
||||
|
||||
def test_returns_key_when_missing(self) -> None:
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.delenv("DEVX_LANG", raising=False)
|
||||
assert _("nonexistent.key.xyz") == "nonexistent.key.xyz"
|
||||
|
||||
def test_formats_kwargs(self) -> None:
|
||||
# Find a key with format placeholders
|
||||
for key, translations in i18n_mod.TRANSLATIONS.items():
|
||||
en = translations.get("en", "")
|
||||
if "{" in en:
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.delenv("DEVX_LANG", raising=False)
|
||||
result = _(key, **dict.fromkeys(_extract_format_keys(en), "x"))
|
||||
assert "{" not in result
|
||||
return
|
||||
pytest.skip("No key with format placeholders found")
|
||||
|
||||
def test_invalid_lang_falls_back_to_english(self) -> None:
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.setenv("DEVX_LANG", "fr")
|
||||
assert _("Running tests") == "Running tests"
|
||||
|
||||
def test_bulgarian_translation(self) -> None:
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.setenv("DEVX_LANG", "bg")
|
||||
# Find a key that has a Bulgarian translation
|
||||
for key, translations in i18n_mod.TRANSLATIONS.items():
|
||||
if "bg" in translations:
|
||||
result = _(key)
|
||||
assert result == translations["bg"]
|
||||
return
|
||||
pytest.skip("No Bulgarian translation found")
|
||||
|
||||
|
||||
class TestConfigureI18n:
|
||||
def test_custom_lang_env_var(self) -> None:
|
||||
configure_i18n(lang_env_var="GRM_LANG")
|
||||
try:
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.setenv("GRM_LANG", "bg")
|
||||
mp.delenv("DEVX_LANG", raising=False)
|
||||
# Find a key with Bulgarian translation
|
||||
for key, translations in i18n_mod.TRANSLATIONS.items():
|
||||
if "bg" in translations:
|
||||
assert _(key) == translations["bg"]
|
||||
return
|
||||
pytest.skip("No Bulgarian translation found")
|
||||
finally:
|
||||
configure_i18n() # Reset to defaults
|
||||
|
||||
def test_custom_translations_path_env_var(self, tmp_path) -> None:
|
||||
custom_translations = {"custom.key": {"en": "Custom Value", "bg": "Персонализирано"}}
|
||||
custom_file = tmp_path / "custom.json"
|
||||
custom_file.write_text(__import__("json").dumps(custom_translations))
|
||||
|
||||
configure_i18n(translations_path_env_var="GRM_TRANSLATIONS_PATH")
|
||||
try:
|
||||
# Use i18n_mod.TRANSLATIONS (not a stale import) — other tests
|
||||
# may call importlib.reload(devx.i18n), replacing the dict object.
|
||||
translations = i18n_mod.TRANSLATIONS
|
||||
original = dict(translations)
|
||||
translations.update(custom_translations)
|
||||
try:
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.setenv("GRM_TRANSLATIONS_PATH", str(custom_file))
|
||||
assert _("custom.key") == "Custom Value"
|
||||
finally:
|
||||
translations.clear()
|
||||
translations.update(original)
|
||||
finally:
|
||||
configure_i18n() # Reset to defaults
|
||||
|
||||
def test_reset_to_defaults(self) -> None:
|
||||
configure_i18n(lang_env_var="GRM_LANG")
|
||||
configure_i18n() # Reset
|
||||
assert i18n_mod._lang_env_var == "DEVX_LANG"
|
||||
assert i18n_mod._translations_path_env_var == "DEVX_TRANSLATIONS_PATH"
|
||||
|
||||
|
||||
def _extract_format_keys(template: str) -> list[str]:
|
||||
"""Extract {key} format placeholders from a template string."""
|
||||
import re
|
||||
|
||||
return re.findall(r"\{(\w+)\}", template)
|
||||
Reference in New Issue
Block a user