GATE_Motion_Analysis / test_deployment.py
astraybirdss's picture
Upload folder using huggingface_hub
3a15d92 verified
raw
history blame
5.58 kB
#!/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)