File size: 4,416 Bytes
b30f068
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
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")