Scaffold bggpipe: typer CLI, config loading, title normalization
uv project with typer/httpx/rapidfuzz, ruff and pytest wired into pyproject. Six stub subcommands matching the pipeline stages, config.toml plus BGG_USERNAME env override, accent/ampersand/article-safe title normalization with tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_addoption(parser: pytest.Parser) -> None:
|
||||
parser.addoption(
|
||||
"--run-live",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Run tests marked 'live' (hit the real BGG API, read-only)",
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(
|
||||
config: pytest.Config, items: list[pytest.Item]
|
||||
) -> None:
|
||||
if config.getoption("--run-live"):
|
||||
return
|
||||
skip_live = pytest.mark.skip(reason="live BGG test; pass --run-live to enable")
|
||||
for item in items:
|
||||
if "live" in item.keywords:
|
||||
item.add_marker(skip_live)
|
||||
@@ -0,0 +1,31 @@
|
||||
from pathlib import Path
|
||||
|
||||
from bggpipe.config import Config, load_config
|
||||
|
||||
|
||||
def test_defaults_when_no_file(tmp_path, monkeypatch):
|
||||
monkeypatch.delenv("BGG_USERNAME", raising=False)
|
||||
cfg = load_config(tmp_path / "missing.toml")
|
||||
assert cfg == Config()
|
||||
assert cfg.cache_dir == Path("data/bgg_cache")
|
||||
|
||||
|
||||
def test_reads_toml(tmp_path, monkeypatch):
|
||||
monkeypatch.delenv("BGG_USERNAME", raising=False)
|
||||
p = tmp_path / "config.toml"
|
||||
p.write_text(
|
||||
'bgg_username = "someone"\ndata_dir = "elsewhere"\nrate_limit_seconds = 3\n'
|
||||
)
|
||||
cfg = load_config(p)
|
||||
assert cfg.bgg_username == "someone"
|
||||
assert cfg.data_dir == Path("elsewhere")
|
||||
assert cfg.rate_limit_seconds == 3.0
|
||||
assert cfg.matches_path == Path("elsewhere/matches.csv")
|
||||
|
||||
|
||||
def test_env_overrides_toml(tmp_path, monkeypatch):
|
||||
p = tmp_path / "config.toml"
|
||||
p.write_text('bgg_username = "from_toml"\n')
|
||||
monkeypatch.setenv("BGG_USERNAME", "from_env")
|
||||
cfg = load_config(p)
|
||||
assert cfg.bgg_username == "from_env"
|
||||
@@ -0,0 +1,25 @@
|
||||
from bggpipe.normalize import normalize_title
|
||||
|
||||
|
||||
def test_casefold_and_punctuation():
|
||||
assert normalize_title("Wingspan: European Expansion") == (
|
||||
"wingspan european expansion"
|
||||
)
|
||||
|
||||
|
||||
def test_accents_stripped():
|
||||
assert normalize_title("Café International") == "cafe international"
|
||||
|
||||
|
||||
def test_ampersand_becomes_and():
|
||||
assert normalize_title("Axis & Allies") == "axis and allies"
|
||||
assert normalize_title("Axis and Allies") == "axis and allies"
|
||||
|
||||
|
||||
def test_articles_dropped():
|
||||
assert normalize_title("The Castles of Burgundy") == "castles of burgundy"
|
||||
assert normalize_title("A Feast for Odin") == "feast for odin"
|
||||
|
||||
|
||||
def test_whitespace_collapsed():
|
||||
assert normalize_title(" Ticket to Ride ") == "ticket to ride"
|
||||
Reference in New Issue
Block a user