Team Ai
Modelpublic

ParallelLLC/algorithmic_trading

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
27likes32downloads
test_ui_integration.py147 linesDownload Raw Back to tests
1"""2Test UI integration for the algorithmic trading system3"""4 5import pytest6import sys7import os8from unittest.mock import patch, MagicMock9 10# Add project root to path11sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))12 13def test_ui_imports():14    """Test that UI modules can be imported"""15    try:16        from ui import create_streamlit_app, create_dash_app, create_jupyter_interface, TradingWebSocketServer17        assert True18    except ImportError as e:19        pytest.fail(f"Failed to import UI modules: {e}")20 21def test_streamlit_app_creation():22    """Test Streamlit app creation"""23    try:24        from ui.streamlit_app import TradingUI25        ui = TradingUI()26        assert ui is not None27        assert hasattr(ui, 'config')28        assert hasattr(ui, 'data')29        assert hasattr(ui, 'alpaca_broker')30    except Exception as e:31        pytest.fail(f"Failed to create Streamlit UI: {e}")32 33def test_dash_app_creation():34    """Test Dash app creation"""35    try:36        from ui.dash_app import TradingDashApp37        app = TradingDashApp()38        assert app is not None39        assert hasattr(app, 'app')40        assert hasattr(app, 'config')41    except Exception as e:42        pytest.fail(f"Failed to create Dash app: {e}")43 44def test_jupyter_ui_creation():45    """Test Jupyter UI creation"""46    try:47        from ui.jupyter_widgets import TradingJupyterUI48        ui = TradingJupyterUI()49        assert ui is not None50        assert hasattr(ui, 'config')51        assert hasattr(ui, 'data')52    except Exception as e:53        pytest.fail(f"Failed to create Jupyter UI: {e}")54 55def test_websocket_server_creation():56    """Test WebSocket server creation"""57    try:58        from ui.websocket_server import TradingWebSocketServer59        server = TradingWebSocketServer(host="localhost", port=8765)60        assert server is not None61        assert server.host == "localhost"62        assert server.port == 876563        assert hasattr(server, 'clients')64    except Exception as e:65        pytest.fail(f"Failed to create WebSocket server: {e}")66 67def test_ui_launcher_imports():68    """Test UI launcher imports"""69    try:70        import ui_launcher71        assert hasattr(ui_launcher, 'check_dependencies')72        assert hasattr(ui_launcher, 'launch_streamlit')73        assert hasattr(ui_launcher, 'launch_dash')74        assert hasattr(ui_launcher, 'launch_jupyter')75        assert hasattr(ui_launcher, 'launch_websocket_server')76    except Exception as e:77        pytest.fail(f"Failed to import UI launcher: {e}")78 79@patch('subprocess.run')80def test_ui_launcher_functions(mock_run):81    """Test UI launcher functions"""82    mock_run.return_value = MagicMock()83    84    try:85        import ui_launcher86        87        # Test dependency check88        result = ui_launcher.check_dependencies()89        assert isinstance(result, bool)90        91        # Test launcher functions (they should not raise exceptions)92        ui_launcher.launch_streamlit()93        ui_launcher.launch_dash()94        ui_launcher.launch_jupyter()95        ui_launcher.launch_websocket_server()96        97    except Exception as e:98        pytest.fail(f"Failed to test UI launcher functions: {e}")99 100def test_ui_configuration():101    """Test UI configuration loading"""102    try:103        from agentic_ai_system.main import load_config104        config = load_config()105        106        # Check if UI-related config can be added107        config['ui'] = {108            'streamlit': {109                'server_port': 8501,110                'server_address': "0.0.0.0"111            },112            'dash': {113                'server_port': 8050,114                'server_address': "0.0.0.0"115            }116        }117        118        assert 'ui' in config119        assert 'streamlit' in config['ui']120        assert 'dash' in config['ui']121        122    except Exception as e:123        pytest.fail(f"Failed to test UI configuration: {e}")124 125def test_ui_dependencies():126    """Test that UI dependencies are available"""127    required_packages = [128        'streamlit',129        'dash',130        'plotly',131        'ipywidgets'132    ]133    134    missing_packages = []135    for package in required_packages:136        try:137            __import__(package)138        except ImportError:139            missing_packages.append(package)140    141    if missing_packages:142        pytest.skip(f"Missing UI dependencies: {missing_packages}")143    else:144        assert True145 146if __name__ == "__main__":147    pytest.main([__file__])