155 lines
4.5 KiB
Python
155 lines
4.5 KiB
Python
"""Tests for the theme system."""
|
|
|
|
import uframe
|
|
from uframe.themes import (
|
|
get_theme, ThemeDef, BUILTIN_THEMES,
|
|
THEME_DEFAULT, THEME_NOUVEAU, THEME_GOTHIC,
|
|
THEME_BAMBOO, THEME_CIRCUIT, THEME_BRUTALIST,
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Theme registry
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_builtin_themes_exist():
|
|
assert len(BUILTIN_THEMES) == 6
|
|
for name in ("default", "nouveau", "gothic", "bamboo", "circuit", "brutalist"):
|
|
assert name in BUILTIN_THEMES
|
|
|
|
|
|
def test_get_theme_by_name():
|
|
theme = get_theme("gothic")
|
|
assert theme.name == "gothic"
|
|
|
|
|
|
def test_get_theme_case_insensitive():
|
|
theme = get_theme("GOTHIC")
|
|
assert theme.name == "gothic"
|
|
|
|
|
|
def test_get_theme_unknown_returns_default():
|
|
theme = get_theme("nonexistent")
|
|
assert theme.name == "default"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Theme structure
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_theme_has_all_fields():
|
|
for name, theme in BUILTIN_THEMES.items():
|
|
assert theme.borders_light is not None
|
|
assert theme.borders_heavy is not None
|
|
assert theme.borders_double is not None
|
|
assert theme.borders_rounded is not None
|
|
assert theme.dividers is not None
|
|
assert theme.indicators is not None
|
|
assert theme.gauge is not None
|
|
assert theme.form is not None
|
|
assert theme.palette is not None
|
|
|
|
|
|
def test_border_chars_method():
|
|
theme = THEME_DEFAULT
|
|
bc = theme.border_chars("light")
|
|
assert bc.tl == "┌"
|
|
assert bc.tr == "┐"
|
|
|
|
|
|
def test_border_dict_method():
|
|
theme = THEME_DEFAULT
|
|
bd = theme.border_dict("double")
|
|
assert bd["tl"] == "╔"
|
|
assert bd["h"] == "═"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Themed rendering — each theme produces correct characters
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_compile_with_default_theme():
|
|
source = '''page "Test" 40
|
|
box light "Panel"
|
|
text "Content"'''
|
|
result = uframe.compile(source)
|
|
assert "┌" in result.ascii # default light border
|
|
|
|
|
|
def test_compile_with_gothic_theme():
|
|
source = '''page "Test" 40
|
|
box light "Panel"
|
|
text "Content"'''
|
|
result = uframe.compile(source, theme="gothic")
|
|
# Gothic uses double-style borders for light
|
|
assert "╔" in result.ascii
|
|
|
|
|
|
def test_compile_with_brutalist_theme():
|
|
source = '''page "Test" 40
|
|
box light "Panel"
|
|
text "Content"'''
|
|
result = uframe.compile(source, theme="brutalist")
|
|
# Brutalist uses block characters for light borders
|
|
assert "▛" in result.ascii
|
|
|
|
|
|
def test_compile_with_bamboo_theme():
|
|
source = '''page "Test" 40
|
|
box light "Panel"
|
|
text "Content"'''
|
|
result = uframe.compile(source, theme="bamboo")
|
|
# Bamboo uses dashed light borders
|
|
assert "╌" in result.ascii or "┌" in result.ascii
|
|
|
|
|
|
def test_compile_with_circuit_theme():
|
|
source = '''page "Test" 40
|
|
gauge "CPU" 50 100 20'''
|
|
result = uframe.compile(source, theme="circuit")
|
|
# Circuit uses ▰/▱ for gauge
|
|
assert "▰" in result.ascii
|
|
assert "▱" in result.ascii
|
|
|
|
|
|
def test_compile_with_nouveau_theme():
|
|
source = '''page "Test" 40
|
|
status "Server" online'''
|
|
result = uframe.compile(source, theme="nouveau")
|
|
# Nouveau uses ❀ for online indicator
|
|
assert "❀" in result.ascii
|
|
|
|
|
|
def test_theme_divider_chars():
|
|
source = '''page "Test" 40
|
|
divider heavy'''
|
|
result_default = uframe.compile(source)
|
|
result_gothic = uframe.compile(source, theme="gothic")
|
|
# Both should render but potentially with different chars
|
|
assert "━" in result_default.ascii
|
|
assert "═" in result_gothic.ascii
|
|
|
|
|
|
def test_theme_gauge_chars():
|
|
source = '''page "Test" 40
|
|
gauge "Test" 50 100 20'''
|
|
result_default = uframe.compile(source)
|
|
result_brutalist = uframe.compile(source, theme="brutalist")
|
|
# Default: █/░, Brutalist: █/(space)
|
|
assert "█" in result_default.ascii
|
|
assert "█" in result_brutalist.ascii
|
|
|
|
|
|
def test_theme_form_chars():
|
|
source = '''page "Test" 50
|
|
form "test"
|
|
checkbox "agree" "Accept"'''
|
|
result_default = uframe.compile(source)
|
|
result_gothic = uframe.compile(source, theme="gothic")
|
|
# Default: [ ], Gothic: ⚐
|
|
assert "[ ]" in result_default.ascii or "Accept" in result_default.ascii
|
|
assert "⚐" in result_gothic.ascii or "Accept" in result_gothic.ascii
|