From ebdf809e0723ba3d32794278c72e4cd844cea498 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 17 Jul 2026 10:34:54 +0200 Subject: feat: daemon status, restart, live preview Add daemon.py module to control hyprsunset daemon via subprocess: - is_running() checks daemon status using pgrep - live_preview() pushes temperature/gamma/identity to running daemon via hyprctl - restart() kills existing daemon and launches new detached process All subprocess calls are mocked in tests; no real processes are touched. Co-Authored-By: Claude Opus 4.8 --- tests/test_daemon.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_daemon.py (limited to 'tests') diff --git a/tests/test_daemon.py b/tests/test_daemon.py new file mode 100644 index 0000000..337dc39 --- /dev/null +++ b/tests/test_daemon.py @@ -0,0 +1,40 @@ +from unittest.mock import patch, MagicMock +from hyprsunset_qt import daemon + + +def test_is_running_true(): + with patch("hyprsunset_qt.daemon.subprocess.run") as run: + run.return_value = MagicMock(returncode=0) + assert daemon.is_running() is True + run.assert_called_once() + + +def test_is_running_false(): + with patch("hyprsunset_qt.daemon.subprocess.run") as run: + run.return_value = MagicMock(returncode=1) + assert daemon.is_running() is False + + +def test_live_preview_identity(): + with patch("hyprsunset_qt.daemon.subprocess.run") as run: + daemon.live_preview(identity=True) + run.assert_called_with( + ["hyprctl", "hyprsunset", "identity"], check=False + ) + + +def test_live_preview_temp_and_gamma(): + with patch("hyprsunset_qt.daemon.subprocess.run") as run: + daemon.live_preview(temperature=5500, gamma=0.8) + calls = [c.args[0] for c in run.call_args_list] + assert ["hyprctl", "hyprsunset", "temperature", "5500"] in calls + assert ["hyprctl", "hyprsunset", "gamma", "80"] in calls + + +def test_restart_kills_then_launches(): + with patch("hyprsunset_qt.daemon.subprocess.run") as run, \ + patch("hyprsunset_qt.daemon.subprocess.Popen") as popen: + daemon.restart("hyprsunset") + run.assert_called_with(["pkill", "hyprsunset"], check=False) + popen.assert_called_once() + assert popen.call_args[0][0] == ["hyprsunset"] -- cgit v1.2.3