summaryrefslogtreecommitdiffstats
path: root/tests/test_daemon.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-17 10:34:54 +0200
committerDanilo M. <danix@danix.xyz>2026-07-17 10:34:54 +0200
commitebdf809e0723ba3d32794278c72e4cd844cea498 (patch)
tree38433f3f7f1b092f698814ecf195bff4c61083f5 /tests/test_daemon.py
parentfc4b8ae587fa5a26648c2bb94e61141d2954f9aa (diff)
downloadhyprsunset-qt-ebdf809e0723ba3d32794278c72e4cd844cea498.tar.gz
hyprsunset-qt-ebdf809e0723ba3d32794278c72e4cd844cea498.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_daemon.py')
-rw-r--r--tests/test_daemon.py40
1 files changed, 40 insertions, 0 deletions
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"]