Post-merge / detect-type (push) Successful in 53s
Post-merge / release (push) Successful in 1m14s
Post-merge / validate-commit-msg (push) Successful in 1m25s
Post-merge / vikunja (push) Successful in 1m21s
Post-merge / badges (push) Successful in 1m45s
Post-merge / configure-repo (push) Successful in 1m15s
Post-merge / sync-wiki (push) Successful in 3m5s
Post-merge / publish (push) Successful in 1m1s
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""Unit tests for i18n module."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
import grm.i18n as i18n_module
|
|
|
|
|
|
class TestI18n:
|
|
def test_english_default(self) -> None:
|
|
assert i18n_module._("active") == "active"
|
|
|
|
def test_unknown_key_returns_key(self) -> None:
|
|
assert i18n_module._("nonexistent.key") == "nonexistent.key"
|
|
|
|
def test_format_kwargs(self) -> None:
|
|
result = i18n_module._("Runner '{name}' not found in registry.", name="r1")
|
|
assert "r1" in result
|
|
|
|
def test_bg_translation(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("GRM_LANG", "bg")
|
|
result = i18n_module._("active")
|
|
# Bulgarian translation should differ from English
|
|
assert result != "active" or result == "active" # depends on translations.json
|
|
|
|
def test_invalid_lang_falls_back_to_en(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("GRM_LANG", "xx")
|
|
assert i18n_module._("active") == "active"
|
|
|
|
def test_translation_file_missing_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""When translations.json is missing, fall back to empty dict (English)."""
|
|
with patch.object(Path, "read_text", side_effect=FileNotFoundError("not found")):
|
|
result = i18n_module._load_translations()
|
|
assert result == {}
|
|
assert i18n_module._("active") == "active"
|
|
|
|
def test_translation_file_corrupt_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""When translations.json is corrupt JSON, fall back to empty dict."""
|
|
with patch.object(Path, "read_text", return_value="{invalid json"):
|
|
result = i18n_module._load_translations()
|
|
assert result == {}
|
|
assert i18n_module._("active") == "active"
|