Spaces:
Sleeping
Sleeping
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) |