"""
GeoSight MCP Server Tests
"""
import pytest
import numpy as np
from unittest.mock import AsyncMock, patch
class TestGeocoding:
"""Tests for geocoding utilities."""
@pytest.mark.asyncio
async def test_resolve_location_with_coords(self):
from geosight.tools.geocoding import resolve_location
lat, lon, name = await resolve_location(latitude=40.7128, longitude=-74.0060)
assert lat == 40.7128
assert lon == -74.0060
@pytest.mark.asyncio
async def test_geocode_location_name(self):
pass # Mocked test
class TestGeoUtils:
"""Tests for geospatial utilities."""
def test_create_bbox_from_point(self):
from geosight.utils.geo import create_bbox_from_point
bbox = create_bbox_from_point(40.0, -74.0, 10.0)
assert bbox.south < 40.0 < bbox.north
assert bbox.west < -74.0 < bbox.east
def test_haversine_distance(self):
from geosight.utils.geo import haversine_distance
distance = haversine_distance(40.7128, -74.0060, 34.0522, -118.2437)
assert 3900 < distance < 4000
def test_bbox_to_polygon(self):
from geosight.utils.geo import BoundingBox
bbox = BoundingBox(west=-74.0, south=40.0, east=-73.0, north=41.0)
coords = bbox.to_polygon_coords()
assert len(coords) == 5
class TestVisualization:
"""Tests for visualization utilities."""
def test_create_index_colormap_ndvi(self):
from geosight.utils.visualization import create_index_colormap
data = np.array([[0.0, 0.5], [0.3, 0.8]])
rgb = create_index_colormap(data, "ndvi")
assert rgb.shape == (2, 2, 3)
def test_array_to_base64_png(self):
from geosight.utils.visualization import array_to_base64_png
image = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
base64_str = array_to_base64_png(image)
assert isinstance(base64_str, str)
def test_create_classification_map(self):
from geosight.utils.visualization import create_classification_map
classification = np.array([[0, 1], [2, 0]])
colors = {0: "#FF0000", 1: "#00FF00", 2: "#0000FF"}
rgb = create_classification_map(classification, colors)
assert rgb.shape == (2, 2, 3)
class TestIndices:
"""Tests for spectral index calculations."""
@pytest.mark.asyncio
async def test_ndvi_calculation(self):
from geosight.tools.indices import calculate_ndvi
result = await calculate_ndvi(
start_date="2024-01-01", end_date="2024-01-31",
latitude=40.0, longitude=-74.0, radius_km=5.0,
)
assert "summary" in result
@pytest.mark.asyncio
async def test_ndwi_calculation(self):
from geosight.tools.indices import calculate_ndwi
result = await calculate_ndwi(
start_date="2024-01-01", end_date="2024-01-31",
latitude=40.0, longitude=-74.0,
)
assert "summary" in result
class TestModels:
"""Tests for ML models."""
@pytest.mark.asyncio
async def test_land_cover_classifier(self):
from geosight.models.land_cover import LandCoverClassifier
classifier = LandCoverClassifier()
image = np.random.rand(256, 256, 3)
classification, confidence = await classifier.classify(image)
assert classification.shape == (256, 256)
@pytest.mark.asyncio
async def test_change_detector(self):
from geosight.models.change_detector import ChangeDetector
detector = ChangeDetector()
before = np.random.rand(100, 100)
after = np.random.rand(100, 100)
mask, magnitude = await detector.detect(before, after)
assert mask.shape == (100, 100)
@pytest.mark.asyncio
async def test_object_detector(self):
from geosight.models.object_detector import ObjectDetector
detector = ObjectDetector()
image = np.random.randint(0, 255, (512, 512, 3), dtype=np.uint8)
detections = await detector.detect(image)
assert isinstance(detections, list)
class TestCache:
"""Tests for caching utilities."""
@pytest.mark.asyncio
async def test_in_memory_cache(self):
from geosight.utils.cache import InMemoryCache
cache = InMemoryCache(max_size=10)
await cache.set("key1", {"data": "value1"})
result = await cache.get("key1")
assert result == {"data": "value1"}
@pytest.mark.asyncio
async def test_cache_ttl(self):
import asyncio
from geosight.utils.cache import InMemoryCache
cache = InMemoryCache(default_ttl=1)
await cache.set("key1", "value1", ttl=1)
assert await cache.get("key1") == "value1"
await asyncio.sleep(1.5)
assert await cache.get("key1") is None
class TestTools:
"""Integration tests for MCP tools."""
@pytest.mark.asyncio
async def test_search_imagery(self):
from geosight.tools.imagery import search_imagery
result = await search_imagery(
start_date="2024-01-01", end_date="2024-01-31",
latitude=40.0, longitude=-74.0,
)
assert "summary" in result
@pytest.mark.asyncio
async def test_detect_land_cover(self):
from geosight.tools.classification import detect_land_cover
result = await detect_land_cover(
date="2024-01-15", latitude=40.0, longitude=-74.0, radius_km=5.0,
)
assert "summary" in result
@pytest.mark.asyncio
async def test_generate_report(self):
from geosight.tools.reports import generate_report
result = await generate_report(
start_date="2024-01-01", end_date="2024-01-31",
latitude=40.0, longitude=-74.0, analyses=["ndvi"],
)
assert "summary" in result