- _on_realize implementiert (war nur connected, nicht definiert) - do_unrealize für as_file() Context-Manager-Cleanup - threading.Lock für _greetd_sock Race Condition - TOML-Parsing-Fehler abfangen statt Crash - last-user Datei: Längen- und Zeichenvalidierung - detect_locale: non-alpha LANG-Werte abweisen - exec_cmd Plausibility-Check mit shutil.which - Exception-Details ins Log statt in die UI - subprocess.run Timeout für Power-Actions - Sequence[Path] statt tuple[Path, ...] in get_sessions - Mock-Server _recvall für fragmentierte Reads - [behavior]-Config-Sektion entfernt (unimplementiert) - Design Decisions in CLAUDE.md dokumentiert
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# ABOUTME: Tests for power actions — reboot and shutdown via loginctl.
|
|
# ABOUTME: Uses mocking to avoid actually calling system commands.
|
|
|
|
import subprocess
|
|
from unittest.mock import patch, call
|
|
|
|
import pytest
|
|
|
|
from moongreet.power import reboot, shutdown, POWER_TIMEOUT
|
|
|
|
|
|
class TestReboot:
|
|
"""Tests for the reboot power action."""
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_calls_loginctl_reboot(self, mock_run) -> None:
|
|
reboot()
|
|
|
|
mock_run.assert_called_once_with(
|
|
["loginctl", "reboot"], check=True, timeout=POWER_TIMEOUT
|
|
)
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_raises_on_failure(self, mock_run) -> None:
|
|
mock_run.side_effect = subprocess.CalledProcessError(1, "loginctl")
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
reboot()
|
|
|
|
|
|
class TestShutdown:
|
|
"""Tests for the shutdown power action."""
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_calls_loginctl_poweroff(self, mock_run) -> None:
|
|
shutdown()
|
|
|
|
mock_run.assert_called_once_with(
|
|
["loginctl", "poweroff"], check=True, timeout=POWER_TIMEOUT
|
|
)
|
|
|
|
@patch("moongreet.power.subprocess.run")
|
|
def test_raises_on_failure(self, mock_run) -> None:
|
|
mock_run.side_effect = subprocess.CalledProcessError(1, "loginctl")
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
shutdown()
|