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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
from pathlib import Path
from hyprsunset_qt.config import Profile, parse_config, serialize, day_index, night_index, read_config, write_config, CONFIG_PATH
def test_parse_two_profiles():
text = """
profile {
time = 5:00
identity = true
}
profile {
time = 19:40
temperature = 5500
gamma = 0.8
}
"""
profiles = parse_config(text)
assert profiles == [
Profile(time="5:00", identity=True, temperature=None, gamma=None),
Profile(time="19:40", identity=False, temperature=5500, gamma=0.8),
]
def test_parse_empty():
assert parse_config("") == []
def test_serialize_roundtrip():
profiles = [
Profile(time="5:00", identity=True),
Profile(time="19:40", temperature=5500, gamma=0.8),
]
text = serialize(profiles)
assert parse_config(text) == profiles
assert "identity = true" in text
assert "temperature = 5500" in text
assert "gamma = 0.8" in text
assert text.startswith("# Managed by hyprsunset-qt")
def test_day_night_index():
profiles = [
Profile(time="5:00", identity=True),
Profile(time="19:40", temperature=5500, gamma=0.8),
]
assert day_index(profiles) == 0
assert night_index(profiles) == 1
def test_day_night_index_missing():
assert day_index([Profile(time="1:00", temperature=4000)]) is None
assert night_index([Profile(time="1:00", identity=True)]) is None
def test_read_missing_returns_empty(tmp_path):
assert read_config(tmp_path / "nope.conf") == []
def test_write_then_read(tmp_path):
path = tmp_path / "hyprsunset.conf"
profiles = [Profile(time="19:40", temperature=5500, gamma=0.8)]
write_config(profiles, path)
assert read_config(path) == profiles
def test_default_path_is_hypr_conf():
assert str(CONFIG_PATH).endswith(".config/hypr/hyprsunset.conf")
from hyprsunset_qt.config import valid_time, valid_temperature, valid_gamma
def test_valid_time():
assert valid_time("19:40")
assert valid_time("5:00")
assert not valid_time("25:00")
assert not valid_time("19:60")
assert not valid_time("abc")
def test_valid_temperature():
assert valid_temperature(5500)
assert not valid_temperature(500)
assert not valid_temperature(30000)
def test_valid_gamma():
assert valid_gamma(0.8)
assert valid_gamma(0.0)
assert not valid_gamma(-1.0)
assert not valid_gamma(2.5)
|