EU-Utility/test_bugs.py

302 lines
8.9 KiB
Python

#!/usr/bin/env python3
"""
EU-Utility Bug Fixer - Test Script
Tests all core modules and plugins for critical bugs.
"""
import sys
import os
import traceback
from pathlib import Path
# Add project to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
print("=" * 60)
print("EU-Utility Bug Fixer - Testing for Critical Issues")
print("=" * 60)
bugs_found = []
def test_module(module_name, import_func):
"""Test a module for import errors."""
try:
import_func()
print(f"{module_name}: OK")
return True
except Exception as e:
error_msg = f"{module_name}: {type(e).__name__}: {e}"
print(error_msg)
bugs_found.append((module_name, e, traceback.format_exc()))
return False
# Test 1: Windows Compatibility - Check for Windows-only imports
print("\n--- Testing Windows Compatibility ---")
def test_window_manager():
from core.window_manager import WindowManager
wm = WindowManager()
# Should gracefully handle non-Windows platforms
if not wm.is_available():
print(" (WindowManager not available on this platform - expected)")
test_module("window_manager", test_window_manager)
# Test 2: OCR Service - Check backend initialization
def test_ocr_service():
from core.ocr_service import OCRService
ocr = OCRService()
# Should not crash on init (lazy initialization)
if not ocr.is_available():
print(" (OCR not available - no backends installed)")
test_module("ocr_service", test_ocr_service)
# Test 3: Screenshot Service - Check backend detection
def test_screenshot_service():
from core.screenshot import ScreenshotService
ss = ScreenshotService()
backends = ss.get_available_backends()
print(f" Available backends: {backends}")
test_module("screenshot", test_screenshot_service)
# Test 4: Audio Manager - Check backend initialization
def test_audio_manager():
from core.audio import AudioManager
audio = AudioManager()
print(f" Backend: {audio._backend}")
test_module("audio", test_audio_manager)
# Test 5: Data Store - Check file locking
def test_data_store():
from core.data_store import DataStore
ds = DataStore()
# Test save/load
ds.save("test_plugin", "test_key", {"test": "data"})
data = ds.load("test_plugin", "test_key")
assert data == {"test": "data"}, "Data mismatch"
ds.delete("test_plugin", "test_key")
test_module("data_store", test_data_store)
# Test 6: Event Bus - Check async operations
def test_event_bus():
from core.event_bus import get_event_bus, SkillGainEvent
bus = get_event_bus()
# Test subscription
received = []
def handler(event):
received.append(event)
sub_id = bus.subscribe_typed(SkillGainEvent, handler)
# Test publish
event = SkillGainEvent(skill_name="Test", skill_value=1.0, gain_amount=0.01)
bus.publish_sync(event)
# Cleanup
bus.unsubscribe(sub_id)
bus.shutdown()
test_module("event_bus", test_event_bus)
# Test 7: Task Manager - Check thread safety
def test_task_manager():
from core.tasks import get_task_manager
tm = get_task_manager()
# Test basic functionality
def test_func():
return "test_result"
task_id = tm.run_in_thread(test_func)
# Don't wait for completion in test
tm.cancel_task(task_id)
tm.shutdown(wait=False)
test_module("task_manager", test_task_manager)
# Test 8: HTTP Client - Check cache operations
def test_http_client():
from core.http_client import HTTPClient
client = HTTPClient(cache_dir="cache/test_http")
stats = client.get_cache_stats()
print(f" Cache stats: {stats}")
test_module("http_client", test_http_client)
# Test 9: Plugin API - Check service registration
def test_plugin_api():
from core.plugin_api import get_api
api = get_api()
# Should have event bus
assert api._event_bus is not None
test_module("plugin_api", test_plugin_api)
# Test 10: Log Reader - Check file path handling
def test_log_reader():
from core.log_reader import LogReader
lr = LogReader()
# Should handle missing log file gracefully
available = lr.is_available()
print(f" Log available: {available}")
test_module("log_reader", test_log_reader)
# Test 11: Clipboard Manager - Check cross-platform
def test_clipboard():
from core.clipboard import get_clipboard_manager
cm = get_clipboard_manager()
available = cm.is_available()
print(f" Clipboard available: {available}")
test_module("clipboard", test_clipboard)
# Test 12: Icon Manager - Check SVG handling
def test_icon_manager():
from core.icon_manager import get_icon_manager
im = get_icon_manager()
# Should not crash even if icons don't exist
icon = im.get_icon("nonexistent")
assert icon is not None
test_module("icon_manager", test_icon_manager)
# Test 13: Icon Extractor - Check TGA handling
def test_icon_extractor():
from core.icon_extractor import TGAReader, IconCacheManager
# Should handle missing files gracefully
reader = TGAReader(Path("/nonexistent/file.tga"))
result = reader.read()
assert result is None
test_module("icon_extractor", test_icon_extractor)
# Test 14: Notifications - Check Qt integration
def test_notifications():
from core.notifications import NotificationManager
nm = NotificationManager()
# Should not crash without QApplication
print(" (Skipping notification test without QApplication)")
test_module("notifications", test_notifications)
# Test 15: Settings - Check JSON handling
def test_settings():
from core.settings import Settings
s = Settings(config_file="data/test_settings.json")
s.set("test_key", "test_value")
val = s.get("test_key")
assert val == "test_value"
# Cleanup
Path("data/test_settings.json").unlink(missing_ok=True)
test_module("settings", test_settings)
# Test 16: Overlay Widgets - Check Qt imports
def test_overlay_widgets():
try:
from PyQt6.QtWidgets import QApplication
from core.overlay_widgets import OverlayManager
print(" (Qt available - overlay widgets can be tested)")
except ImportError:
print(" (Qt not available - skipping overlay widget test)")
test_module("overlay_widgets", test_overlay_widgets)
# Test 17: Overlay Window - Check Qt imports
def test_overlay_window():
try:
from PyQt6.QtWidgets import QApplication
from core.overlay_window import OverlayWindow
print(" (Qt available - overlay window can be tested)")
except ImportError:
print(" (Qt not available - skipping overlay window test)")
test_module("overlay_window", test_overlay_window)
# Test 18: Floating Icon - Check Qt imports
def test_floating_icon():
try:
from PyQt6.QtWidgets import QApplication
from core.floating_icon import FloatingIcon
print(" (Qt available - floating icon can be tested)")
except ImportError:
print(" (Qt not available - skipping floating icon test)")
test_module("floating_icon", test_floating_icon)
# Test 19: Dashboard - Check Qt imports
def test_dashboard():
try:
from PyQt6.QtWidgets import QApplication
from core.dashboard import Dashboard
print(" (Qt available - dashboard can be tested)")
except ImportError:
print(" (Qt not available - skipping dashboard test)")
test_module("dashboard", test_dashboard)
# Test 20: Plugin Store - Check HTTP operations
def test_plugin_store():
from core.plugin_store import PluginStore
# Should initialize without network
ps = PluginStore(plugins_dir="test_plugins")
print(" (PluginStore initialized)")
test_module("plugin_store", test_plugin_store)
# Test Plugins
print("\n--- Testing Plugins ---")
def test_auction_tracker():
from plugins.auction_tracker.plugin import AuctionTrackerPlugin
# Can't fully test without overlay, but can check imports
print(" (Import OK)")
test_module("auction_tracker", test_auction_tracker)
def test_tp_runner():
from plugins.tp_runner.plugin import TPRunnerPlugin
print(" (Import OK)")
test_module("tp_runner", test_tp_runner)
def test_inventory_manager():
from plugins.inventory_manager.plugin import InventoryManagerPlugin
print(" (Import OK)")
test_module("inventory_manager", test_inventory_manager)
def test_loot_tracker():
from plugins.loot_tracker.plugin import LootTrackerPlugin
print(" (Import OK)")
test_module("loot_tracker", test_loot_tracker)
def test_universal_search():
from plugins.universal_search.plugin import UniversalSearchPlugin
print(" (Import OK)")
test_module("universal_search", test_universal_search)
# Summary
print("\n" + "=" * 60)
print("BUG FIXER SUMMARY")
print("=" * 60)
if bugs_found:
print(f"\n❌ Found {len(bugs_found)} critical bugs:")
for module, error, tb in bugs_found:
print(f"\n {module}:")
print(f" Error: {type(error).__name__}: {error}")
print(f" Traceback: {tb[:500]}...")
else:
print("\n✅ No critical bugs found in basic tests!")
print("\n" + "=" * 60)