""" Test script for Weather Tool Run this to verify the weather tool is working correctly """ import sys from pathlib import Path # Add src to path sys.path.insert(0, str(Path(__file__).parent / "src")) from tools.weather_tool import execute_weather_tool, format_weather_response def test_weather_tool(): """Test the weather tool with sample questions""" print("="* 70) print("๐Ÿงช TESTING WEATHER TOOL") print("=" * 70) test_questions = [ "What's the weather in London?", "Show me temperature in Tokyo", "Is it raining in New York?", "Weather in Paris", "How's the weather in Los Angeles?" ] for i, question in enumerate(test_questions, 1): print(f"\n{'โ”€' * 70}") print(f"Test {i}/5") print(f"{'โ”€' * 70}") print(f"๐Ÿ“ Question: {question}") print() # Execute the weather tool result = execute_weather_tool(question) if result["success"]: print("โœ… Tool execution: SUCCESS") print() # Display raw data data = result["data"] print(f"๐Ÿ“ Location: {data['city']}, {data['country']}") print(f"๐ŸŒก๏ธ Temperature: {data['temperature']}{data['temp_unit']}") print(f"๐Ÿค” Feels like: {data['feels_like']}{data['temp_unit']}") print(f"๐Ÿ’ง Humidity: {data['humidity']}%") print(f"๐Ÿ’จ Wind: {data['wind_speed']} m/s") print(f"{data['icon']} Condition: {data['description'].title()}") print() # Generate natural language response nl_response = format_weather_response(data) print("๐Ÿค– Natural Language Response:") print(f" {nl_response}") else: print("โŒ Tool execution: FAILED") print(f" Error: {result['error']}") print(f"\n{'=' * 70}") print("โœ… Testing complete!") print("=" * 70) def check_setup(): """Check if everything is set up correctly""" print("\n" + "=" * 70) print("๐Ÿ” CHECKING SETUP") print("=" * 70) errors = [] # Check 1: .env file env_file = Path(__file__).parent / ".env" if not env_file.exists(): errors.append("โŒ .env file not found. Create it from env_template.txt") else: print("โœ… .env file exists") # Check 2: API key try: from config.credentials import CredentialsManager creds = CredentialsManager() key = creds.get_api_key("openweather") print(f"โœ… OpenWeather API key loaded: {key[:10]}...") except Exception as e: errors.append(f"โŒ API key problem: {e}") # Check 3: Dependencies try: import spacy print("โœ… spaCy installed") try: nlp = spacy.load("en_core_web_sm") print("โœ… spaCy model (en_core_web_sm) loaded") except: errors.append("โŒ spaCy model not found. Run: python -m spacy download en_core_web_sm") except ImportError: errors.append("โŒ spaCy not installed") try: import requests print("โœ… requests library installed") except ImportError: errors.append("โŒ requests library not installed") try: from dotenv import load_dotenv print("โœ… python-dotenv installed") except ImportError: errors.append("โŒ python-dotenv not installed") # Summary print("=" * 70) if errors: print("\nโš ๏ธ SETUP INCOMPLETE:") for error in errors: print(f" {error}") print("\nPlease fix the issues above before running tests.") return False else: print("\nโœ… All checks passed! Ready to test.") return True if __name__ == "__main__": print("\n" + "๐ŸŒค๏ธ WEATHER TOOL TEST SUITE" + "\n") # Check setup first if check_setup(): # Run tests test_weather_tool() else: print("\n๐Ÿ’ก Setup instructions:") print(" 1. Copy env_template.txt to .env") print(" 2. Add your OpenWeatherMap API key to .env") print(" 3. Run: conda env update -f environment.yml --prune") print(" 4. Run: python -m spacy download en_core_web_sm") print(" 5. Run this script again")