File size: 5,582 Bytes
3a15d92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""

Test script for GATE Motion Analysis Gradio deployment.

Verifies that all components work correctly before deployment.

"""

import sys
import traceback
from pathlib import Path

def test_imports():
    """Test that all required imports work."""
    print("πŸ” Testing imports...")
    
    try:
        import gradio as gr
        print("βœ… Gradio import successful")
    except ImportError as e:
        print(f"❌ Gradio import failed: {e}")
        return False
    
    try:
        import numpy as np
        print("βœ… NumPy import successful")
    except ImportError as e:
        print(f"❌ NumPy import failed: {e}")
        return False
    
    try:
        import cv2
        print("βœ… OpenCV import successful")
    except ImportError as e:
        print(f"❌ OpenCV import failed: {e}")
        return False
    
    try:
        from PIL import Image
        print("βœ… Pillow import successful")
    except ImportError as e:
        print(f"❌ Pillow import failed: {e}")
        return False
    
    return True

def test_app_components():
    """Test that app components can be imported."""
    print("\nπŸ” Testing app components...")
    
    try:
        from app import SimpleMotionAnalyzer, create_interface, get_system_info
        print("βœ… App components import successful")
    except ImportError as e:
        print(f"❌ App components import failed: {e}")
        return False
    
    try:
        from config import get_app_info, LAUNCH_CONFIG
        print("βœ… Config import successful")
    except ImportError as e:
        print(f"❌ Config import failed: {e}")
        return False
    
    return True

def test_analyzer():
    """Test the motion analyzer."""
    print("\nπŸ” Testing motion analyzer...")
    
    try:
        from app import SimpleMotionAnalyzer
        import numpy as np
        
        analyzer = SimpleMotionAnalyzer()
        
        # Test with dummy frame
        dummy_frame = np.zeros((480, 640, 3), dtype=np.uint8)
        result = analyzer.analyze_frame(dummy_frame)
        
        if len(result) == 4:
            frame, status, confidence, feedback = result
            print(f"βœ… Analyzer test successful")
            print(f"   Status: {status}")
            print(f"   Confidence: {confidence}")
            print(f"   Feedback: {feedback[:50]}...")
            return True
        else:
            print("❌ Analyzer returned unexpected result format")
            return False
            
    except Exception as e:
        print(f"❌ Analyzer test failed: {e}")
        traceback.print_exc()
        return False

def test_interface_creation():
    """Test that the Gradio interface can be created."""
    print("\nπŸ” Testing interface creation...")
    
    try:
        from app import create_interface
        
        interface = create_interface()
        
        if interface is not None:
            print("βœ… Interface creation successful")
            return True
        else:
            print("❌ Interface creation returned None")
            return False
            
    except Exception as e:
        print(f"❌ Interface creation failed: {e}")
        traceback.print_exc()
        return False

def test_config():
    """Test configuration settings."""
    print("\nπŸ” Testing configuration...")
    
    try:
        from config import get_app_info, get_system_status, LAUNCH_CONFIG
        
        app_info = get_app_info()
        system_status = get_system_status()
        
        print(f"βœ… Configuration test successful")
        print(f"   App: {app_info['name']} v{app_info['version']}")
        print(f"   Debug: {app_info['debug_mode']}")
        print(f"   GPU: {app_info['gpu_enabled']}")
        print(f"   Launch config keys: {list(LAUNCH_CONFIG.keys())}")
        
        return True
        
    except Exception as e:
        print(f"❌ Configuration test failed: {e}")
        traceback.print_exc()
        return False

def run_all_tests():
    """Run all tests and return overall result."""
    print("πŸš€ Starting GATE Motion Analysis deployment tests...\n")
    
    tests = [
        ("Import Test", test_imports),
        ("App Components Test", test_app_components),
        ("Analyzer Test", test_analyzer),
        ("Interface Creation Test", test_interface_creation),
        ("Configuration Test", test_config)
    ]
    
    results = []
    
    for test_name, test_func in tests:
        try:
            result = test_func()
            results.append((test_name, result))
        except Exception as e:
            print(f"❌ {test_name} crashed: {e}")
            results.append((test_name, False))
    
    # Summary
    print("\n" + "="*50)
    print("πŸ“Š TEST SUMMARY")
    print("="*50)
    
    passed = 0
    total = len(results)
    
    for test_name, result in results:
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"{status} {test_name}")
        if result:
            passed += 1
    
    print(f"\nResults: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! Deployment should work correctly.")
        return True
    else:
        print("⚠️  Some tests failed. Check errors above before deploying.")
        return False

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