EU-Utility/plugins/test_plugin.py

140 lines
4.6 KiB
Python

"""
TestPlugin - Demonstrates Clipboard Manager functionality
This plugin showcases:
- Copy coordinates to clipboard
- Read pasted values from user
- Access clipboard history
"""
import time
import threading
from core.base_plugin import BasePlugin
class TestPlugin(BasePlugin):
"""Test plugin for demonstrating clipboard functionality."""
name = "test_plugin"
description = "Tests clipboard copy, paste, and history features"
version = "1.0.0"
author = "EU-Utility"
def __init__(self):
super().__init__()
self._test_thread = None
self._running = False
def on_start(self) -> None:
"""Start the test plugin."""
print(f"[{self.name}] Starting test plugin...")
self._running = True
# Run tests in background thread
self._test_thread = threading.Thread(target=self._run_tests, daemon=True)
self._test_thread.start()
def on_stop(self) -> None:
"""Stop the test plugin."""
print(f"[{self.name}] Stopping test plugin...")
self._running = False
def _run_tests(self) -> None:
"""Run clipboard tests after a short delay."""
time.sleep(1) # Wait for everything to initialize
if not self._running:
return
print(f"\n{'='*60}")
print(f"[{self.name}] RUNNING CLIPBOARD TESTS")
print(f"{'='*60}")
# Test 1: Copy coordinates to clipboard
self._test_copy_coordinates()
time.sleep(0.5)
# Test 2: Read pasted values
self._test_paste()
time.sleep(0.5)
# Test 3: Access clipboard history
self._test_history()
print(f"\n{'='*60}")
print(f"[{self.name}] ALL TESTS COMPLETE")
print(f"{'='*60}\n")
def _test_copy_coordinates(self) -> None:
"""Test copying coordinates to clipboard."""
print(f"\n[{self.name}] Test 1: Copy coordinates to clipboard")
print(f"[{self.name}] " + "-" * 40)
test_coords = [
("100, 200", "Simple coordinates"),
("45.5231, -122.6765", "GPS coordinates (Portland, OR)"),
("x: 150, y: 300", "Named coordinates"),
]
for coords, desc in test_coords:
success = self.copy_to_clipboard(coords)
if success:
print(f"[{self.name}] ✓ Copied: {coords} ({desc})")
else:
print(f"[{self.name}] ✗ Failed to copy: {coords}")
time.sleep(0.3)
def _test_paste(self) -> None:
"""Test reading pasted values from clipboard."""
print(f"\n[{self.name}] Test 2: Read pasted values from clipboard")
print(f"[{self.name}] " + "-" * 40)
# Copy something first
self.copy_to_clipboard("Test paste value")
time.sleep(0.2)
# Read it back
pasted = self.paste_from_clipboard()
if pasted:
print(f"[{self.name}] ✓ Pasted value: '{pasted}'")
else:
print(f"[{self.name}] ✗ Failed to paste (clipboard may be empty)")
# Try reading current clipboard (may be user content)
current = self.paste_from_clipboard()
print(f"[{self.name}] Current clipboard: '{current[:50] if current else 'None'}...' "
if current and len(current) > 50
else f"[{self.name}] Current clipboard: '{current}'")
def _test_history(self) -> None:
"""Test accessing clipboard history."""
print(f"\n[{self.name}] Test 3: Access clipboard history")
print(f"[{self.name}] " + "-" * 40)
# Get full history
history = self.get_clipboard_history()
print(f"[{self.name}] Total history entries: {len(history)}")
# Get limited history
recent = self.get_clipboard_history(limit=5)
print(f"[{self.name}] Recent entries (up to 5):")
for i, entry in enumerate(recent[:5], 1):
content = entry['content']
source = entry.get('source', 'unknown')
if len(content) > 40:
content = content[:40] + "..."
print(f"[{self.name}] {i}. [{source}] {content}")
def test_clear_history(self) -> None:
"""
Test clearing clipboard history.
This is a manual test method - not run automatically.
"""
print(f"[{self.name}] Clearing clipboard history...")
self.clear_clipboard_history()
history = self.get_clipboard_history()
print(f"[{self.name}] History cleared. Entries: {len(history)}")