| | |
| | """ |
| | 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 |
| |
|
| | |
| | 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) |
| | |
| | |
| | self.test_environment_setup() |
| | |
| | |
| | self.test_dependencies() |
| | |
| | |
| | self.test_configurations() |
| | |
| | |
| | self.test_core_modules() |
| | |
| | |
| | self.test_advanced_analytics() |
| | |
| | |
| | self.test_streamlit_ui() |
| | |
| | |
| | self.test_integration() |
| | |
| | |
| | self.test_performance() |
| | |
| | |
| | self.generate_test_report() |
| | |
| | def test_environment_setup(self): |
| | """Test environment setup""" |
| | logger.info("๐ง Testing environment setup...") |
| | |
| | |
| | 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 |
| | |
| | |
| | logger.info(f"โ
Working directory: {self.root_dir}") |
| | self.test_results['working_directory'] = True |
| | |
| | |
| | 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...") |
| | |
| | |
| | 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: |
| | |
| | from src.core.enhanced_fred_client import EnhancedFREDClient |
| | logger.info("โ
Enhanced FRED Client imported successfully") |
| | |
| | |
| | from src.analysis.economic_forecasting import EconomicForecaster |
| | logger.info("โ
Economic Forecasting imported successfully") |
| | |
| | |
| | from src.analysis.economic_segmentation import EconomicSegmentation |
| | logger.info("โ
Economic Segmentation imported successfully") |
| | |
| | |
| | from src.analysis.statistical_modeling import StatisticalModeling |
| | logger.info("โ
Statistical Modeling imported successfully") |
| | |
| | |
| | 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: |
| | |
| | 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 |
| | |
| | |
| | with open(streamlit_app, 'r') as f: |
| | content = f.read() |
| | |
| | |
| | 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: |
| | |
| | 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") |
| | |
| | |
| | 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 |
| | |
| | |
| | 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: |
| | |
| | import pandas as pd |
| | import numpy as np |
| | |
| | |
| | test_data = pd.DataFrame({ |
| | 'GDPC1': np.random.randn(1000), |
| | 'INDPRO': np.random.randn(1000), |
| | 'RSAFS': np.random.randn(1000) |
| | }) |
| | |
| | |
| | from src.analysis.economic_forecasting import EconomicForecaster |
| | from src.analysis.economic_segmentation import EconomicSegmentation |
| | from src.analysis.statistical_modeling import StatisticalModeling |
| | |
| | |
| | forecaster = EconomicForecaster(test_data) |
| | logger.info("โ
Forecasting module performance test passed") |
| | |
| | |
| | segmentation = EconomicSegmentation(test_data) |
| | logger.info("โ
Segmentation module performance test passed") |
| | |
| | |
| | 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...") |
| | |
| | |
| | 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" |
| | |
| | |
| | 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 |
| | } |
| | |
| | |
| | report_file = self.root_dir / 'system_test_report.json' |
| | with open(report_file, 'w') as f: |
| | json.dump(report, f, indent=2) |
| | |
| | |
| | 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) |
| | |
| | |
| | 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: |
| | |
| | demo_script = self.root_dir / 'scripts/comprehensive_demo.py' |
| | if demo_script.exists(): |
| | logger.info("โ
Comprehensive demo script exists") |
| | |
| | |
| | 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 |
| | |
| | |
| | analytics_script = self.root_dir / 'scripts/run_advanced_analytics.py' |
| | if analytics_script.exists(): |
| | logger.info("โ
Advanced analytics script exists") |
| | |
| | |
| | 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: |
| | |
| | tester.run_complete_system_test() |
| | |
| | |
| | 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() |