summaryrefslogtreecommitdiffstats
path: root/tests/test_config.py
blob: 62acd977b560216c3b3ca84edcbddbd01a49d0c8 (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
41
42
43
44
45
46
47
48
49
50
51
52
from hyprsunset_qt.config import Profile, parse_config, serialize, day_index, night_index


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