File size: 4,223 Bytes
1381148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test script to verify the LLMGuardian Dashboard installation
"""

import sys
import subprocess

def test_dependencies():
    """Test if all required dependencies are available"""
    print("=" * 60)
    print("Testing Dashboard Dependencies")
    print("=" * 60)
    
    required_packages = {
        'streamlit': '1.28.0',
        'plotly': '5.17.0',
        'pandas': '2.0.0',
        'numpy': '1.24.0',
    }
    
    optional_packages = {
        'psutil': '5.9.0',
    }
    
    all_ok = True
    
    print("\nRequired Packages:")
    for package, min_version in required_packages.items():
        try:
            mod = __import__(package)
            version = getattr(mod, '__version__', 'unknown')
            print(f"  βœ“ {package:15} {version}")
        except ImportError:
            print(f"  βœ— {package:15} NOT INSTALLED (need >={min_version})")
            all_ok = False
    
    print("\nOptional Packages:")
    for package, min_version in optional_packages.items():
        try:
            mod = __import__(package)
            version = getattr(mod, '__version__', 'unknown')
            print(f"  βœ“ {package:15} {version}")
        except ImportError:
            print(f"  ⚠ {package:15} NOT INSTALLED (optional, need >={min_version})")
    
    return all_ok


def test_dashboard_import():
    """Test if dashboard can be imported"""
    print("\n" + "=" * 60)
    print("Testing Dashboard Import")
    print("=" * 60)
    
    try:
        sys.path.insert(0, 'src')
        from llmguardian.dashboard.app import LLMGuardianDashboard
        print("  βœ“ Dashboard module imported successfully")
        
        # Try to create instance in demo mode
        dashboard = LLMGuardianDashboard(demo_mode=True)
        print("  βœ“ Dashboard instance created in demo mode")
        
        return True
    except Exception as e:
        print(f"  βœ— Error importing dashboard: {e}")
        return False


def test_demo_launcher():
    """Test if demo launcher exists and is valid"""
    print("\n" + "=" * 60)
    print("Testing Demo Launcher")
    print("=" * 60)
    
    import os
    
    files_to_check = [
        'demo_dashboard.py',
        'run_dashboard.bat',
        'run_dashboard.ps1',
        'examples_dashboard.py',
    ]
    
    all_ok = True
    for filename in files_to_check:
        if os.path.exists(filename):
            print(f"  βœ“ {filename:25} exists")
        else:
            print(f"  βœ— {filename:25} NOT FOUND")
            all_ok = False
    
    return all_ok


def test_documentation():
    """Test if documentation files exist"""
    print("\n" + "=" * 60)
    print("Testing Documentation")
    print("=" * 60)
    
    import os
    
    docs = [
        'DASHBOARD_QUICKSTART.md',
        'DASHBOARD_BUILD_SUMMARY.md',
        'src/llmguardian/dashboard/README_FULL.md',
        'requirements/dashboard.txt',
    ]
    
    all_ok = True
    for doc in docs:
        if os.path.exists(doc):
            print(f"  βœ“ {doc:45} exists")
        else:
            print(f"  βœ— {doc:45} NOT FOUND")
            all_ok = False
    
    return all_ok


def main():
    """Run all tests"""
    print("\n" + "=" * 60)
    print("LLMGuardian Dashboard Installation Test")
    print("=" * 60)
    
    results = {
        'Dependencies': test_dependencies(),
        'Dashboard Import': test_dashboard_import(),
        'Demo Launcher': test_demo_launcher(),
        'Documentation': test_documentation(),
    }
    
    print("\n" + "=" * 60)
    print("Test Summary")
    print("=" * 60)
    
    for test_name, passed in results.items():
        status = "βœ“ PASS" if passed else "βœ— FAIL"
        print(f"  {test_name:20} {status}")
    
    all_passed = all(results.values())
    
    print("\n" + "=" * 60)
    if all_passed:
        print("βœ“ All tests passed! Dashboard is ready to use.")
        print("\nTo start the dashboard, run:")
        print("  python demo_dashboard.py")
    else:
        print("⚠ Some tests failed. Please install missing dependencies:")
        print("  pip install -r requirements/dashboard.txt")
    print("=" * 60)
    
    return 0 if all_passed else 1


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