| """ |
| Test script for Weather Tool |
| Run this to verify the weather tool is working correctly |
| """ |
|
|
| import sys |
| from pathlib import 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() |
| |
| |
| result = execute_weather_tool(question) |
| |
| if result["success"]: |
| print("β
Tool execution: SUCCESS") |
| print() |
| |
| |
| 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() |
| |
| |
| 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 = [] |
| |
| |
| 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") |
| |
| |
| 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}") |
| |
| |
| 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") |
| |
| |
| 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") |
| |
| |
| if check_setup(): |
| |
| 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") |
|
|
|
|