Spaces:
Sleeping
Sleeping
File size: 4,568 Bytes
33d3592 | 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 | # final_test.py - Final comprehensive test
import os
import sys
from dotenv import load_dotenv
def test_environment():
"""Test environment configuration"""
print("π Testing Environment Configuration...")
load_dotenv(override=True)
required_vars = {
'OPENROUTER_API_KEY': os.getenv('OPENROUTER_API_KEY'),
'OPENROUTER_MODEL': os.getenv('OPENROUTER_MODEL'),
'GROQ_API_KEY': os.getenv('GROQ_API_KEY'),
'GEMINI_API_KEY': os.getenv('GEMINI_API_KEY')
}
all_good = True
for var, value in required_vars.items():
if value:
if 'KEY' in var:
print(f"β
{var}: {value[:15]}...{value[-8:]}")
else:
print(f"β
{var}: {value}")
else:
print(f"β {var}: Missing")
all_good = False
return all_good
def test_translator_fresh():
"""Test translator with fresh import"""
print("\nπ Testing Translator (Fresh Import)...")
try:
# Clear module cache
if 'translator' in sys.modules:
del sys.modules['translator']
# Fresh import
from translator import get_translator
translator = get_translator()
print(f"π OpenRouter Model: {translator.openrouter_model}")
# Test OpenRouter
result, error = translator._openrouter_complete("Say 'Hello' in Arabic")
if result:
print(f"β
OpenRouter working: {result[:50]}...")
return True
else:
print(f"β OpenRouter failed: {error}")
return False
except Exception as e:
print(f"β Translator test failed: {str(e)}")
return False
def test_ai_questions_fresh():
"""Test AI questions with fresh import"""
print("\nπ Testing AI Questions (Fresh Import)...")
try:
# Clear module cache
if 'ai_questions' in sys.modules:
del sys.modules['ai_questions']
# Fresh import
from ai_questions import get_ai_question_engine
engine = get_ai_question_engine()
# Test question processing
response, error, session_id, model_used = engine.process_question(
selected_text="This is a test text about artificial intelligence.",
question="What is this text about?",
segment_info={"id": "test"},
ui_language='en',
preferred_model='auto'
)
if response:
print(f"β
AI Questions working: {response[:50]}...")
print(f"π§ Model used: {model_used}")
return True
else:
print(f"β AI Questions failed: {error}")
return False
except Exception as e:
print(f"β AI Questions test failed: {str(e)}")
return False
def test_app_imports():
"""Test app.py imports"""
print("\nπ Testing App Imports...")
try:
# Test critical imports
from translator import get_translator
from ai_questions import get_ai_question_engine
from exporter import BroadcastExporter
from style_fixes import apply_custom_styling
print("β
All critical imports successful")
return True
except Exception as e:
print(f"β Import test failed: {str(e)}")
return False
def main():
"""Run all final tests"""
print("π Final Comprehensive Test")
print("=" * 60)
# Test environment
env_ok = test_environment()
# Test translator
translator_ok = test_translator_fresh()
# Test AI questions
ai_questions_ok = test_ai_questions_fresh()
# Test app imports
imports_ok = test_app_imports()
print("\n" + "=" * 60)
print("π Final Test Results:")
print(f" Environment: {'β
PASS' if env_ok else 'β FAIL'}")
print(f" Translator: {'β
PASS' if translator_ok else 'β FAIL'}")
print(f" AI Questions: {'β
PASS' if ai_questions_ok else 'β FAIL'}")
print(f" App Imports: {'β
PASS' if imports_ok else 'β FAIL'}")
if all([env_ok, translator_ok, ai_questions_ok, imports_ok]):
print("\nπ ALL TESTS PASSED!")
print("π‘ Your app should work perfectly now!")
print("π Run: streamlit run app.py")
return True
else:
print("\nβ οΈ Some tests failed. Check the logs above.")
return False
if __name__ == "__main__":
main() |