From ebe7b04ba58a28e8c6f4af9637edbf08e7eec56b Mon Sep 17 00:00:00 2001 From: Gene Johnson Date: Mon, 16 Mar 2026 02:50:36 -0700 Subject: [PATCH] feat: add ACTIVE_THEME global and set_active_theme() to config --- engine/config.py | 23 +++++++++++++++++++ tests/test_config.py | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/engine/config.py b/engine/config.py index 1de24e5..5b045db 100644 --- a/engine/config.py +++ b/engine/config.py @@ -104,3 +104,26 @@ def set_font_selection(font_path=None, font_index=None): FONT_PATH = _resolve_font_path(font_path) if font_index is not None: FONT_INDEX = max(0, int(font_index)) + + +# ─── THEME MANAGEMENT ───────────────────────────────────────── +ACTIVE_THEME = None + + +def set_active_theme(theme_id: str = "green"): + """Set the active theme by ID. + + Args: + theme_id: Theme identifier ("green", "orange", or "purple") + Defaults to "green" + + Raises: + KeyError: If theme_id is not in the theme registry + + Side Effects: + Sets the ACTIVE_THEME global variable + """ + global ACTIVE_THEME + from engine import themes + + ACTIVE_THEME = themes.get_theme(theme_id) diff --git a/tests/test_config.py b/tests/test_config.py index 9cf6c1c..79a8c28 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -7,6 +7,8 @@ import tempfile from pathlib import Path from unittest.mock import patch +import pytest + from engine import config @@ -160,3 +162,55 @@ class TestSetFontSelection: config.set_font_selection(font_path=None, font_index=None) assert original_path == config.FONT_PATH assert original_index == config.FONT_INDEX + + +class TestActiveTheme: + """Tests for ACTIVE_THEME global and set_active_theme function.""" + + def test_active_theme_initially_none(self): + """ACTIVE_THEME should be None at module start.""" + # Reset to None to test initial state + original = config.ACTIVE_THEME + config.ACTIVE_THEME = None + try: + assert config.ACTIVE_THEME is None + finally: + config.ACTIVE_THEME = original + + def test_set_active_theme_green(self): + """Setting green theme works correctly.""" + config.set_active_theme("green") + assert config.ACTIVE_THEME is not None + assert config.ACTIVE_THEME.name == "green" + assert len(config.ACTIVE_THEME.main_gradient) == 12 + assert len(config.ACTIVE_THEME.message_gradient) == 12 + + def test_set_active_theme_default(self): + """Default theme is green when not specified.""" + config.set_active_theme() + assert config.ACTIVE_THEME is not None + assert config.ACTIVE_THEME.name == "green" + + def test_set_active_theme_invalid(self): + """Invalid theme_id raises KeyError.""" + with pytest.raises(KeyError): + config.set_active_theme("nonexistent") + + def test_set_active_theme_all_themes(self): + """Verify orange and purple themes work.""" + # Test orange + config.set_active_theme("orange") + assert config.ACTIVE_THEME.name == "orange" + + # Test purple + config.set_active_theme("purple") + assert config.ACTIVE_THEME.name == "purple" + + def test_set_active_theme_idempotent(self): + """Calling set_active_theme multiple times works.""" + config.set_active_theme("green") + first_theme = config.ACTIVE_THEME + config.set_active_theme("green") + second_theme = config.ACTIVE_THEME + assert first_theme.name == second_theme.name + assert first_theme.name == "green"