Spaces:
Sleeping
Sleeping
Download tests/test_visualization/test_basic.py from MikeZhang09/marketwise: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/spaces/MikeZhang09/marketwise/resolve/main/tests/test_visualization/test_basic.py
- Command line
-
hf download hf://spaces/MikeZhang09/marketwise/tests/test_visualization/test_basic.py
-
curl -L -o test_basic.py https://huggingface.co/spaces/MikeZhang09/marketwise/resolve/main/tests/test_visualization/test_basic.py
2.32 kB
| """ | |
| 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!") | |