forked from genewildish/Mainline
feat: add ACTIVE_THEME global and set_active_theme() to config
This commit is contained in:
@@ -104,3 +104,26 @@ def set_font_selection(font_path=None, font_index=None):
|
|||||||
FONT_PATH = _resolve_font_path(font_path)
|
FONT_PATH = _resolve_font_path(font_path)
|
||||||
if font_index is not None:
|
if font_index is not None:
|
||||||
FONT_INDEX = max(0, int(font_index))
|
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)
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import tempfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from engine import config
|
from engine import config
|
||||||
|
|
||||||
|
|
||||||
@@ -160,3 +162,55 @@ class TestSetFontSelection:
|
|||||||
config.set_font_selection(font_path=None, font_index=None)
|
config.set_font_selection(font_path=None, font_index=None)
|
||||||
assert original_path == config.FONT_PATH
|
assert original_path == config.FONT_PATH
|
||||||
assert original_index == config.FONT_INDEX
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user