aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_theme.py
blob: 6530af5f7e237d0b869d1465a833e248f884ff0c (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
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import unittest

import deckit.theme as theme

PALETTE = """* {
    base:      #24273aff;
    text:      #cad3f5ff;
    surface0:  #363a4fff;
}"""
ACCENT = "* { accent: #b7bdf8; }"


class Theme(unittest.TestCase):
    def test_parses_palette(self):
        self.assertEqual(theme.parse_palette(PALETTE),
                         {"base": "#24273aff", "text": "#cad3f5ff", "surface0": "#363a4fff"})

    def test_parses_accent(self):
        self.assertEqual(theme.parse_accent(ACCENT), "#b7bdf8")
        self.assertIsNone(theme.parse_accent("nothing"))

    def test_css_exposes_vars_and_falls_back(self):
        out = theme.css({"base": "#24273a"}, None)
        self.assertIn("--udt-base: #24273a", out)
        self.assertIn("--udt-accent:", out)  # fallback accent

    def test_load_falls_back_when_files_are_missing(self):
        saved = (theme.PALETTE_PATH, theme.ACCENT_PATH)
        theme.PALETTE_PATH = Path("/nonexistent/palette.rasi")
        theme.ACCENT_PATH = Path("/nonexistent/accent.rasi")
        try:
            out = theme.load()
        finally:
            theme.PALETTE_PATH, theme.ACCENT_PATH = saved
        self.assertIn("--udt-base: #24273a", out)


if __name__ == "__main__":
    unittest.main()