File size: 4,758 Bytes
26a8ea5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
FRED ML - Streamlit UI Test
Simple test to validate Streamlit UI functionality
"""

import os
import sys
import subprocess
from pathlib import Path

def test_streamlit_ui():
    """Test Streamlit UI functionality"""
    print("🎨 Testing Streamlit UI...")
    
    # Check if Streamlit app exists
    app_path = Path(__file__).parent.parent / 'frontend/app.py'
    if not app_path.exists():
        print("❌ Streamlit app not found")
        return False
    
    print("βœ… Streamlit app exists")
    
    # Check app content
    with open(app_path, 'r') as f:
        content = f.read()
    
    # Check for required components
    required_components = [
        'st.set_page_config',
        'show_executive_dashboard',
        'show_advanced_analytics_page',
        'show_indicators_page',
        'show_reports_page',
        'show_configuration_page'
    ]
    
    missing_components = []
    for component in required_components:
        if component not in content:
            missing_components.append(component)
    
    if missing_components:
        print(f"❌ Missing components in Streamlit app: {missing_components}")
        return False
    else:
        print("βœ… All required Streamlit components found")
    
    # Check for enterprise styling
    styling_components = [
        'main-header',
        'metric-card',
        'analysis-section',
        'chart-container'
    ]
    
    missing_styling = []
    for component in styling_components:
        if component not in content:
            missing_styling.append(component)
    
    if missing_styling:
        print(f"⚠️ Missing styling components: {missing_styling}")
    else:
        print("βœ… Enterprise styling components found")
    
    # Check for analytics integration
    analytics_components = [
        'ComprehensiveAnalytics',
        'EnhancedFREDClient',
        'display_analysis_results'
    ]
    
    missing_analytics = []
    for component in analytics_components:
        if component not in content:
            missing_analytics.append(component)
    
    if missing_analytics:
        print(f"⚠️ Missing analytics components: {missing_analytics}")
    else:
        print("βœ… Analytics integration components found")
    
    print("βœ… Streamlit UI test passed")
    return True

def test_streamlit_syntax():
    """Test Streamlit app syntax"""
    print("πŸ” Testing Streamlit app syntax...")
    
    app_path = Path(__file__).parent.parent / 'frontend/app.py'
    
    try:
        with open(app_path, 'r') as f:
            compile(f.read(), str(app_path), 'exec')
        print("βœ… Streamlit app syntax is valid")
        return True
    except SyntaxError as e:
        print(f"❌ Streamlit app syntax error: {e}")
        return False
    except Exception as e:
        print(f"❌ Error testing syntax: {e}")
        return False

def test_streamlit_launch():
    """Test if Streamlit can launch the app"""
    print("πŸš€ Testing Streamlit launch capability...")
    
    try:
        # Test if streamlit is available
        result = subprocess.run(
            ['streamlit', '--version'],
            capture_output=True,
            text=True
        )
        
        if result.returncode == 0:
            print(f"βœ… Streamlit version: {result.stdout.strip()}")
            return True
        else:
            print("❌ Streamlit not available")
            return False
            
    except FileNotFoundError:
        print("❌ Streamlit not installed")
        return False
    except Exception as e:
        print(f"❌ Error testing Streamlit: {e}")
        return False

def main():
    """Main test function"""
    print("πŸ§ͺ Starting Streamlit UI Test")
    print("=" * 50)
    
    # Test 1: UI Components
    ui_test = test_streamlit_ui()
    
    # Test 2: Syntax
    syntax_test = test_streamlit_syntax()
    
    # Test 3: Launch capability
    launch_test = test_streamlit_launch()
    
    # Summary
    print("\n" + "=" * 50)
    print("πŸ“Š STREAMLIT UI TEST RESULTS")
    print("=" * 50)
    
    tests = [
        ("UI Components", ui_test),
        ("Syntax Check", syntax_test),
        ("Launch Capability", launch_test)
    ]
    
    passed = 0
    for test_name, result in tests:
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"{test_name}: {status}")
        if result:
            passed += 1
    
    print(f"\nOverall: {passed}/{len(tests)} tests passed")
    
    if passed == len(tests):
        print("πŸŽ‰ All Streamlit UI tests passed!")
        return True
    else:
        print("❌ Some Streamlit UI tests failed")
        return False

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)