Skip to content

Commit 2d5af2a

Browse files
authored
Enable pytest-asyncio tests in CI (#3)
* Set asyncio_mode="auto" in pytest.ini config Xref https://pytest-asyncio.readthedocs.io/en/latest/reference/configuration.html#asyncio-mode * Add test-python GitHub Actions CI workflow * Add `--color=yes` flag to force GitHub Actions logs to have color Xref pytest-dev/pytest#7443 * Refactor contents of test_api.py slightly Using some ruff rules * Delete test_api.py * Make test_get_place async * Make get_place async, and call .ainvoke method on it
1 parent 93b405c commit 2d5af2a

File tree

5 files changed

+53
-52
lines changed

5 files changed

+53
-52
lines changed

.github/workflows/test-python.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Test Python
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read # Required to checkout repository
11+
12+
jobs:
13+
pytest:
14+
name: Pytest
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.13"]
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
22+
with:
23+
persist-credentials: false
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install a specific version of uv
31+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
32+
with:
33+
version: "latest"
34+
35+
- name: Install dependencies
36+
run: uv sync
37+
38+
- name: Run pytest
39+
run: uv run pytest --verbose

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ build-backend = "hatchling.build"
3333

3434
[tool.hatch.build.targets.wheel]
3535
packages = ["src/geo_assistant"]
36+
37+
[tool.pytest.ini_options]
38+
addopts = "--color=yes"
39+
asyncio_mode = "auto"

src/geo_assistant/tools/overture.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import json
12
from typing import Annotated
3+
24
import duckdb
3-
import json
4-
from langchain_core.tools import tool
5-
from langgraph.types import Command
65
from langchain_core.messages import ToolMessage
6+
from langchain_core.tools import tool
77
from langchain_core.tools.base import InjectedToolCallId
8+
from langgraph.types import Command
89

910

1011
def create_database_connection():
@@ -15,6 +16,7 @@ def create_database_connection():
1516
1617
Returns:
1718
Configured DuckDB connection
19+
1820
"""
1921
connection = duckdb.connect()
2022
connection.execute("INSTALL spatial;")
@@ -25,7 +27,7 @@ def create_database_connection():
2527

2628

2729
@tool
28-
def get_place(
30+
async def get_place(
2931
place_name: str, tool_call_id: Annotated[str, InjectedToolCallId] = ""
3032
) -> Command:
3133
"""Get place location from Overture Maps based on user input place name."""

tests/test_api.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/tools/test_overture.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from langchain_core.tools.base import ToolCall
2+
23
from geo_assistant.tools.overture import get_place
34

45

5-
def test_get_place():
6-
command = get_place.invoke(
6+
async def test_get_place():
7+
command = await get_place.ainvoke(
78
ToolCall(
89
name="get_place",
910
type="tool_call",
1011
id="test_id",
11-
args={"place_name": "Neighboourhood Cafe Lisbon"},
12+
args={"place_name": "Neighbourhood Cafe Lisbon"},
1213
)
1314
)
1415
assert "place" in command.update

0 commit comments

Comments
 (0)