summaryrefslogtreecommitdiffstats
path: root/tests/test_daemon.py
blob: 337dc391700f4d547a6f6940854122c17749f46c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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"]