syncmaster8 / final_test.py
aseelflihan's picture
Initial commit without node_modules
33d3592
# 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()