File size: 4,481 Bytes
9f44dc9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
"""
Test UI integration for the algorithmic trading system
"""
import pytest
import sys
import os
from unittest.mock import patch, MagicMock
# Add project root to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def test_ui_imports():
"""Test that UI modules can be imported"""
try:
from ui import create_streamlit_app, create_dash_app, create_jupyter_interface, TradingWebSocketServer
assert True
except ImportError as e:
pytest.fail(f"Failed to import UI modules: {e}")
def test_streamlit_app_creation():
"""Test Streamlit app creation"""
try:
from ui.streamlit_app import TradingUI
ui = TradingUI()
assert ui is not None
assert hasattr(ui, 'config')
assert hasattr(ui, 'data')
assert hasattr(ui, 'alpaca_broker')
except Exception as e:
pytest.fail(f"Failed to create Streamlit UI: {e}")
def test_dash_app_creation():
"""Test Dash app creation"""
try:
from ui.dash_app import TradingDashApp
app = TradingDashApp()
assert app is not None
assert hasattr(app, 'app')
assert hasattr(app, 'config')
except Exception as e:
pytest.fail(f"Failed to create Dash app: {e}")
def test_jupyter_ui_creation():
"""Test Jupyter UI creation"""
try:
from ui.jupyter_widgets import TradingJupyterUI
ui = TradingJupyterUI()
assert ui is not None
assert hasattr(ui, 'config')
assert hasattr(ui, 'data')
except Exception as e:
pytest.fail(f"Failed to create Jupyter UI: {e}")
def test_websocket_server_creation():
"""Test WebSocket server creation"""
try:
from ui.websocket_server import TradingWebSocketServer
server = TradingWebSocketServer(host="localhost", port=8765)
assert server is not None
assert server.host == "localhost"
assert server.port == 8765
assert hasattr(server, 'clients')
except Exception as e:
pytest.fail(f"Failed to create WebSocket server: {e}")
def test_ui_launcher_imports():
"""Test UI launcher imports"""
try:
import ui_launcher
assert hasattr(ui_launcher, 'check_dependencies')
assert hasattr(ui_launcher, 'launch_streamlit')
assert hasattr(ui_launcher, 'launch_dash')
assert hasattr(ui_launcher, 'launch_jupyter')
assert hasattr(ui_launcher, 'launch_websocket_server')
except Exception as e:
pytest.fail(f"Failed to import UI launcher: {e}")
@patch('subprocess.run')
def test_ui_launcher_functions(mock_run):
"""Test UI launcher functions"""
mock_run.return_value = MagicMock()
try:
import ui_launcher
# Test dependency check
result = ui_launcher.check_dependencies()
assert isinstance(result, bool)
# Test launcher functions (they should not raise exceptions)
ui_launcher.launch_streamlit()
ui_launcher.launch_dash()
ui_launcher.launch_jupyter()
ui_launcher.launch_websocket_server()
except Exception as e:
pytest.fail(f"Failed to test UI launcher functions: {e}")
def test_ui_configuration():
"""Test UI configuration loading"""
try:
from agentic_ai_system.main import load_config
config = load_config()
# Check if UI-related config can be added
config['ui'] = {
'streamlit': {
'server_port': 8501,
'server_address': "0.0.0.0"
},
'dash': {
'server_port': 8050,
'server_address': "0.0.0.0"
}
}
assert 'ui' in config
assert 'streamlit' in config['ui']
assert 'dash' in config['ui']
except Exception as e:
pytest.fail(f"Failed to test UI configuration: {e}")
def test_ui_dependencies():
"""Test that UI dependencies are available"""
required_packages = [
'streamlit',
'dash',
'plotly',
'ipywidgets'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
except ImportError:
missing_packages.append(package)
if missing_packages:
pytest.skip(f"Missing UI dependencies: {missing_packages}")
else:
assert True
if __name__ == "__main__":
pytest.main([__file__]) |