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