#!/usr/bin/env python3 """ System Test Script for SyncMaster Enhanced سكريبت اختبار النظام لـ SyncMaster المحسن """ import os import sys import traceback from pathlib import Path def test_imports(): """Test all required imports""" print("🔍 Testing imports...") tests = [ ('google.genai', 'Google Generative AI'), ('librosa', 'LibROSA'), ('soundfile', 'SoundFile'), ('streamlit', 'Streamlit'), ('flask', 'Flask'), ('dotenv', 'Python-dotenv'), ] failed_imports = [] for module, name in tests: try: __import__(module) print(f" ✅ {name}") except ImportError as e: print(f" ❌ {name}: {e}") failed_imports.append(name) return len(failed_imports) == 0 def test_env_file(): """Test environment configuration""" print("\n🔑 Testing environment...") if not Path('.env').exists(): print(" ❌ .env file not found") return False try: from dotenv import load_dotenv load_dotenv() api_key = os.getenv("GEMINI_API_KEY") if not api_key: print(" ❌ GEMINI_API_KEY not found in .env") return False elif api_key == "your_api_key_here": print(" ⚠️ GEMINI_API_KEY needs to be replaced with actual key") return False else: print(f" ✅ GEMINI_API_KEY configured (length: {len(api_key)})") return True except Exception as e: print(f" ❌ Error reading .env: {e}") return False def test_translator(): """Test translator initialization""" print("\n🌐 Testing translator...") try: from translator import AITranslator, get_translator # Test direct initialization translator = AITranslator() if translator.init_error: print(f" ❌ Translator init error: {translator.init_error}") return False print(" ✅ Translator initialized successfully") # Test simple translation test_text = "Hello, this is a test" translated, error = translator.translate_text(test_text, 'ar') if error: print(f" ❌ Translation test failed: {error}") return False elif translated: print(f" ✅ Translation test successful: '{test_text}' → '{translated}'") return True else: print(" ⚠️ Translation returned empty result") return False except Exception as e: print(f" ❌ Translator test failed: {e}") print(f" 🔍 Traceback: {traceback.format_exc()}") return False def test_audio_processor(): """Test audio processor initialization""" print("\n🎵 Testing audio processor...") try: from audio_processor import AudioProcessor processor = AudioProcessor() if processor.init_error: print(f" ❌ Audio processor init error: {processor.init_error}") return False print(" ✅ Audio processor initialized successfully") # Check if translator is available if processor.translator: print(" ✅ Translator integration available") else: print(" ⚠️ Translator integration not available") return True except Exception as e: print(f" ❌ Audio processor test failed: {e}") print(f" 🔍 Traceback: {traceback.format_exc()}") return False def test_server_components(): """Test server components""" print("\n🖥️ Testing server components...") try: from recorder_server import app print(" ✅ Recorder server imports OK") # Test routes with app.test_client() as client: # Test health check response = client.get('/record') if response.status_code == 200: print(" ✅ Health check endpoint working") else: print(f" ⚠️ Health check returned {response.status_code}") # Test languages endpoint response = client.get('/languages') if response.status_code == 200: print(" ✅ Languages endpoint working") else: print(f" ⚠️ Languages endpoint returned {response.status_code}") return True except Exception as e: print(f" ❌ Server test failed: {e}") print(f" 🔍 Traceback: {traceback.format_exc()}") return False def test_ui_translations(): """Test UI translations""" print("\n🎨 Testing UI translations...") try: from translator import UI_TRANSLATIONS, get_translation # Test English translations en_keys = len(UI_TRANSLATIONS.get('en', {})) ar_keys = len(UI_TRANSLATIONS.get('ar', {})) print(f" ✅ English translations: {en_keys} keys") print(f" ✅ Arabic translations: {ar_keys} keys") if en_keys != ar_keys: print(f" ⚠️ Translation key count mismatch: EN={en_keys}, AR={ar_keys}") # Test translation function test_key = 'start_recording' en_text = get_translation(test_key, 'en') ar_text = get_translation(test_key, 'ar') print(f" ✅ Test translation: '{en_text}' → '{ar_text}'") return True except Exception as e: print(f" ❌ UI translations test failed: {e}") return False def main(): """Run all tests""" print("=" * 60) print("🧪 SyncMaster Enhanced - System Test") print("اختبار النظام الشامل لـ SyncMaster المحسن") print("=" * 60) # Change to script directory script_dir = Path(__file__).parent os.chdir(script_dir) print(f"📁 Working directory: {script_dir}") tests = [ ("Import Test", test_imports), ("Environment Test", test_env_file), ("Translator Test", test_translator), ("Audio Processor Test", test_audio_processor), ("Server Components Test", test_server_components), ("UI Translations Test", test_ui_translations), ] results = {} for test_name, test_func in tests: try: results[test_name] = test_func() except Exception as e: print(f"\n❌ {test_name} crashed: {e}") results[test_name] = False # Summary print("\n" + "=" * 60) print("📊 TEST SUMMARY / ملخص الاختبار") print("=" * 60) passed = sum(results.values()) total = len(results) for test_name, result in results.items(): status = "✅ PASS" if result else "❌ FAIL" print(f" {status} {test_name}") print(f"\n🎯 Results: {passed}/{total} tests passed") if passed == total: print("🎉 All tests passed! System is ready to use.") print("🚀 You can now run: python start_debug.py") else: print("⚠️ Some tests failed. Please fix the issues before running the application.") print("📝 Check the error messages above for details.") return passed == total if __name__ == "__main__": success = main() sys.exit(0 if success else 1)