This repository was archived by the owner on Jul 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_theme_manager.py
More file actions
318 lines (252 loc) · 10.6 KB
/
Copy pathtest_theme_manager.py
File metadata and controls
318 lines (252 loc) · 10.6 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/usr/bin/env python3
"""
Test script for theme management system.
This script validates the theme management functionality including:
- Theme enumeration and settings
- Stylesheet generation for all themes
- Theme switching and persistence
- System theme detection
- Menu creation functionality
"""
import sys
import os
from pathlib import Path
# Add src to path for imports
sys.path.insert(0, 'src')
def test_theme_imports():
"""Test theme manager imports."""
try:
from ui.themes import (
Theme, ThemeManager, ThemeSettings,
apply_theme, detect_system_theme, create_theme_menu
)
print("✅ Theme manager imports successful")
return True
except ImportError as e:
print(f"❌ Theme manager import failed: {e}")
return False
def test_theme_enumeration():
"""Test theme enumeration values."""
try:
from ui.themes import Theme
themes = [
Theme.LIGHT,
Theme.DARK,
Theme.HIGH_CONTRAST,
Theme.SYSTEM
]
print("✅ Available themes:")
for theme in themes:
print(f" - {theme.value}")
return True
except Exception as e:
print(f"❌ Theme enumeration test failed: {e}")
return False
def test_theme_settings():
"""Test theme settings persistence."""
try:
from ui.themes import ThemeSettings, Theme
# Create settings with fallback for testing
settings = ThemeSettings()
print("✅ Theme settings functionality:")
# Test default theme
default_theme = settings.get_theme()
print(f" - Default theme: {default_theme.value}")
# Test setting theme
settings.set_theme(Theme.DARK)
saved_theme = settings.get_theme()
print(f" - After setting DARK: {saved_theme.value}")
# Test auto-switch settings
settings.set_auto_switch(True)
auto_switch = settings.get_auto_switch()
print(f" - Auto-switch enabled: {auto_switch}")
settings.set_auto_switch(False)
auto_switch = settings.get_auto_switch()
print(f" - Auto-switch disabled: {auto_switch}")
return True
except Exception as e:
print(f"❌ Theme settings test failed: {e}")
return False
def test_stylesheet_generation():
"""Test stylesheet generation for all themes."""
try:
from ui.themes import ThemeManager, Theme
manager = ThemeManager()
print("✅ Stylesheet generation:")
themes_to_test = [Theme.LIGHT, Theme.DARK, Theme.HIGH_CONTRAST]
for theme in themes_to_test:
manager.current_theme = theme
stylesheet = manager.get_current_stylesheet()
# Basic validation
if not stylesheet:
print(f" ❌ {theme.value}: No stylesheet generated")
return False
if len(stylesheet) < 100:
print(f" ❌ {theme.value}: Stylesheet too short ({len(stylesheet)} chars)")
return False
# Check for theme-specific colors
if theme == Theme.DARK:
if "#1a1a1a" not in stylesheet and "#2d2d2d" not in stylesheet:
print(f" ❌ {theme.value}: Missing dark theme colors")
return False
elif theme == Theme.HIGH_CONTRAST:
if "#000000" not in stylesheet or "#ffffff" not in stylesheet:
print(f" ❌ {theme.value}: Missing high contrast colors")
return False
print(f" ✅ {theme.value}: {len(stylesheet):,} characters")
return True
except Exception as e:
print(f"❌ Stylesheet generation test failed: {e}")
return False
def test_theme_manager():
"""Test theme manager functionality."""
try:
from ui.themes import ThemeManager, Theme
manager = ThemeManager()
print("✅ Theme manager functionality:")
# Test initial state
current_theme = manager.get_current_theme()
print(f" - Initial theme: {current_theme.value}")
# Test theme switching
manager.set_theme(Theme.DARK)
new_theme = manager.get_current_theme()
print(f" - After setting DARK: {new_theme.value}")
# Test toggle functionality
manager.toggle_theme()
toggled_theme = manager.get_current_theme()
print(f" - After toggle: {toggled_theme.value}")
# Test system theme detection
system_theme = manager._detect_system_theme()
print(f" - Detected system theme: {system_theme.value}")
return True
except Exception as e:
print(f"❌ Theme manager test failed: {e}")
return False
def test_helper_functions():
"""Test helper functions."""
try:
from ui.themes import detect_system_theme, create_theme_menu, ThemeManager
print("✅ Helper functions:")
# Test system theme detection
system_theme = detect_system_theme()
print(f" - System theme detection: {system_theme.value}")
# Test menu creation (without GUI)
manager = ThemeManager()
menu = create_theme_menu(manager)
if menu is not None:
print(" - Theme menu created successfully")
else:
print(" - Theme menu creation skipped (no PySide6)")
return True
except Exception as e:
print(f"❌ Helper functions test failed: {e}")
return False
def test_dark_theme_specifics():
"""Test dark theme specific features for nighttime operations."""
try:
from ui.themes import ThemeManager, Theme
manager = ThemeManager()
manager.set_theme(Theme.DARK)
stylesheet = manager.get_current_stylesheet()
print("✅ Dark theme nighttime operation features:")
# Check for dark background colors
dark_backgrounds = ["#1a1a1a", "#242424", "#2d2d2d"]
found_dark = any(color in stylesheet for color in dark_backgrounds)
print(f" - Dark backgrounds: {'✅' if found_dark else '❌'}")
# Check for reduced brightness elements
if "#64b5f6" in stylesheet: # Light blue for accents
print(" - ✅ Reduced brightness accent colors")
else:
print(" - ❌ Missing reduced brightness accents")
# Check for improved scrollbar visibility
if "QScrollBar" in stylesheet:
print(" - ✅ Enhanced scrollbar visibility")
else:
print(" - ❌ Missing scrollbar enhancements")
# Check for form validation colors in dark theme
validation_colors = ["#4a1a1a", "#4a3a1a", "#1a4a1a"]
found_validation = any(color in stylesheet for color in validation_colors)
print(f" - Validation feedback colors: {'✅' if found_validation else '❌'}")
return True
except Exception as e:
print(f"❌ Dark theme specifics test failed: {e}")
return False
def test_high_contrast_accessibility():
"""Test high contrast theme accessibility features."""
try:
from ui.themes import ThemeManager, Theme
manager = ThemeManager()
manager.set_theme(Theme.HIGH_CONTRAST)
stylesheet = manager.get_current_stylesheet()
print("✅ High contrast accessibility features:")
# Check for high contrast colors
if "#000000" in stylesheet and "#ffffff" in stylesheet:
print(" - ✅ High contrast black/white base colors")
else:
print(" - ❌ Missing high contrast base colors")
# Check for accessibility yellow
if "#ffff00" in stylesheet:
print(" - ✅ High visibility yellow accents")
else:
print(" - ❌ Missing yellow accent colors")
# Check for increased border widths
if "3px solid" in stylesheet:
print(" - ✅ Enhanced border visibility")
else:
print(" - ❌ Missing enhanced borders")
# Check for larger font sizes
if "12pt" in stylesheet:
print(" - ✅ Increased font sizes for readability")
else:
print(" - ❌ Missing font size enhancements")
# Check for bold font weights
if "font-weight: bold" in stylesheet:
print(" - ✅ Bold text for better visibility")
else:
print(" - ❌ Missing bold font weights")
return True
except Exception as e:
print(f"❌ High contrast accessibility test failed: {e}")
return False
def main():
"""Main test execution."""
print("Theme Manager Test Suite")
print("=" * 50)
tests = [
("Import Test", test_theme_imports),
("Theme Enumeration", test_theme_enumeration),
("Theme Settings", test_theme_settings),
("Stylesheet Generation", test_stylesheet_generation),
("Theme Manager", test_theme_manager),
("Helper Functions", test_helper_functions),
("Dark Theme Features", test_dark_theme_specifics),
("High Contrast Accessibility", test_high_contrast_accessibility)
]
passed = 0
failed = 0
for test_name, test_func in tests:
print(f"\n🧪 {test_name}")
print("-" * 30)
try:
if test_func():
passed += 1
else:
failed += 1
except Exception as e:
print(f"❌ {test_name} failed with exception: {e}")
failed += 1
print(f"\n📊 Test Results")
print("=" * 50)
print(f"Passed: {passed}")
print(f"Failed: {failed}")
print(f"Total: {passed + failed}")
if failed == 0:
print("\n✅ All theme manager tests passed!")
print("\nDark theme is ready for nighttime operations!")
print("High contrast theme meets accessibility requirements!")
sys.exit(0)
else:
print(f"\n❌ {failed} test(s) failed!")
sys.exit(1)
if __name__ == "__main__":
main()