229 lines
6.0 KiB
Python
229 lines
6.0 KiB
Python
"""
|
|
Pytest Configuration and Shared Fixtures
|
|
========================================
|
|
"""
|
|
|
|
import pytest
|
|
import sys
|
|
import json
|
|
import tempfile
|
|
import shutil
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, Mock
|
|
|
|
# Ensure project root is in path
|
|
project_root = Path(__file__).parent.parent
|
|
if str(project_root) not in sys.path:
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def project_root():
|
|
"""Return project root path."""
|
|
return Path(__file__).parent.parent
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def temp_dir():
|
|
"""Create temporary directory for test files."""
|
|
temp_path = Path(tempfile.mkdtemp(prefix="eu_test_"))
|
|
yield temp_path
|
|
shutil.rmtree(temp_path, ignore_errors=True)
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_overlay():
|
|
"""Create mock overlay window."""
|
|
overlay = MagicMock()
|
|
overlay.show = Mock()
|
|
overlay.hide = Mock()
|
|
overlay.plugin_stack = MagicMock()
|
|
overlay.sidebar_buttons = []
|
|
return overlay
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_plugin_manager(mock_overlay):
|
|
"""Create mock plugin manager."""
|
|
from core.plugin_manager import PluginManager
|
|
|
|
# Create minimal plugin manager
|
|
pm = MagicMock(spec=PluginManager)
|
|
pm.overlay = mock_overlay
|
|
pm.plugins = {}
|
|
pm.plugin_classes = {}
|
|
pm.config = {"enabled": [], "settings": {}}
|
|
|
|
def mock_is_enabled(plugin_id):
|
|
return plugin_id in pm.config["enabled"]
|
|
|
|
pm.is_plugin_enabled = mock_is_enabled
|
|
pm.get_all_plugins = Mock(return_value={})
|
|
pm.get_all_discovered_plugins = Mock(return_value={})
|
|
pm.enable_plugin = Mock(return_value=True)
|
|
pm.disable_plugin = Mock(return_value=True)
|
|
|
|
return pm
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_qt_app():
|
|
"""Create mock Qt application."""
|
|
app = MagicMock()
|
|
app.primaryScreen = Mock(return_value=MagicMock())
|
|
app.primaryScreen.return_value.geometry = Mock(return_value=MagicMock())
|
|
app.primaryScreen.return_value.geometry.return_value.width = Mock(return_value=1920)
|
|
app.primaryScreen.return_value.geometry.return_value.height = Mock(return_value=1080)
|
|
return app
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def sample_config():
|
|
"""Sample configuration for testing."""
|
|
return {
|
|
"enabled": ["plugins.calculator.plugin.CalculatorPlugin"],
|
|
"settings": {
|
|
"plugins.calculator.plugin.CalculatorPlugin": {
|
|
"precision": 2,
|
|
"auto_calculate": True
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_nexus_response():
|
|
"""Sample Nexus API response."""
|
|
return {
|
|
"success": True,
|
|
"data": [
|
|
{
|
|
"Id": 12345,
|
|
"Name": "Omegaton A104",
|
|
"Value": 150.50,
|
|
"Markup": 120.5,
|
|
"Category": "Weapon"
|
|
},
|
|
{
|
|
"Id": 12346,
|
|
"Name": "Omegaton A105",
|
|
"Value": 250.00,
|
|
"Markup": 115.0,
|
|
"Category": "Weapon"
|
|
}
|
|
]
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_window_info():
|
|
"""Mock window information."""
|
|
return {
|
|
"handle": 12345,
|
|
"title": "Entropia Universe",
|
|
"pid": 67890,
|
|
"rect": (100, 100, 1100, 700),
|
|
"width": 1000,
|
|
"height": 600,
|
|
"is_visible": True,
|
|
"is_focused": True
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_ocr_result():
|
|
"""Sample OCR result."""
|
|
return """Inventory
|
|
PED: 1500.00
|
|
Items: 45/200
|
|
TT Value: 2345.67"""
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def sample_log_lines():
|
|
"""Sample game log lines."""
|
|
return [
|
|
"[2024-02-15 14:30:25] System: You gained 0.12 points in Rifle",
|
|
"[2024-02-15 14:30:30] Loot: You received Shrapnel x 50",
|
|
"[2024-02-15 14:30:35] Loot: You received Weapon Cells x 100",
|
|
"[2024-02-15 14:30:40] Global: PlayerOne killed Feffoid (1345 PED)",
|
|
"[2024-02-15 14:31:00] System: Your VU time is 3:45:12",
|
|
]
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def event_bus():
|
|
"""Create fresh event bus instance."""
|
|
from core.event_bus import EventBus
|
|
return EventBus()
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def data_store(temp_dir):
|
|
"""Create temporary data store."""
|
|
from core.data_store import DataStore
|
|
store = DataStore(str(temp_dir / "test_data.json"))
|
|
return store
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_http_client():
|
|
"""Create mock HTTP client."""
|
|
client = MagicMock()
|
|
client.get = Mock(return_value={
|
|
"success": True,
|
|
"data": {"test": "data"},
|
|
"error": None
|
|
})
|
|
client.post = Mock(return_value={
|
|
"success": True,
|
|
"data": {"result": "ok"},
|
|
"error": None
|
|
})
|
|
return client
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def test_logger():
|
|
"""Get test logger."""
|
|
import logging
|
|
logger = logging.getLogger("eu_test")
|
|
logger.setLevel(logging.DEBUG)
|
|
handler = logging.StreamHandler()
|
|
handler.setLevel(logging.DEBUG)
|
|
formatter = logging.Formatter(
|
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
handler.setFormatter(formatter)
|
|
logger.addHandler(handler)
|
|
return logger
|
|
|
|
|
|
# Pytest hooks for custom reporting
|
|
def pytest_configure(config):
|
|
"""Configure pytest."""
|
|
config.addinivalue_line(
|
|
"markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')"
|
|
)
|
|
config.addinivalue_line(
|
|
"markers", "integration: marks tests as integration tests"
|
|
)
|
|
config.addinivalue_line(
|
|
"markers", "ui: marks tests as UI tests"
|
|
)
|
|
config.addinivalue_line(
|
|
"markers", "windows_only: tests that only run on Windows"
|
|
)
|
|
|
|
|
|
def pytest_collection_modifyitems(config, items):
|
|
"""Modify test collection."""
|
|
for item in items:
|
|
# Auto-mark slow tests
|
|
if "performance" in str(item.fspath):
|
|
item.add_marker(pytest.mark.slow)
|
|
if "integration" in str(item.fspath):
|
|
item.add_marker(pytest.mark.integration)
|
|
if "ui" in str(item.fspath):
|
|
item.add_marker(pytest.mark.ui)
|