File size: 4,117 Bytes
2469150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script for FRED ML analytics functionality
"""

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

def test_imports():
    """Test if all required modules can be imported"""
    try:
        from src.core.enhanced_fred_client import EnhancedFREDClient
        print("βœ… EnhancedFREDClient import: PASSED")
        
        from src.analysis.comprehensive_analytics import ComprehensiveAnalytics
        print("βœ… ComprehensiveAnalytics import: PASSED")
        
        from src.analysis.economic_forecasting import EconomicForecaster
        print("βœ… EconomicForecaster import: PASSED")
        
        from src.analysis.economic_segmentation import EconomicSegmentation
        print("βœ… EconomicSegmentation import: PASSED")
        
        from src.analysis.statistical_modeling import StatisticalModeling
        print("βœ… StatisticalModeling import: PASSED")
        
        return True
    except Exception as e:
        print(f"❌ Import test: FAILED ({e})")
        return False

def test_fred_client():
    """Test FRED client functionality"""
    try:
        from src.core.enhanced_fred_client import EnhancedFREDClient
        
        client = EnhancedFREDClient("acf8bbec7efe3b6dfa6ae083e7152314")
        
        # Test basic functionality - check for the correct method names
        if hasattr(client, 'fetch_economic_data') and hasattr(client, 'fetch_quarterly_data'):
            print("βœ… FRED Client structure: PASSED")
            return True
        else:
            print("❌ FRED Client structure: FAILED")
            return False
    except Exception as e:
        print(f"❌ FRED Client test: FAILED ({e})")
        return False

def test_analytics_structure():
    """Test analytics module structure"""
    try:
        from src.analysis.comprehensive_analytics import ComprehensiveAnalytics
        
        # Test if the class has required methods
        analytics = ComprehensiveAnalytics("acf8bbec7efe3b6dfa6ae083e7152314")
        
        required_methods = [
            'run_complete_analysis',
            '_run_statistical_analysis',
            '_run_forecasting_analysis', 
            '_run_segmentation_analysis',
            '_extract_insights'
        ]
        
        for method in required_methods:
            if hasattr(analytics, method):
                print(f"βœ… Method {method}: PASSED")
            else:
                print(f"❌ Method {method}: FAILED")
                return False
        
        return True
    except Exception as e:
        print(f"❌ Analytics structure test: FAILED ({e})")
        return False

def test_config():
    """Test configuration loading"""
    try:
        # Test if config can be loaded
        import os
        fred_key = os.getenv('FRED_API_KEY', 'acf8bbec7efe3b6dfa6ae083e7152314')
        
        if fred_key and len(fred_key) > 10:
            print("βœ… Configuration loading: PASSED")
            return True
        else:
            print("❌ Configuration loading: FAILED")
            return False
    except Exception as e:
        print(f"❌ Configuration test: FAILED ({e})")
        return False

def main():
    """Run all analytics tests"""
    print("πŸ§ͺ Testing FRED ML Analytics...")
    print("=" * 50)
    
    tests = [
        ("Module Imports", test_imports),
        ("FRED Client", test_fred_client),
        ("Analytics Structure", test_analytics_structure),
        ("Configuration", test_config),
    ]
    
    passed = 0
    total = len(tests)
    
    for test_name, test_func in tests:
        print(f"\nπŸ” Testing: {test_name}")
        if test_func():
            passed += 1
    
    print("\n" + "=" * 50)
    print(f"πŸ“Š Analytics Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All analytics tests passed! The analytics modules are working correctly.")
        return 0
    else:
        print("⚠️  Some analytics tests failed. Check the module imports and structure.")
        return 1

if __name__ == "__main__":
    sys.exit(main())