Spaces:
Paused
Paused
File size: 7,394 Bytes
a5784e9 | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | """Tests for gui/styles.py module."""
from unittest.mock import MagicMock, patch
class TestApplyTheme:
"""Tests for apply_theme function."""
def test_apply_theme_function_exists(self):
"""apply_theme function should exist."""
from gui.styles import apply_theme
assert callable(apply_theme)
def test_apply_theme_calls_set_appearance_mode(self):
"""apply_theme should set CTk appearance mode via theme module."""
with patch("gui.styles.ctk") as mock_ctk:
with patch("gui.theme.ctk"): # Also mock theme.ctk
from gui.styles import apply_theme
apply_theme(appearance_mode="dark")
# apply_theme uses theme.set_appearance_mode which calls ctk
# So we verify the color theme was set
mock_ctk.set_default_color_theme.assert_called()
def test_apply_theme_calls_set_default_color_theme(self):
"""apply_theme should set CTk color theme."""
with patch("gui.styles.ctk") as mock_ctk:
from gui.styles import CTK_COLOR_THEME, apply_theme
apply_theme()
mock_ctk.set_default_color_theme.assert_called_once_with(CTK_COLOR_THEME)
class TestModernStyleLegacy:
"""Tests for ModernStyle legacy wrapper."""
def test_modern_style_class_exists(self):
"""ModernStyle class should exist for backwards compatibility."""
from gui.styles import ModernStyle
assert ModernStyle is not None
def test_modern_style_has_apply_method(self):
"""ModernStyle has static apply method."""
from gui.styles import ModernStyle
assert hasattr(ModernStyle, "apply")
assert callable(ModernStyle.apply)
def test_apply_is_static_method(self):
"""apply should be a static method."""
from gui.styles import ModernStyle
assert isinstance(ModernStyle.__dict__["apply"], staticmethod)
def test_modern_style_apply_calls_apply_theme(self):
"""ModernStyle.apply should call apply_theme."""
with patch("gui.styles.ctk"):
from gui.styles import ModernStyle
mock_root = MagicMock()
# Should not raise
ModernStyle.apply(mock_root)
class TestGetButtonColors:
"""Tests for get_button_colors function."""
def test_get_button_colors_exists(self):
"""get_button_colors function should exist."""
from gui.styles import get_button_colors
assert callable(get_button_colors)
def test_get_button_colors_default(self):
"""get_button_colors returns default style."""
from gui.styles import get_button_colors
colors = get_button_colors("default")
assert "fg_color" in colors
assert "hover_color" in colors
assert "text_color" in colors
def test_get_button_colors_success(self):
"""get_button_colors returns success style."""
from gui.config import COLORS
from gui.styles import get_button_colors
colors = get_button_colors("success")
assert colors["fg_color"] == COLORS["success"]
assert colors["hover_color"] == COLORS["success_hover"]
def test_get_button_colors_danger(self):
"""get_button_colors returns danger style."""
from gui.config import COLORS
from gui.styles import get_button_colors
colors = get_button_colors("danger")
assert colors["fg_color"] == COLORS["error"]
assert colors["hover_color"] == COLORS["error_hover"]
def test_get_button_colors_accent(self):
"""get_button_colors returns accent style."""
from gui.config import COLORS
from gui.styles import get_button_colors
colors = get_button_colors("accent")
assert colors["fg_color"] == COLORS["accent"]
def test_get_button_colors_outline(self):
"""get_button_colors returns outline style with border."""
from gui.styles import get_button_colors
colors = get_button_colors("outline")
assert colors["fg_color"] == "transparent"
assert "border_width" in colors
assert "border_color" in colors
def test_get_button_colors_ghost(self):
"""get_button_colors returns ghost style."""
from gui.styles import get_button_colors
colors = get_button_colors("ghost")
assert colors["fg_color"] == "transparent"
def test_get_button_colors_unknown_returns_default(self):
"""get_button_colors returns default for unknown style."""
from gui.styles import get_button_colors
default_colors = get_button_colors("default")
unknown_colors = get_button_colors("nonexistent_style")
assert default_colors == unknown_colors
class TestGetEntryStyle:
"""Tests for get_entry_style function."""
def test_get_entry_style_exists(self):
"""get_entry_style function should exist."""
from gui.styles import get_entry_style
assert callable(get_entry_style)
def test_get_entry_style_returns_required_keys(self):
"""get_entry_style returns required style keys."""
from gui.styles import get_entry_style
style = get_entry_style()
assert "corner_radius" in style
assert "border_width" in style
assert "fg_color" in style
assert "text_color" in style
class TestGetFrameStyle:
"""Tests for get_frame_style function."""
def test_get_frame_style_exists(self):
"""get_frame_style function should exist."""
from gui.styles import get_frame_style
assert callable(get_frame_style)
def test_get_frame_style_default(self):
"""get_frame_style returns default variant."""
from gui.styles import get_frame_style
style = get_frame_style("default")
assert "fg_color" in style
assert "corner_radius" in style
def test_get_frame_style_card(self):
"""get_frame_style returns card variant with border."""
from gui.styles import get_frame_style
style = get_frame_style("card")
assert "border_width" in style
assert "border_color" in style
def test_get_frame_style_transparent(self):
"""get_frame_style returns transparent variant."""
from gui.styles import get_frame_style
style = get_frame_style("transparent")
assert style["fg_color"] == "transparent"
class TestColorsIntegration:
"""Tests for color usage in styles."""
def test_colors_imported_from_config(self):
"""Styles module imports COLORS from config."""
from gui.config import COLORS as CONFIG_COLORS
from gui.styles import COLORS
assert COLORS is CONFIG_COLORS
def test_accent_color_used_for_highlights(self):
"""Accent color is used for interactive elements."""
from gui.config import COLORS
assert "accent" in COLORS
assert "accent_hover" in COLORS
assert COLORS["accent"] != COLORS["accent_hover"]
def test_background_colors_hierarchy(self):
"""Background colors should have visual hierarchy."""
from gui.config import COLORS
assert "bg_dark" in COLORS
assert "bg_medium" in COLORS
assert "bg_light" in COLORS
bg_colors = [COLORS["bg_dark"], COLORS["bg_medium"], COLORS["bg_light"]]
assert len(set(bg_colors)) == 3
|