Files
ClaudeProjectManager/test_refactoring.py
Claude Project Manager 4dab418f2f Initial commit
2025-07-09 22:10:42 +02:00

213 Zeilen
7.2 KiB
Python

#!/usr/bin/env python3
"""
Test script for refactoring verification
Tests that refactored methods work correctly
"""
import sys
import os
from unittest.mock import MagicMock
# Mock GUI dependencies
sys.modules['customtkinter'] = MagicMock()
sys.modules['tkinter'] = MagicMock()
sys.modules['PIL'] = MagicMock()
sys.modules['PIL.Image'] = MagicMock()
# Import after mocking
from gui.config import refactoring_config
from gui.main_window import MainWindow
def test_ui_helpers():
"""Test UI helpers functionality"""
print("\n=== Testing UI Helpers ===")
# Check current configuration
status = refactoring_config.get_status()
print(f"USE_UI_HELPERS: {status['flags']['USE_UI_HELPERS']}")
# Mock required components
with MagicMock() as mock_project_manager:
mock_project_manager.get_projects.return_value = []
# Test load_and_apply_theme
print("\nTesting load_and_apply_theme...")
try:
# Create a minimal MainWindow instance
# This will test if the refactored method is called
import customtkinter as ctk
ctk.CTk = MagicMock(return_value=MagicMock())
# The method should be called during __init__
# Since we can't fully instantiate MainWindow, test the handler directly
from gui.handlers.ui_helpers import UIHelpersHandler
mock_main_window = MagicMock()
mock_main_window.root = MagicMock()
mock_main_window.main_container = MagicMock()
handler = UIHelpersHandler(mock_main_window)
handler.load_and_apply_theme()
print("✅ load_and_apply_theme executed successfully")
# Test _show_scrollable_info
print("\nTesting _show_scrollable_info...")
handler._show_scrollable_info("Test Title", "Test Content")
print("✅ _show_scrollable_info executed successfully")
# Test create_header
print("\nTesting create_header...")
handler.create_header()
print("✅ create_header executed successfully")
# Test create_status_bar
print("\nTesting create_status_bar...")
handler.create_status_bar()
print("✅ create_status_bar executed successfully")
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
def test_project_handler():
"""Test project handler functionality"""
print("\n=== Testing Project Handler ===")
from gui.handlers.project_manager import ProjectManagerHandler
from project_manager import Project
mock_main_window = MagicMock()
mock_main_window.project_manager = MagicMock()
mock_main_window.refresh_projects = MagicMock()
mock_main_window.update_status = MagicMock()
handler = ProjectManagerHandler(mock_main_window)
# Test delete_project
print("\nTesting delete_project...")
try:
mock_project = MagicMock()
mock_project.name = "Test Project"
mock_project.id = "test-id"
# Mock the dialog to return False (no delete)
with MagicMock() as mock_messagebox:
mock_messagebox.askyesno.return_value = False
handler.delete_project(mock_project)
print("✅ delete_project executed (no delete)")
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
def test_process_handler():
"""Test process handler functionality"""
print("\n=== Testing Process Handler ===")
from gui.handlers.process_manager import ProcessManagerHandler
mock_main_window = MagicMock()
mock_main_window.status_label = MagicMock()
handler = ProcessManagerHandler(mock_main_window)
# Test update_status
print("\nTesting update_status...")
try:
handler.update_status("Test message", error=False)
print("✅ update_status executed successfully")
handler.update_status("Error message", error=True)
print("✅ update_status with error executed successfully")
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
# Note: download_log requires file dialog interaction, harder to test
def test_gitea_handler():
"""Test Gitea handler functionality"""
print("\n=== Testing Gitea Handler ===")
from gui.handlers.gitea_operations import GiteaOperationsHandler
mock_main_window = MagicMock()
mock_main_window._show_scrollable_info = MagicMock()
mock_repo_manager = MagicMock()
mock_repo_manager.client = MagicMock()
mock_repo_manager.git_ops = MagicMock()
mock_main_window.repo_manager = mock_repo_manager
handler = GiteaOperationsHandler(mock_main_window)
# Test consolidated test_gitea_connection
print("\nTesting test_gitea_connection (consolidated)...")
try:
# Mock the API calls
mock_repo_manager.client.get_user_info.return_value = {'username': 'testuser'}
mock_repo_manager.client.get_user_orgs.return_value = []
mock_repo_manager.client.get_user_teams.return_value = []
mock_repo_manager.client.get_user_repos.return_value = []
handler.test_gitea_connection()
print("✅ test_gitea_connection executed successfully (without project)")
# Test with project
mock_project = MagicMock()
mock_project.name = "Test Project"
mock_project.path = "/test/path"
handler.test_gitea_connection(mock_project)
print("✅ test_gitea_connection executed successfully (with project)")
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
def main():
"""Run all tests"""
print("=== Refactoring Test Suite ===")
# Show current configuration
print("\nCurrent Configuration:")
status = refactoring_config.get_status()
for flag, value in status['flags'].items():
if flag.startswith('USE_'):
status_str = "✅ ENABLED" if value else "❌ DISABLED"
print(f" {flag}: {status_str}")
# Run tests based on enabled features
if status['flags']['USE_UI_HELPERS']:
test_ui_helpers()
else:
print("\n⚠️ UI Helpers not enabled. Enable with:")
print(" python3 manage_refactoring.py enable ui")
if status['flags']['USE_PROJECT_HANDLER']:
test_project_handler()
else:
print("\n⚠️ Project Handler not enabled. Enable with:")
print(" python3 manage_refactoring.py enable project")
if status['flags']['USE_PROCESS_HANDLER']:
test_process_handler()
else:
print("\n⚠️ Process Handler not enabled. Enable with:")
print(" python3 manage_refactoring.py enable process")
if status['flags']['USE_GITEA_HANDLER']:
test_gitea_handler()
else:
print("\n⚠️ Gitea Handler not enabled. Enable with:")
print(" python3 manage_refactoring.py enable gitea")
print("\n✅ Test completed")
if __name__ == '__main__':
main()