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