Skip to content

Commit ded8f3e

Browse files
authored
Add unit tests (#12)
* tests: add tests * chore: add gh actions workflow for testing * chore: update pyright configuration to suppress untyped function decorator warnings * chore: update dependency sync in workflows to include test group
1 parent ad438db commit ded8f3e

27 files changed

Lines changed: 6742 additions & 8 deletions

.github/workflows/main.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ permissions:
1212

1313
jobs:
1414
lint:
15+
name: Lint
1516
uses: ./.github/workflows/lint.yaml
17+
1618
typecheck:
19+
name: Type Check
1720
needs: lint
18-
uses: ./.github/workflows/typecheck.yaml
21+
uses: ./.github/workflows/typecheck.yaml
22+
23+
tests:
24+
name: Tests
25+
needs: [lint, typecheck]
26+
uses: ./.github/workflows/tests.yaml

.github/workflows/tests.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests
2+
on:
3+
workflow_call:
4+
5+
jobs:
6+
test:
7+
name: Run tests
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ["3.12", "3.13"]
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
20+
- name: Install uv
21+
uses: astral-sh/setup-uv@v4
22+
23+
- name: Sync dependencies
24+
run: uv sync --group dev --group test
25+
26+
- name: Run tests
27+
run: uv run pytest --tb=short -v
28+
29+
- name: Test summary
30+
if: always()
31+
run: |
32+
echo "### Test Results" >> $GITHUB_STEP_SUMMARY
33+
echo "Python version: ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
34+
echo "Status: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
35+

.github/workflows/typecheck.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
- name: Install uv
1818
uses: astral-sh/setup-uv@v4
1919

20-
- name: Sync dev deps
21-
run: uv sync --group dev
20+
- name: Sync dependencies
21+
run: uv sync --group dev --group test
2222

2323
- name: Type check
2424
run: uv run pyright

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: lint-check lint-fix typecheck
1+
.PHONY: lint-check lint-fix typecheck test
22

33
lint-check:
44
uv run ruff format --check
@@ -11,3 +11,6 @@ lint-fix:
1111
typecheck:
1212
uv run pyright
1313
uv run mypy .
14+
15+
test:
16+
uv run pytest

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ dev = [
5959
"pyright==1.1.399",
6060
"mypy",
6161
]
62+
test = [
63+
"pytest>=7.0.0",
64+
"pytest-asyncio>=0.21.0",
65+
"pytest-cov>=4.0.0",
66+
]
6267

6368
[tool.ruff]
6469
line-length = 120
@@ -99,3 +104,11 @@ disallow_untyped_decorators = true
99104
exclude = [
100105
"^examples/",
101106
]
107+
108+
[[tool.mypy.overrides]]
109+
module = "tests.*"
110+
disallow_untyped_defs = false
111+
disallow_untyped_calls = false
112+
disallow_untyped_decorators = false
113+
disallow_incomplete_defs = false
114+
warn_unreachable = false

pyrightconfig.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["src"],
2+
"include": ["src", "tests"],
33
"exclude": [".venv", ".git", "examples/**", "**/__pycache__"],
44
"typeCheckingMode": "strict",
55
"pythonVersion": "3.12",
@@ -8,10 +8,17 @@
88
"root": "src/blindpay/resources",
99
"reportArgumentType": "error",
1010
"reportTypedDictNotRequiredAccess": "error",
11-
"reportMissingTypeArgument": "error",
11+
"reportMissingTypeArgument": "error"
1212
},
1313
{
14-
"root": "src/blindpay",
14+
"root": "src/blindpay"
15+
},
16+
{
17+
"root": "tests",
18+
"reportPrivateUsage": "none",
19+
"reportUnknownMemberType": "none",
20+
"reportUnknownArgumentType": "none",
21+
"reportUntypedFunctionDecorator": "none"
1522
}
1623
]
1724
}

pytest.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
python_classes = Test*
5+
python_functions = test_*
6+
asyncio_mode = auto
7+
addopts =
8+
-v
9+
--tb=short
10+
--strict-markers
11+
markers =
12+
asyncio: mark test as an asyncio test
13+

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
from pathlib import Path
3+
4+
src_path = Path(__file__).parent.parent / "src"
5+
sys.path.insert(0, str(src_path))

tests/resources/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)