Files
d4c-service-geo-assistant/tests/tools/test_buffer.py
T
Wei Ji e3373026d6 Enable pydocstyle (D) ruff rule and add more docs (#21)
* Use pydocstyle (D) rule with google convention

Add a ruff rule to catch missing documentation. Using google convention so that undocumented-param (D417) rule is enabled to catch missing params, xref https://docs.astral.sh/ruff/rules/undocumented-param. Extended to include D213 (instead of D212) and D410 rules too.

* Fix D100 Missing docstring in public module

* Fix D101 Missing docstring in public class

* Fix D103 Missing docstring in public function

Also ignore rule D205 to allow first sentence of docstring to wrap to multiple lines.

* Fix  D417 Missing argument description in the docstring

* Update indent in pyproject.toml file
2025-12-09 08:22:01 +00:00

51 lines
1.6 KiB
Python

"""Tests for buffer tool."""
from geojson_pydantic import Feature, Point
from langchain_core.tools.base import ToolCall
from pytest import fixture
from geo_assistant.agent.state import GeoAssistantState
from geo_assistant.tools.buffer import get_search_area
@fixture
def geo_assistant_fixture():
"""Fixture with a GeoJSON point feature in a GeoAssistantState."""
place_geojson = Feature(
type="Feature",
geometry=Point(type="Point", coordinates=[-9.1393, 38.7223]),
properties={"name": "Neighbourhood Cafe Lisbon"},
)
return GeoAssistantState(
place=place_geojson,
search_area=None,
messages=[],
naip_img_bytes=None,
)
async def test_get_search_area(geo_assistant_fixture):
"""Ensure that `get_search_area` tool returns a buffer Polygon."""
# Call the underlying function directly to test the logic
# This bypasses the injection framework which is better suited for integration tests
command = await get_search_area.ainvoke(
ToolCall(
name="get_search_area",
type="tool_call",
id="test_id_search_area",
args={
"buffer_size_km": 10.0,
"state": geo_assistant_fixture,
"tool_call_id": "test_id_search_area",
},
),
)
# Verify the state was used correctly
assert "search_area" in command.update
assert "messages" in command.update
# Verify the buffer was created around the correct place
search_area = command.update["search_area"]
assert search_area.geometry.type == "Polygon"