Spaces:
Sleeping

File size: 2,321 Bytes
e7cf9be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test visualization components with real data.
"""
import pytest
import pandas as pd
from datetime import datetime
import sys
from pathlib import Path

# Add src to path
sys.path.append(str(Path(__file__).parent.parent.parent / "src"))

def test_chart_creation():
    """Test that charts can be created with sample data."""
    from visualization.charts import create_line_chart, create_comparison_chart
    
    # Create sample data
    sample_data = pd.DataFrame({
        'timestamp': pd.date_range('2024-01-01', periods=5, freq='D'),
        'close_price': [100, 102, 101, 105, 103],
        'open_price': [99, 101, 100, 104, 102],
        'high_price': [101, 103, 102, 106, 104],
        'low_price': [98, 100, 99, 103, 101],
        'volume': [1000000, 1100000, 1200000, 1300000, 1400000]
    })
    
    # Test line chart creation
    fig = create_line_chart(sample_data, "Test Chart")
    assert fig is not None
    assert len(fig.data) > 0
    
    # Test comparison chart
    data_dict = {'TEST': sample_data}
    comp_fig = create_comparison_chart(data_dict, "Comparison Test")
    assert comp_fig is not None
    assert len(comp_fig.data) > 0


def test_educational_insights():
    """Test educational insights generation."""
    from visualization.educational import EducationalInsights
    
    insights = EducationalInsights()
    
    # Test market context
    context = insights.get_market_context('^GSPC')
    assert 'S&P 500' in context
    assert len(context) > 50  # Should be substantial content
    
    # Test investment basics
    basics = insights.get_investment_basics()
    assert 'diversification' in basics.lower()
    assert len(basics) > 100


def test_dashboard_functions():
    """Test dashboard utility functions."""
    from visualization.dashboard import load_available_symbols, load_indices_config
    
    # Test loading symbols (should work with real database)
    symbols = load_available_symbols()
    assert isinstance(symbols, list)
    # Should have symbols if database exists
    
    # Test loading config
    config = load_indices_config()
    assert isinstance(config, dict)
    assert 'indices' in config


if __name__ == "__main__":
    test_chart_creation()
    test_educational_insights()
    test_dashboard_functions()
    print("All visualization tests passed!")