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