# deck-it - tests for theme # Copyright (C) 2026 Danilo M. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 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_parses_border_hues(self): self.assertEqual( theme.parse_border('return { "rgb(58a6ff)", "rgb(a371f7)", "rgb(db61a2)" }'), ["#58a6ff", "#a371f7", "#db61a2"]) def test_css_exposes_border_vars(self): out = theme.css({"base": "#24273a"}, None, ["#111111", "#222222", "#333333"]) for index, value in enumerate(["#111111", "#222222", "#333333"], 1): self.assertIn(f"--udt-border-{index}: {value}", out) 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()