# 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()