moonset/tests/test_integration.py
nevaforget 4cad984263 feat: initial moonset implementation — Wayland session power menu v0.1.0
5 Power-Aktionen (lock, logout, hibernate, reboot, shutdown),
GTK4 + Layer Shell UI mit Catppuccin Mocha Theme,
Multi-Monitor-Support, Inline-Confirmation, DE/EN i18n,
TOML-Config mit Wallpaper-Fallback. 54 Tests grün.
2026-03-27 13:47:03 +01:00

75 lines
3.1 KiB
Python

# ABOUTME: Integration tests for the moonset power menu.
# ABOUTME: Verifies that all modules work together correctly.
from pathlib import Path
from unittest.mock import patch
from moonset.config import Config, load_config, resolve_background_path
from moonset.i18n import Strings, load_strings
from moonset.panel import ACTION_DEFINITIONS, ActionDef
from moonset.power import POWER_TIMEOUT
class TestModuleIntegration:
"""Tests that verify modules work together."""
def test_action_defs_reference_valid_power_functions(self) -> None:
"""Each ActionDef references a function from power.py."""
from moonset import power
power_functions = {
power.lock, power.logout, power.hibernate,
power.reboot, power.shutdown,
}
for action_def in ACTION_DEFINITIONS:
assert action_def.action_fn in power_functions, (
f"{action_def.name} references unknown power function"
)
def test_action_defs_match_i18n_fields_de(self) -> None:
"""All label/error/confirm attrs in ActionDefs exist in DE strings."""
strings = load_strings("de")
for action_def in ACTION_DEFINITIONS:
assert hasattr(strings, action_def.label_attr)
assert hasattr(strings, action_def.error_attr)
if action_def.confirm_attr:
assert hasattr(strings, action_def.confirm_attr)
def test_action_defs_match_i18n_fields_en(self) -> None:
"""All label/error/confirm attrs in ActionDefs exist in EN strings."""
strings = load_strings("en")
for action_def in ACTION_DEFINITIONS:
assert hasattr(strings, action_def.label_attr)
assert hasattr(strings, action_def.error_attr)
if action_def.confirm_attr:
assert hasattr(strings, action_def.confirm_attr)
def test_config_defaults_produce_valid_background_path(self) -> None:
"""Default config resolves to an existing wallpaper file."""
config = Config()
path = resolve_background_path(config)
assert path.suffix in (".jpg", ".png", ".webp")
def test_full_config_to_strings_flow(self, tmp_path: Path) -> None:
"""Config loading and string loading work independently."""
conf = tmp_path / "moonset.toml"
conf.write_text('background_path = "/custom/path.jpg"\n')
config = load_config(config_paths=[conf])
assert config.background_path == "/custom/path.jpg"
strings = load_strings("de")
assert strings.lock_label == "Sperren"
@patch.dict("os.environ", {"LANG": "de_DE.UTF-8"})
def test_german_locale_produces_german_labels(self) -> None:
"""Full flow: German locale → German button labels."""
strings = load_strings()
for action_def in ACTION_DEFINITIONS:
label = action_def.get_label(strings)
assert label
# German labels should not be the English ones
en_strings = load_strings("en")
en_label = action_def.get_label(en_strings)
assert label != en_label, (
f"{action_def.name}: DE and EN labels are identical"
)