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,16 +1,21 @@
#!/usr/bin/env python3
"""Test script to analyze all theme header colors."""
# ruff: noqa: E402
import sys
import tkinter as tk
from pathlib import Path
from init import logger
from theme_manager import ThemeManager
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
# Add src directory to Python path
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
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"))
def analyze_all_themes():

View File

@@ -3,18 +3,23 @@
Integration test for TheChart export system
Tests the complete export workflow without GUI dependencies
"""
# ruff: noqa: E402
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, "src")
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
from data_manager import DataManager
from export_manager import ExportManager
from init import logger
from medicine_manager import MedicineManager
from pathology_manager import PathologyManager
from thechart.core.constants import LOG_LEVEL
from thechart.core.logger import init_logger
from thechart.data import DataManager
from thechart.export import ExportManager
from thechart.managers import MedicineManager, PathologyManager
logger = init_logger(__name__, testing_mode=(LOG_LEVEL == "DEBUG"))
class MockGraphManager:

View File

@@ -1,17 +1,25 @@
#!/usr/bin/env python3
"""Test the darker header text for Arc theme."""
# ruff: noqa: E402
#!/usr/bin/env python3
"""Test the darker header text for Arc theme."""
import sys
import tkinter as tk
from pathlib import Path
from tkinter import ttk
from init import logger
from theme_manager import ThemeManager
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
# Add src directory to Python path
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
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"))
def test_arc_darker_headers():

View File

@@ -1,13 +1,22 @@
#!/usr/bin/env python3
"""Test script to check table header visibility in Arc theme."""
# ruff: noqa: E402
import sys
import tkinter as tk
from pathlib import Path
from tkinter import ttk
from init import logger
from theme_manager import ThemeManager
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
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"))
# Add src directory to Python path
src_path = Path(__file__).parent / "src"

View File

@@ -2,16 +2,22 @@
"""
Test the complete dose tracking flow: load -> display -> add -> save
"""
# ruff: noqa: E402
import os
import sys
from datetime import datetime
# Add the src directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = os.path.join(os.path.dirname(__file__), "..", "src")
if SRC_DIR not in sys.path:
sys.path.insert(0, SRC_DIR)
from init import logger
from ui_manager import UIManager
from thechart.core.constants import LOG_LEVEL
from thechart.core.logger import init_logger
from thechart.ui import UIManager
logger = init_logger(__name__, testing_mode=(LOG_LEVEL == "DEBUG"))
def test_dose_parsing():

View File

@@ -3,20 +3,28 @@
Test script for dose tracking UI in edit window.
Tests the specific issue where adding new doses replaces existing ones.
"""
# ruff: noqa: E402
import os
import sys
import tkinter as tk
from datetime import datetime
from pathlib import Path
# Add the src directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from init import logger
from medicine_manager import MedicineManager
from pathology_manager import PathologyManager
from theme_manager import ThemeManager
from ui_manager import UIManager
def _ensure_src_on_path() -> None:
src_dir = Path(__file__).resolve().parent.parent / "src"
if str(src_dir) not in sys.path:
sys.path.insert(0, str(src_dir))
_ensure_src_on_path()
from thechart.core.constants import LOG_LEVEL
from thechart.core.logger import init_logger
from thechart.managers import Medicine, MedicineManager, PathologyManager
from thechart.ui import ThemeManager
from thechart.ui.ui_manager import UIManager
logger = init_logger(__name__, testing_mode=(LOG_LEVEL == "DEBUG"))
def test_dose_tracking():
@@ -39,8 +47,6 @@ def test_dose_tracking():
# Add a test medicine if none exist
medicines = medicine_manager.get_all_medicines()
if not medicines:
from medicine_manager import Medicine
test_medicine = Medicine(
key="bupropion",
display_name="Bupropion",

View File

@@ -1,13 +1,22 @@
#!/usr/bin/env python3
"""Test the improved header visibility fix."""
# ruff: noqa: E402
import sys
import tkinter as tk
from pathlib import Path
from tkinter import ttk
from init import logger
from theme_manager import ThemeManager
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
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"))
# Add src directory to Python path
src_path = Path(__file__).parent / "src"

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())

View File

@@ -1,17 +1,22 @@
#!/usr/bin/env python3
"""Test the improved header visibility with white text."""
# ruff: noqa: E402
import sys
import tkinter as tk
from pathlib import Path
from tkinter import ttk
from init import logger
from theme_manager import ThemeManager
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
# Add src directory to Python path
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
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"))
def test_white_headers():

View File

@@ -1,16 +1,21 @@
#!/usr/bin/env python3
"""Verify header visibility across all themes."""
# ruff: noqa: E402
import sys
import tkinter as tk
from pathlib import Path
from init import logger
from theme_manager import ThemeManager
# Ensure the 'src' directory is on sys.path so 'thechart' package is importable
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
# Add src directory to Python path
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
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"))
def verify_all_themes():
@@ -56,7 +61,6 @@ def verify_all_themes():
darker = min(bg_lum, fg_lum)
contrast_ratio = (lighter + 0.05) / (darker + 0.05)
# Determine status
if contrast_ratio >= 4.5:
status = "✅ EXCELLENT"
elif contrast_ratio >= 3.0:

View File

@@ -1,16 +1,24 @@
#!/usr/bin/env python3
"""Verify that other themes still work correctly with Arc-specific change."""
# ruff: noqa: E402
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 / "src"
sys.path.insert(0, str(src_path))
def _ensure_src_on_path() -> None:
src_dir = Path(__file__).resolve().parent.parent / "src"
if str(src_dir) not in sys.path:
sys.path.insert(0, str(src_dir))
_ensure_src_on_path()
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"))
def verify_other_themes():