117 lines
3.3 KiB
Python
117 lines
3.3 KiB
Python
"""
|
|
Test for EU-Utility main application
|
|
|
|
Run with: python tests/test_main.py
|
|
"""
|
|
|
|
import sys
|
|
import time
|
|
import threading
|
|
from pathlib import Path
|
|
|
|
# Add parent to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from main import EUUtility
|
|
from core.clipboard import ClipboardManager
|
|
|
|
|
|
def test_initialization():
|
|
"""Test that EU-Utility initializes correctly."""
|
|
print("\n" + "="*60)
|
|
print("TESTING EU-Utility INITIALIZATION")
|
|
print("="*60)
|
|
|
|
# Reset singleton
|
|
ClipboardManager._instance = None
|
|
|
|
# Create app
|
|
print("\n1. Creating EU-Utility instance...")
|
|
app = EUUtility()
|
|
print(" ✓ Instance created")
|
|
|
|
# Initialize (without monitoring to avoid thread issues)
|
|
print("\n2. Initializing (without monitoring)...")
|
|
app.initialize(auto_start_clipboard_monitor=False)
|
|
print(" ✓ Initialized")
|
|
|
|
# Check clipboard manager
|
|
print("\n3. Checking clipboard manager...")
|
|
clipboard = app.get_clipboard_manager()
|
|
if clipboard:
|
|
print(f" ✓ Clipboard manager ready")
|
|
print(f" - Available: {clipboard.is_available()}")
|
|
print(f" - History: {len(clipboard.get_history())} entries")
|
|
else:
|
|
print(" ✗ Clipboard manager not found")
|
|
|
|
# Check plugins
|
|
print("\n4. Checking plugins...")
|
|
plugins = app.plugin_api.get_all_plugins()
|
|
print(f" - Loaded plugins: {len(plugins)}")
|
|
for plugin in plugins:
|
|
print(f" - {plugin.name} v{plugin.version}")
|
|
|
|
# Stop
|
|
print("\n5. Stopping...")
|
|
app.stop()
|
|
print(" ✓ Stopped cleanly")
|
|
|
|
print("\n" + "="*60)
|
|
print("INITIALIZATION TEST PASSED")
|
|
print("="*60)
|
|
|
|
|
|
def test_clipboard_in_main():
|
|
"""Test clipboard functionality through main app."""
|
|
print("\n" + "="*60)
|
|
print("TESTING CLIPBOARD THROUGH MAIN APP")
|
|
print("="*60)
|
|
|
|
# Reset singleton
|
|
ClipboardManager._instance = None
|
|
|
|
app = EUUtility()
|
|
app.initialize(auto_start_clipboard_monitor=False)
|
|
|
|
clipboard = app.get_clipboard_manager()
|
|
|
|
if clipboard and clipboard.is_available():
|
|
print("\n1. Testing copy/paste...")
|
|
clipboard.copy("Test from main", source="main_test")
|
|
pasted = clipboard.paste()
|
|
assert pasted == "Test from main", f"Expected 'Test from main', got '{pasted}'"
|
|
print(" ✓ Copy/paste works")
|
|
|
|
print("\n2. Testing history...")
|
|
history = clipboard.get_history()
|
|
assert len(history) > 0, "History should have entries"
|
|
assert history[0].source == "main_test", "Source should be tracked"
|
|
print(f" ✓ History tracking works ({len(history)} entries)")
|
|
|
|
print("\n3. Testing stats...")
|
|
stats = clipboard.get_stats()
|
|
assert 'history_count' in stats
|
|
print(f" ✓ Stats available: {stats}")
|
|
else:
|
|
print(" ⚠ Clipboard not available (pyperclip may not be installed)")
|
|
|
|
app.stop()
|
|
|
|
print("\n" + "="*60)
|
|
print("CLIPBOARD TEST COMPLETE")
|
|
print("="*60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
test_initialization()
|
|
test_clipboard_in_main()
|
|
print("\n✅ ALL TESTS PASSED")
|
|
except AssertionError as e:
|
|
print(f"\n❌ TEST FAILED: {e}")
|
|
except Exception as e:
|
|
print(f"\n❌ ERROR: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|