Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/unit/test_language_consistency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from __future__ import annotations

Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a module-level docstring to explain the purpose of these tests, similar to other test files like test_security_encrypt_decrypt_consistency.py and test_config_load_resilience.py. This would help document what these consistency tests validate and why they're important.

Suggested change
"""Tests for consistency of language message definitions and tone mappings.
These tests verify that:
* All supported languages (currently English and Chinese) share the same set
of message keys in ``glitter.language.MESSAGES`` so that translations stay
in sync.
* The ``MESSAGE_TONES`` mapping only references existing message keys, which
helps prevent runtime errors and incomplete user-facing messages.
A lightweight ``rich`` stub is used when the real dependency is not present
so that the language module can be imported in isolation during testing.
"""

Copilot uses AI. Check for mistakes.
import importlib
import sys
import types


def _import_language_module():
"""Import glitter.language with a lightweight rich stub when needed."""

if "rich.text" not in sys.modules:
rich_module = types.ModuleType("rich")
rich_text_module = types.ModuleType("rich.text")

class _FakeText:
def __init__(self, value: str) -> None:
self.plain = value

def stylize(self, style: str) -> None: # noqa: ARG002
return None

rich_text_module.Text = _FakeText
sys.modules["rich"] = rich_module
sys.modules["rich.text"] = rich_text_module

return importlib.import_module("glitter.language")


def test_message_keys_are_consistent_between_languages() -> None:
language = _import_language_module()
en_keys = set(language.MESSAGES["en"].keys())
zh_keys = set(language.MESSAGES["zh"].keys())
assert en_keys == zh_keys


def test_message_tones_only_reference_existing_message_keys() -> None:
language = _import_language_module()
Comment on lines +3 to +37
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rich.text stub appears to be unnecessary since rich is a required dependency in pyproject.toml. All other test files in the codebase import rich.text directly without any stubbing. Consider simplifying by directly importing from glitter.language instead of using importlib and stubbing.

Suggested change
import importlib
import sys
import types
def _import_language_module():
"""Import glitter.language with a lightweight rich stub when needed."""
if "rich.text" not in sys.modules:
rich_module = types.ModuleType("rich")
rich_text_module = types.ModuleType("rich.text")
class _FakeText:
def __init__(self, value: str) -> None:
self.plain = value
def stylize(self, style: str) -> None: # noqa: ARG002
return None
rich_text_module.Text = _FakeText
sys.modules["rich"] = rich_module
sys.modules["rich.text"] = rich_text_module
return importlib.import_module("glitter.language")
def test_message_keys_are_consistent_between_languages() -> None:
language = _import_language_module()
en_keys = set(language.MESSAGES["en"].keys())
zh_keys = set(language.MESSAGES["zh"].keys())
assert en_keys == zh_keys
def test_message_tones_only_reference_existing_message_keys() -> None:
language = _import_language_module()
import glitter.language as language
def test_message_keys_are_consistent_between_languages() -> None:
en_keys = set(language.MESSAGES["en"].keys())
zh_keys = set(language.MESSAGES["zh"].keys())
assert en_keys == zh_keys
def test_message_tones_only_reference_existing_message_keys() -> None:

Copilot uses AI. Check for mistakes.
message_keys = set(language.MESSAGES["en"].keys())
tone_keys = set(language.MESSAGE_TONES.keys())
assert tone_keys <= message_keys
Loading