Spaces:
Sleeping
Sleeping
File size: 7,546 Bytes
6123728 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | #!/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)
|