#!/usr/bin/env python3 """ Basic test script to verify ChatCal Voice structure. Run this to check if all imports work and basic functionality is available. """ import os import sys import asyncio from datetime import datetime # Add current directory to path for imports sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def test_imports(): """Test that all core modules import correctly.""" print("๐Ÿ” Testing imports...") try: from core.config import config print("โœ… Config imported successfully") from core.session import SessionData print("โœ… SessionData imported successfully") from core.session_manager import SessionManager print("โœ… SessionManager imported successfully") from core.llm_provider import get_llm print("โœ… LLM Provider imported successfully") from core.chat_agent import ChatCalAgent print("โœ… ChatCalAgent imported successfully") from core.calendar_service import CalendarService print("โœ… CalendarService imported successfully") from core.audio_handler import AudioHandler print("โœ… AudioHandler imported successfully") print("๐ŸŽ‰ All imports successful!") return True except Exception as e: print(f"โŒ Import error: {e}") return False def test_basic_functionality(): """Test basic functionality of core components.""" print("\n๐Ÿงช Testing basic functionality...") try: # Test config from core.config import config print(f"๐Ÿ“‹ App Name: {config.app_name}") print(f"๐Ÿ“‹ Default Voice: {config.default_voice}") # Test session creation from core.session import SessionData session = SessionData(session_id="test_session") session.add_message("user", "Hello test") print(f"๐Ÿ’ฌ Session created with {len(session.conversation_history)} messages") # Test LLM provider from core.llm_provider import get_llm llm = get_llm() print(f"๐Ÿค– LLM initialized: {type(llm).__name__}") # Test calendar service from core.calendar_service import CalendarService calendar = CalendarService() print(f"๐Ÿ“… Calendar service initialized (demo_mode: {calendar.demo_mode})") # Test audio handler from core.audio_handler import AudioHandler audio = AudioHandler() status = audio.get_audio_status() print(f"๐ŸŽต Audio handler initialized (demo_mode: {status['demo_mode']})") print("๐ŸŽ‰ Basic functionality tests passed!") return True except Exception as e: print(f"โŒ Functionality test error: {e}") return False async def test_chat_agent(): """Test the chat agent with a simple message.""" print("\n๐Ÿ’ฌ Testing chat agent...") try: from core.chat_agent import ChatCalAgent from core.session import SessionData agent = ChatCalAgent() session = SessionData(session_id="test_chat") # Test message processing response = await agent.process_message("Hello, I'm John", session) print(f"๐Ÿค– Agent response: {response[:100]}...") print(f"๐Ÿ‘ค User info extracted: {session.user_info}") print("๐ŸŽ‰ Chat agent test passed!") return True except Exception as e: print(f"โŒ Chat agent test error: {e}") return False def test_gradio_compatibility(): """Test Gradio compatibility.""" print("\n๐ŸŽจ Testing Gradio compatibility...") try: import gradio as gr print(f"โœ… Gradio version: {gr.__version__}") # Test basic Gradio components with gr.Blocks() as demo: gr.Markdown("# Test Interface") chatbot = gr.Chatbot() msg = gr.Textbox(label="Message") print("โœ… Gradio interface creation successful") print("๐ŸŽ‰ Gradio compatibility test passed!") return True except Exception as e: print(f"โŒ Gradio compatibility error: {e}") return False async def main(): """Run all tests.""" print("๐Ÿš€ ChatCal Voice - Basic Structure Test") print("=" * 50) # Set minimal environment for testing os.environ.setdefault("GROQ_API_KEY", "test_key") os.environ.setdefault("MY_PHONE_NUMBER", "+1-555-123-4567") os.environ.setdefault("MY_EMAIL_ADDRESS", "test@example.com") os.environ.setdefault("SECRET_KEY", "test_secret") tests = [ ("Imports", test_imports), ("Basic Functionality", test_basic_functionality), ("Chat Agent", test_chat_agent), ("Gradio Compatibility", test_gradio_compatibility) ] passed = 0 total = len(tests) for test_name, test_func in tests: print(f"\n{'='*20} {test_name} {'='*20}") try: if asyncio.iscoroutinefunction(test_func): result = await test_func() else: result = test_func() if result: passed += 1 except Exception as e: print(f"โŒ {test_name} failed with exception: {e}") print(f"\n{'='*50}") print(f"๐Ÿ Test Results: {passed}/{total} tests passed") if passed == total: print("๐ŸŽ‰ All tests passed! ChatCal Voice structure is ready.") print("\n๐Ÿš€ Next steps:") print("1. Update STT_SERVICE_URL and TTS_SERVICE_URL in .env") print("2. Add your actual API keys") print("3. Deploy to Hugging Face Spaces") else: print("โŒ Some tests failed. Check the errors above.") return False return True if __name__ == "__main__": asyncio.run(main())