Skip to content

Commit 757ac30

Browse files
committed
feat: centralize logic, narrow exceptions, add tests and dev tooling (v0.13.0)
Address all 5 review priorities from project review: - Centralize duplicated logic: normalize_country(), _db_connection(), _build_result() helpers (#22) - Narrow exception handling: replace 9 bare except Exception blocks with specific types (#23) - Add Makefile, pre-commit hooks, ruff format CI check (#24) - Add 69 pytest tests covering postal_patterns, data_loader, and API endpoints with CI test job (#25) - Version bump to 0.13.0, requirements-dev.txt, .dockerignore updates Closes #22, closes #23, closes #24, closes #25
1 parent 1a19d52 commit 757ac30

19 files changed

Lines changed: 712 additions & 184 deletions

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ __pycache__
22
*.pyc
33
.git
44
.env
5+
tests/
6+
Makefile
7+
.pre-commit-config.yaml
8+
requirements-dev.txt
9+
docs/

.github/workflows/ci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
python-version: "3.12"
2121
- run: pip install ruff
2222
- run: ruff check app/ scripts/
23+
- run: ruff format --check app/ scripts/
2324

2425
import-check:
2526
runs-on: ubuntu-latest
@@ -44,6 +45,16 @@ jobs:
4445
- name: Static security analysis
4546
run: pip install bandit && bandit -r app/ -c pyproject.toml
4647

48+
test:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v6
52+
- uses: actions/setup-python@v6
53+
with:
54+
python-version: "3.12"
55+
- run: pip install -r requirements-dev.txt
56+
- run: pytest tests/ -v
57+
4758
docker:
4859
runs-on: ubuntu-latest
4960
steps:
@@ -58,7 +69,7 @@ jobs:
5869
5970
publish:
6071
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
61-
needs: [lint, import-check, security, docker]
72+
needs: [lint, import-check, test, security, docker]
6273
runs-on: ubuntu-latest
6374
steps:
6475
- uses: actions/checkout@v6

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ build/
77
.venv/
88
venv/
99
data/
10+
tests/*.csv

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.8.6
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
- id: ruff-format

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/).
66

7+
## [0.13.0] - 2026-02-23
8+
9+
### Added
10+
11+
- **Automated test suite** (#25): 69 pytest tests covering `postal_patterns.py` (preprocessing, tercet_map, extraction), `data_loader.py` (normalize functions, all 5 lookup tiers), and FastAPI endpoints (`/lookup`, `/pattern`, `/health`). CI now runs tests before publish.
12+
- **Makefile** (#24): standard targets for `lint`, `format`, `test`, `run`, `docker-build`, `docker-run`.
13+
- **Pre-commit hooks** (#24): ruff lint + format via `.pre-commit-config.yaml`.
14+
- **`requirements-dev.txt`** (#22): dev/test dependencies (ruff, bandit, pip-audit, pytest).
15+
- **`ruff format` CI check** (#24): enforces consistent code formatting in CI.
16+
17+
### Changed
18+
19+
- **Centralized duplicated logic** (#22): `normalize_country()` replaces duplicate GR→EL blocks, `_db_connection()` context manager replaces 6 manual SQLite connect/close patterns, `_build_result()` helper replaces repetitive result dict construction across all lookup tiers.
20+
- **Narrowed exception handling** (#23): 9 bare `except Exception` blocks in `data_loader.py` replaced with specific types (`sqlite3.Error`, `httpx.RequestError`, `OSError`, etc.). Silent catch in `import_estimates.py` now logs a message.
21+
- **Return type hints** added to `dispatch()` and `_rate_limit_handler()` in `main.py`.
22+
723
## [0.12.0] - 2026-02-23
824

925
### Fixed

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY: lint format test run docker-build docker-run
2+
3+
lint:
4+
ruff check app/ scripts/
5+
6+
format:
7+
ruff format app/ scripts/
8+
9+
test:
10+
pytest tests/ -v
11+
12+
run:
13+
uvicorn app.main:app --reload --port 8000
14+
15+
docker-build:
16+
docker build -t postalcode2nuts .
17+
18+
docker-run:
19+
docker run -p 8000:8000 postalcode2nuts

app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.12.0"
1+
__version__ = "0.13.0"

0 commit comments

Comments
 (0)