Skip to content

Commit 261dc06

Browse files
inntranclaude
andcommitted
Add test infrastructure and GitHub Actions workflow
This commit adds comprehensive test suite and CI/CD setup: - Add GitHub Actions workflow for automated testing - Tests on Python 3.9-3.13 (ordered by real-world likelihood) - Includes linting (flake8), formatting (black), import sorting (isort), and type checking (mypy) - Uploads coverage to Codecov - Add comprehensive test suite covering: - Client initialization and HTTP methods - Error handling (auth, network, API errors) - Environment configurations - Custom exception classes - Data models (BaseModel, BaseResponse) - Pools resource operations - Update pyproject.toml: - Switch to Hatchling build backend - Add requests dependency - Add dev dependencies (pytest, black, flake8, isort, mypy) - Configure tool settings for linting and testing - Fix TOML syntax for project URLs Tests are expected to fail until source code is added. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 294c844 commit 261dc06

9 files changed

Lines changed: 703 additions & 5 deletions

File tree

.github/workflows/test.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop, staging ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.14", "3.12", "3.13", "3.9", "3.10", "3.11" ]
16+
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v6
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
cache: 'pip'
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -e ".[dev]"
30+
31+
- name: Lint with flake8
32+
run: |
33+
# Stop the build if there are Python syntax errors or undefined names
34+
flake8 src/tmo_api --count --select=E9,F63,F7,F82 --show-source --statistics
35+
# Exit-zero treats all errors as warnings
36+
flake8 src/tmo_api --count --exit-zero --max-line-length=88 --extend-ignore=E203,W503 --statistics
37+
38+
- name: Check formatting with black
39+
run: |
40+
black --check src/tmo_api tests/
41+
42+
- name: Check import sorting with isort
43+
run: |
44+
isort --check-only src/tmo_api tests/
45+
46+
- name: Type check with mypy
47+
run: |
48+
mypy src/tmo_api --ignore-missing-imports
49+
continue-on-error: true
50+
51+
- name: Run tests with pytest
52+
run: |
53+
pytest tests/ -v --cov=tmo_api --cov-report=xml --cov-report=term
54+
55+
- name: Upload coverage to Codecov
56+
if: matrix.python-version == '3.11'
57+
uses: codecov/codecov-action@v5
58+
env:
59+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
60+
with:
61+
file: ./coverage.xml
62+
fail_ci_if_error: false

pyproject.toml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ authors = [
88
{ name = "Yinchuan Song", email = "songyinchuan@gmail.com" }
99
]
1010
requires-python = ">=3.9"
11-
dependencies = []
11+
dependencies = [
12+
"requests>=2.25.0,<3.0.0",
13+
]
1214
keywords = ["TMO", "The Mortgage Office", "Mortgage Pools", "Mortgage Pool Shares"]
1315
classifiers = [
1416
"Development Status :: 4 - Beta",
@@ -29,9 +31,40 @@ classifiers = [
2931
]
3032

3133
[project.urls]
32-
Repository = https://github.com/inntran/tmo-api-python
33-
Issues = https://github.com/inntran/tmo-api-python/issues
34+
Repository = "https://github.com/inntran/tmo-api-python"
35+
Issues = "https://github.com/inntran/tmo-api-python/issues"
36+
37+
[project.optional-dependencies]
38+
dev = [
39+
"pytest>=7.0.0",
40+
"pytest-cov>=4.0.0",
41+
"black>=23.0.0",
42+
"flake8>=6.0.0",
43+
"isort>=5.12.0",
44+
"mypy>=1.0.0",
45+
]
3446

3547
[build-system]
36-
requires = ["uv_build>=0.9.5,<0.10.0"]
37-
build-backend = "uv_build"
48+
requires = ["hatchling"]
49+
build-backend = "hatchling.build"
50+
51+
[tool.hatch.build.targets.wheel]
52+
packages = ["src/tmo_api"]
53+
54+
[tool.black]
55+
line-length = 100
56+
target-version = ['py39', 'py310', 'py311', 'py312', 'py313', 'py314']
57+
58+
[tool.isort]
59+
profile = "black"
60+
line_length = 100
61+
62+
[tool.mypy]
63+
python_version = "3.9"
64+
warn_return_any = true
65+
warn_unused_configs = true
66+
disallow_untyped_defs = false
67+
68+
[tool.pytest.ini_options]
69+
testpaths = ["tests"]
70+
addopts = "--cov=tmo_api --cov-report=term-missing --cov-report=xml"

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for tmo_api package."""

tests/conftest.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Pytest configuration and fixtures."""
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def mock_token():
8+
"""Mock API token for testing."""
9+
return "test_token_12345"
10+
11+
12+
@pytest.fixture
13+
def mock_database():
14+
"""Mock database name for testing."""
15+
return "test_database"
16+
17+
18+
@pytest.fixture
19+
def mock_pool_account():
20+
"""Mock pool account for testing."""
21+
return "POOL001"
22+
23+
24+
@pytest.fixture
25+
def mock_api_response_success():
26+
"""Mock successful API response."""
27+
return {
28+
"Status": 0,
29+
"ErrorMessage": None,
30+
"ErrorNumber": None,
31+
"Data": {"rec_id": 1, "account": "POOL001", "name": "Test Pool"},
32+
}
33+
34+
35+
@pytest.fixture
36+
def mock_api_response_error():
37+
"""Mock error API response."""
38+
return {
39+
"Status": 1,
40+
"ErrorMessage": "Test error message",
41+
"ErrorNumber": 500,
42+
"Data": None,
43+
}
44+
45+
46+
@pytest.fixture
47+
def mock_pools_response():
48+
"""Mock pools list response."""
49+
return {
50+
"Status": 0,
51+
"ErrorMessage": None,
52+
"ErrorNumber": None,
53+
"Data": [
54+
{"rec_id": 1, "account": "POOL001", "name": "Pool 1"},
55+
{"rec_id": 2, "account": "POOL002", "name": "Pool 2"},
56+
],
57+
}

0 commit comments

Comments
 (0)