Run ruff format changes and finalize indentation and lint fixes.

This commit is contained in:
William Valentin
2025-08-09 12:10:16 -07:00
parent 9cec07e9f6
commit 9a5a2f0022
68 changed files with 1272 additions and 4301 deletions

View File

@@ -1,57 +1,73 @@
#!/usr/bin/env python3
"""Test script to verify theme changing functionality works without errors."""
"""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
from init import logger
from theme_manager import ThemeManager
# Add src directory to Python path
src_path = Path(__file__).parent.parent / "src"
sys.path.insert(0, str(src_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 test_theme_changes():
"""Test changing between different themes to ensure no errors occur."""
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 window
root = tk.Tk()
root.withdraw() # Hide the window
# 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
# Initialize theme manager
theme_manager = ThemeManager(root, logger)
try:
root.withdraw() # Hide the window
# Test all available themes
available_themes = theme_manager.get_available_themes()
print(f"Available themes: {available_themes}")
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")
for theme in available_themes:
print(f"Testing theme: {theme}")
try:
success = theme_manager.apply_theme(theme)
if success:
print(f"{theme} applied successfully")
# Test getting theme colors (this is where the error was occurring)
colors = theme_manager.get_theme_colors()
print(f" ✓ Theme colors retrieved: {list(colors.keys())}")
colors = theme_manager.get_theme_colors()
print(f" ✓ Theme colors retrieved: {list(colors.keys())}")
# Test getting menu colors
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:
print(f" ✗ Error with {theme}: {e}")
# Clean up
root.destroy()
print("Theme testing completed!")
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__":
test_theme_changes()
raise SystemExit(main())