#!/usr/bin/env python3 """Quick smoke test for ThemeManager: iterate and apply available themes. This script can be run standalone. It ensures the local ``src`` is on sys.path so the ``thechart`` package is importable without installation. It also hides the Tk window and gracefully skips if no display is available. """ from __future__ import annotations import contextlib import sys import tkinter as tk from pathlib import Path def _ensure_src_on_path() -> None: """Add the repository's ``src`` dir to sys.path when running locally.""" repo_root = Path(__file__).resolve().parents[1] src_dir = repo_root / "src" if str(src_dir) not in sys.path: sys.path.insert(0, str(src_dir)) def main() -> int: _ensure_src_on_path() # Imports after path fix from thechart.core.constants import LOG_LEVEL from thechart.core.logger import init_logger from thechart.ui import ThemeManager logger = init_logger(__name__, testing_mode=(LOG_LEVEL == "DEBUG")) print("Testing theme changing functionality...") # Create a test tkinter root; skip gracefully if headless try: root = tk.Tk() except tk.TclError as exc: print(f"Skipping: no display available ({exc})") return 0 try: root.withdraw() # Hide the window theme_manager = ThemeManager(root, logger) available_themes = theme_manager.get_available_themes() for theme in available_themes: print(f"Testing theme: {theme}") try: success = theme_manager.apply_theme(theme) if success: print(f" ✓ {theme} applied successfully") colors = theme_manager.get_theme_colors() print(f" ✓ Theme colors retrieved: {list(colors.keys())}") menu_colors = theme_manager.get_menu_colors() print(f" ✓ Menu colors retrieved: {list(menu_colors.keys())}") else: print(f" ✗ Failed to apply {theme}") except Exception as e: # pragma: no cover - smoke test resilience print(f" ✗ Error applying {theme}: {e}") return 0 finally: with contextlib.suppress(Exception): root.destroy() if __name__ == "__main__": raise SystemExit(main())