Spaces:
Sleeping
Sleeping
| # 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() |