-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_buffer_functionality.py
More file actions
70 lines (56 loc) · 2.47 KB
/
test_buffer_functionality.py
File metadata and controls
70 lines (56 loc) · 2.47 KB
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
#!/usr/bin/env python3
"""
Test script to verify buffer_geometry functionality works through the LLM interface.
"""
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__)))
from shapely.geometry import Point
from utils.factory import create_geospatial_analyzer
from utils.llm_function_caller import ask_with_functions
def test_buffer_functionality():
"""Test the buffer functionality through the LLM interface."""
print("🧪 Testing buffer_geometry functionality...")
# Create analyzer
analyzer = create_geospatial_analyzer()
# Test 1: Test buffer_geometry method directly
print("\n1. Testing buffer_geometry method directly...")
test_point = Point(32.8, 3.16) # Point in Lamwo, Uganda
try:
buffered = analyzer.buffer_geometry(test_point, 1000) # 1km buffer
print(f"✅ Direct buffer test successful: {type(buffered)}")
except Exception as e:
print(f"❌ Direct buffer test failed: {e}")
return False
# Test 2: Test through LLM interface
print("\n2. Testing through LLM interface...")
# Note: For this test to work, you need OpenAI API key set
if not os.environ.get("OPENAI_API_KEY"):
print("⚠️ Skipping LLM test - OPENAI_API_KEY not set")
print("✅ Core buffer functionality works!")
return True
try:
query = f"Create a 500 meter buffer around this point: {test_point.wkt}"
response = ask_with_functions(query, analyzer)
print(f"✅ LLM buffer test successful: {response[:100]}...")
except Exception as e:
print(f"❌ LLM buffer test failed: {e}")
# Don't fail the test if it's just an API issue
if "openai" in str(e).lower() or "api" in str(e).lower():
print("✅ Core buffer functionality works! (LLM API issue)")
return True
return False
print("✅ All buffer tests passed!")
return True
if __name__ == "__main__":
success = test_buffer_functionality()
if success:
print("\n🎉 Buffer functionality is ready for frontend integration!")
print("\n📋 Next steps for full end-to-end workflow:")
print(" 1. Frontend feature selection (click on minigrids)")
print(" 2. Buffer visualization on map")
print(" 3. Interactive buffer queries through chat")
print(" 4. Session management for selected features")
else:
print("\n❌ Buffer functionality needs fixes before frontend integration")
sys.exit(1)