syncmaster4 / test_system.py
aseelflihan's picture
Initial clean upload
f93a960
#!/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)