Skip to content

Commit 4ba3096

Browse files
committed
Add some workflow/actions
with a very simple python test
1 parent 7b679d3 commit 4ba3096

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: 'Common Python job setup'
2+
description: 'Perform build environment setup steps common to all Python jobs.'
3+
4+
inputs:
5+
python-version:
6+
description: 'Python version to use'
7+
required: true
8+
default: "3.13"
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Fetch git tags
14+
shell: bash
15+
run: |
16+
git fetch --tags origin
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ inputs.python-version }}
22+
allow-prereleases: true
23+
24+
- name: Install uv and set the python version
25+
uses: astral-sh/setup-uv@v6
26+
with:
27+
python-version: ${{ inputs.python-version }}
28+
29+
- name: Install the project
30+
shell: bash
31+
run: |
32+
uv sync --locked --all-extras --dev
33+
34+
- name: Pip cache
35+
uses: actions/cache@v4
36+
with:
37+
path: ~/.cache/pip
38+
key: ${{ runner.os }}-pip
39+
restore-keys: |
40+
${{ runner.os }}-pip
41+
42+
- name: "Install tools : nox"
43+
shell: bash
44+
run: |
45+
pip install --upgrade nox
46+
47+
- name: "Build Environment"
48+
shell: bash
49+
run: |
50+
printenv | sort

.github/workflows/tests.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
workflow_dispatch:
7+
workflow_call:
8+
9+
jobs:
10+
lint:
11+
name: Linting
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: Prepare common Python build environment
17+
uses: ./.github/actions/python-build-env-setup
18+
- name: 'Nox: Python Black'
19+
run: |
20+
nox -s lint
21+
22+
test:
23+
name: Test Python ${{ matrix.python-version }}
24+
runs-on: ubuntu-latest
25+
strategy:
26+
matrix:
27+
python-version: ['3.11', '3.12', '3.13']
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
- name: Set up Python ${{ matrix.python-version }}
33+
uses: actions/setup-python@v4
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
allow-prereleases: true
37+
- name: Pip cache
38+
uses: actions/cache@v4
39+
with:
40+
path: ~/.cache/pip
41+
key: ${{ runner.os }}-pip
42+
restore-keys: |
43+
${{ runner.os }}-pip
44+
- name: Test
45+
run: |
46+
pip install --upgrade nox
47+
nox -s test-${{ matrix.python-version }}

noxfile.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import nox
2+
3+
nox.options.stop_on_first_error = True
4+
nox.options.reuse_existing_virtualenvs = False
5+
6+
# Default sessions - all tests, but not packaging
7+
nox.options.sessions = [
8+
"lint",
9+
"test",
10+
]
11+
12+
_DEFAULT_PYTHON = "3.13"
13+
_ALL_PYTHON = ["3.11", "3.12", "3.13"]
14+
15+
16+
@nox.session(python=_ALL_PYTHON)
17+
def test(session):
18+
"""Run Pytest test suites"""
19+
session.run("python", "-m", "ensurepip", "--upgrade")
20+
session.install("-e", ".[test]")
21+
session.run("uv", "run", "pytest", "-vv", "tests")
22+
23+
24+
@nox.session(python=_DEFAULT_PYTHON)
25+
def lint(session):
26+
"""Check code formatting with Black"""
27+
session.install("-e", ".[dev]")
28+
session.run("black", "--verbose", "--check", "--diff", "--color", ".")
29+
session.run("ruff", "--verbose", "check", ".")

tests/__init__.py

Whitespace-only changes.

tests/test_server.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
from fastmcp import FastMCP, Client
3+
4+
5+
@pytest.fixture
6+
def test_server():
7+
mcp = FastMCP("Planet MCP Test Server")
8+
9+
## a very simple "search" test
10+
@mcp.tool
11+
def search(item_type: str) -> dict:
12+
items = {"PSScene": 123, "SkySat": 456, "Tanager": 789}
13+
return {"item_type": item_type, "temp": items.get(item_type)}
14+
15+
return mcp
16+
17+
18+
@pytest.mark.asyncio
19+
async def test_search_tool(test_server):
20+
async with Client(test_server) as client:
21+
result = await client.call_tool("search", {"item_type": "SkySat"})
22+
assert result.data == {"item_type": "SkySat", "temp": 456}

0 commit comments

Comments
 (0)