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"