test_misspelling_fix.pyā¢4.19 kB
#!/usr/bin/env python3
"""
Test misspelling fix for city names
"""
import requests
import json
def test_misspelling_fix():
"""Test that misspelled city names are corrected."""
print("š¤ Testing City Name Misspelling Fix")
print("=" * 50)
# Test misspelled city names
misspelling_tests = [
("weather in banglore", "Bangalore"),
("weather in bengaluru", "Bangalore"),
("weather in bombay", "Mumbai"),
("weather in calcutta", "Kolkata"),
("weather in madras", "Chennai"),
("weather in new delhi", "Delhi"),
("weather in ny", "New York"),
("weather in nyc", "New York"),
("weather in la", "Los Angeles")
]
for query, expected_city in misspelling_tests:
print(f"\nš Testing: '{query}' ā Should return {expected_city}")
try:
response = requests.post(
'http://localhost:8000/api/mcp/command',
json={'command': query},
timeout=30
)
if response.status_code == 200:
result = response.json()
print(f"ā
Status: {result.get('status')}")
print(f"šÆ Type: {result.get('type')}")
print(f"š Location: {result.get('location', 'N/A')}")
# Check if it's weather response
if result.get('type') == 'weather':
print("ā
CORRECT: Routed to weather agent!")
# Check if location is corrected
actual_location = result.get('location', '')
if expected_city.lower() in actual_location.lower():
print(f"ā
CORRECT: Misspelling corrected to {actual_location}!")
else:
print(f"ā WRONG: Expected {expected_city}, got {actual_location}")
if 'current' in result:
current = result['current']
print(f"š”ļø Temperature: {current.get('temperature', 'N/A')}")
print(f"āļø Condition: {current.get('condition', 'N/A')}")
if 'summary' in result:
print(f"š Summary: {result['summary']}")
else:
print(f"ā WRONG: Routed to {result.get('type')} instead of weather")
else:
print(f"ā Request failed: {response.status_code}")
except Exception as e:
print(f"ā Error: {e}")
# Test correct spellings still work
print(f"\nā
Testing Correct Spellings Still Work:")
correct_tests = [
("weather in bangalore", "Bangalore"),
("weather in mumbai", "Mumbai"),
("weather in delhi", "Delhi"),
("weather in london", "London")
]
for query, expected_city in correct_tests:
try:
response = requests.post(
'http://localhost:8000/api/mcp/command',
json={'command': query},
timeout=30
)
if response.status_code == 200:
result = response.json()
actual_location = result.get('location', '')
print(f"š '{query}' ā {actual_location}")
if expected_city.lower() in actual_location.lower():
print(" ā
Correct spelling works!")
else:
print(f" ā Expected {expected_city}, got {actual_location}")
except Exception as e:
print(f"ā Error testing {query}: {e}")
print(f"\nšÆ MISSPELLING FIX TEST COMPLETE")
print("=" * 50)
print("ā
Common misspellings should be corrected")
print("ā
banglore ā bangalore")
print("ā
bombay ā mumbai")
print("ā
calcutta ā kolkata")
print("ā
Correct spellings should still work")
if __name__ == "__main__":
test_misspelling_fix()