File size: 16,089 Bytes
2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 26a8ea5 2b395f2 |
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
#!/usr/bin/env python3
"""
FRED ML - Complete System Test
Comprehensive testing of all system components
"""
import os
import sys
import subprocess
import logging
from pathlib import Path
from datetime import datetime
import json
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
class FREDMLSystemTest:
"""Complete system testing for FRED ML"""
def __init__(self):
self.root_dir = Path(__file__).parent.parent
self.test_results = {}
def run_complete_system_test(self):
"""Run complete system test"""
logger.info("๐งช Starting FRED ML Complete System Test")
logger.info("=" * 60)
# 1. Environment Setup Test
self.test_environment_setup()
# 2. Dependencies Test
self.test_dependencies()
# 3. Configuration Test
self.test_configurations()
# 4. Core Modules Test
self.test_core_modules()
# 5. Advanced Analytics Test
self.test_advanced_analytics()
# 6. Streamlit UI Test
self.test_streamlit_ui()
# 7. Integration Test
self.test_integration()
# 8. Performance Test
self.test_performance()
# 9. Generate Test Report
self.generate_test_report()
def test_environment_setup(self):
"""Test environment setup"""
logger.info("๐ง Testing environment setup...")
# Check Python version
python_version = sys.version_info
if python_version.major >= 3 and python_version.minor >= 8:
logger.info(f"โ
Python version: {python_version.major}.{python_version.minor}.{python_version.micro}")
self.test_results['python_version'] = True
else:
logger.error(f"โ Python version too old: {python_version}")
self.test_results['python_version'] = False
# Check working directory
logger.info(f"โ
Working directory: {self.root_dir}")
self.test_results['working_directory'] = True
# Check environment variables
required_env_vars = ['FRED_API_KEY']
env_status = True
for var in required_env_vars:
if os.getenv(var):
logger.info(f"โ
Environment variable set: {var}")
else:
logger.warning(f"โ ๏ธ Environment variable not set: {var}")
env_status = False
self.test_results['environment_variables'] = env_status
def test_dependencies(self):
"""Test dependencies"""
logger.info("๐ฆ Testing dependencies...")
required_packages = [
'pandas',
'numpy',
'scikit-learn',
'scipy',
'statsmodels',
'streamlit',
'plotly',
'boto3',
'fredapi'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
logger.info(f"โ
Package available: {package}")
except ImportError:
logger.error(f"โ Package missing: {package}")
missing_packages.append(package)
if missing_packages:
self.test_results['dependencies'] = False
logger.error(f"โ Missing packages: {missing_packages}")
else:
self.test_results['dependencies'] = True
logger.info("โ
All dependencies available")
def test_configurations(self):
"""Test configuration files"""
logger.info("โ๏ธ Testing configurations...")
config_files = [
'config/pipeline.yaml',
'config/settings.py',
'requirements.txt',
'pyproject.toml'
]
config_status = True
for config_file in config_files:
full_path = self.root_dir / config_file
if full_path.exists():
logger.info(f"โ
Configuration file exists: {config_file}")
else:
logger.error(f"โ Configuration file missing: {config_file}")
config_status = False
self.test_results['configurations'] = config_status
def test_core_modules(self):
"""Test core modules"""
logger.info("๐ง Testing core modules...")
# Add src to path
sys.path.append(str(self.root_dir / 'src'))
core_modules = [
'src.core.enhanced_fred_client',
'src.analysis.economic_forecasting',
'src.analysis.economic_segmentation',
'src.analysis.statistical_modeling',
'src.analysis.comprehensive_analytics'
]
module_status = True
for module in core_modules:
try:
__import__(module)
logger.info(f"โ
Module available: {module}")
except ImportError as e:
logger.error(f"โ Module missing: {module} - {e}")
module_status = False
self.test_results['core_modules'] = module_status
def test_advanced_analytics(self):
"""Test advanced analytics functionality"""
logger.info("๐ฎ Testing advanced analytics...")
try:
# Test Enhanced FRED Client
from src.core.enhanced_fred_client import EnhancedFREDClient
logger.info("โ
Enhanced FRED Client imported successfully")
# Test Economic Forecasting
from src.analysis.economic_forecasting import EconomicForecaster
logger.info("โ
Economic Forecasting imported successfully")
# Test Economic Segmentation
from src.analysis.economic_segmentation import EconomicSegmentation
logger.info("โ
Economic Segmentation imported successfully")
# Test Statistical Modeling
from src.analysis.statistical_modeling import StatisticalModeling
logger.info("โ
Statistical Modeling imported successfully")
# Test Comprehensive Analytics
from src.analysis.comprehensive_analytics import ComprehensiveAnalytics
logger.info("โ
Comprehensive Analytics imported successfully")
self.test_results['advanced_analytics'] = True
except Exception as e:
logger.error(f"โ Advanced analytics test failed: {e}")
self.test_results['advanced_analytics'] = False
def test_streamlit_ui(self):
"""Test Streamlit UI"""
logger.info("๐จ Testing Streamlit UI...")
try:
# Check if Streamlit app exists
streamlit_app = self.root_dir / 'frontend/app.py'
if not streamlit_app.exists():
logger.error("โ Streamlit app not found")
self.test_results['streamlit_ui'] = False
return
# Check app content
with open(streamlit_app, 'r') as f:
content = f.read()
# Check for required components
required_components = [
'st.set_page_config',
'ComprehensiveAnalytics',
'EnhancedFREDClient',
'show_executive_dashboard',
'show_advanced_analytics_page'
]
missing_components = []
for component in required_components:
if component not in content:
missing_components.append(component)
if missing_components:
logger.error(f"โ Missing components in Streamlit app: {missing_components}")
self.test_results['streamlit_ui'] = False
else:
logger.info("โ
Streamlit UI components found")
self.test_results['streamlit_ui'] = True
except Exception as e:
logger.error(f"โ Streamlit UI test failed: {e}")
self.test_results['streamlit_ui'] = False
def test_integration(self):
"""Test system integration"""
logger.info("๐ Testing system integration...")
try:
# Test FRED API connection (if API key available)
from config.settings import FRED_API_KEY
if FRED_API_KEY:
try:
from src.core.enhanced_fred_client import EnhancedFREDClient
client = EnhancedFREDClient(FRED_API_KEY)
logger.info("โ
FRED API client created successfully")
# Test series info retrieval
series_info = client.get_series_info('GDPC1')
if 'error' not in series_info:
logger.info("โ
FRED API connection successful")
self.test_results['fred_api_integration'] = True
else:
logger.warning("โ ๏ธ FRED API connection failed")
self.test_results['fred_api_integration'] = False
except Exception as e:
logger.error(f"โ FRED API integration failed: {e}")
self.test_results['fred_api_integration'] = False
else:
logger.warning("โ ๏ธ FRED API key not available, skipping API test")
self.test_results['fred_api_integration'] = False
# Test analytics integration
try:
from src.analysis.comprehensive_analytics import ComprehensiveAnalytics
logger.info("โ
Analytics integration successful")
self.test_results['analytics_integration'] = True
except Exception as e:
logger.error(f"โ Analytics integration failed: {e}")
self.test_results['analytics_integration'] = False
except Exception as e:
logger.error(f"โ Integration test failed: {e}")
self.test_results['integration'] = False
def test_performance(self):
"""Test system performance"""
logger.info("โก Testing system performance...")
try:
# Test data processing performance
import pandas as pd
import numpy as np
# Create test data
test_data = pd.DataFrame({
'GDPC1': np.random.randn(1000),
'INDPRO': np.random.randn(1000),
'RSAFS': np.random.randn(1000)
})
# Test analytics modules with test data
from src.analysis.economic_forecasting import EconomicForecaster
from src.analysis.economic_segmentation import EconomicSegmentation
from src.analysis.statistical_modeling import StatisticalModeling
# Test forecasting performance
forecaster = EconomicForecaster(test_data)
logger.info("โ
Forecasting module performance test passed")
# Test segmentation performance
segmentation = EconomicSegmentation(test_data)
logger.info("โ
Segmentation module performance test passed")
# Test statistical modeling performance
modeling = StatisticalModeling(test_data)
logger.info("โ
Statistical modeling performance test passed")
self.test_results['performance'] = True
except Exception as e:
logger.error(f"โ Performance test failed: {e}")
self.test_results['performance'] = False
def generate_test_report(self):
"""Generate comprehensive test report"""
logger.info("๐ Generating test report...")
# Calculate overall status
total_tests = len(self.test_results)
passed_tests = sum(1 for status in self.test_results.values() if status)
overall_status = "โ
PASSED" if passed_tests == total_tests else "โ FAILED"
# Generate report
report = {
"timestamp": datetime.now().isoformat(),
"overall_status": overall_status,
"summary": {
"total_tests": total_tests,
"passed_tests": passed_tests,
"failed_tests": total_tests - passed_tests,
"success_rate": f"{(passed_tests/total_tests)*100:.1f}%"
},
"detailed_results": self.test_results
}
# Save report
report_file = self.root_dir / 'system_test_report.json'
with open(report_file, 'w') as f:
json.dump(report, f, indent=2)
# Print summary
logger.info("=" * 60)
logger.info("๐ SYSTEM TEST REPORT")
logger.info("=" * 60)
logger.info(f"Overall Status: {overall_status}")
logger.info(f"Total Tests: {total_tests}")
logger.info(f"Passed: {passed_tests}")
logger.info(f"Failed: {total_tests - passed_tests}")
logger.info(f"Success Rate: {(passed_tests/total_tests)*100:.1f}%")
logger.info("=" * 60)
# Print detailed results
logger.info("Detailed Results:")
for test, status in self.test_results.items():
status_icon = "โ
" if status else "โ"
logger.info(f" {status_icon} {test}")
logger.info("=" * 60)
logger.info(f"Report saved to: {report_file}")
return report
def run_demo_tests(self):
"""Run demo tests"""
logger.info("๐ฏ Running demo tests...")
try:
# Test comprehensive demo
demo_script = self.root_dir / 'scripts/comprehensive_demo.py'
if demo_script.exists():
logger.info("โ
Comprehensive demo script exists")
# Test demo script syntax
with open(demo_script, 'r') as f:
compile(f.read(), str(demo_script), 'exec')
logger.info("โ
Comprehensive demo script syntax valid")
self.test_results['comprehensive_demo'] = True
else:
logger.error("โ Comprehensive demo script not found")
self.test_results['comprehensive_demo'] = False
# Test advanced analytics script
analytics_script = self.root_dir / 'scripts/run_advanced_analytics.py'
if analytics_script.exists():
logger.info("โ
Advanced analytics script exists")
# Test script syntax
with open(analytics_script, 'r') as f:
compile(f.read(), str(analytics_script), 'exec')
logger.info("โ
Advanced analytics script syntax valid")
self.test_results['advanced_analytics_script'] = True
else:
logger.error("โ Advanced analytics script not found")
self.test_results['advanced_analytics_script'] = False
except Exception as e:
logger.error(f"โ Demo tests failed: {e}")
self.test_results['demo_tests'] = False
def main():
"""Main test function"""
tester = FREDMLSystemTest()
try:
# Run complete system test
tester.run_complete_system_test()
# Run demo tests
tester.run_demo_tests()
logger.info("๐ Complete system test finished!")
except Exception as e:
logger.error(f"โ System test failed: {e}")
sys.exit(1)
if __name__ == "__main__":
main() |