File size: 7,546 Bytes
88fbdc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)