test: replace prep(**_CTX) splat with a typed _prep helper
CI / Lint (ruff check) (push) Successful in 1m0s
CI / Format (ruff format) (push) Successful in 1m6s
CI / Type check (ty) (push) Successful in 1m23s
CI / Tests (push) Successful in 1m51s
CI / Bump version, build & publish wheel (push) Has been skipped

ty correctly flagged this as unsound: _CTX's inferred dict[str, int]
type doesn't rule out a "run_dir" key, which would silently bind to
prep's own run_dir: str | Path | None parameter instead of falling
through to **ctx_kwargs. Passing the context kwargs by name in a
small test helper removes the ambiguity.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-24 11:17:45 +02:00
parent 77b2e9e5f4
commit 1115301eb9
+15 -6
View File
@@ -51,7 +51,16 @@ def _write_inputs(tmp_path: Path) -> Path:
return yaml_path
_CTX = dict(n_energy_bins=2, n_marginal_bins=8, top_k_pdg=3, sample_rows=1000)
def _prep(rollout_yaml: Path, run_dir: str | Path | None = None) -> Path:
"""``prep`` with small test-sized context bins/sampling."""
return prep(
rollout_yaml,
run_dir,
n_energy_bins=2,
n_marginal_bins=8,
top_k_pdg=3,
sample_rows=1000,
)
def test_load_rollout_yaml_requires_paths(tmp_path: Path):
@@ -69,7 +78,7 @@ def test_derive_run_dir_next_to_rollout():
def test_prep_lays_out_run_dir(tmp_path: Path):
yaml_path = _write_inputs(tmp_path)
run_dir = prep(yaml_path, **_CTX)
run_dir = _prep(yaml_path)
assert run_dir == tmp_path / "analysis_abcd1234"
assert (run_dir / "shared.json").exists()
ctx = Context.load(run_dir / "shared.json")
@@ -81,7 +90,7 @@ def test_prep_lays_out_run_dir(tmp_path: Path):
def test_compute_one_from_run_dir(tmp_path: Path):
run_dir = prep(_write_inputs(tmp_path), **_CTX)
run_dir = _prep(_write_inputs(tmp_path))
out = compute_one("marginal_edep", run_dir)
assert out == run_dir / "reduced" / "marginal_edep.json"
reduced = Reduced.load(out)
@@ -90,7 +99,7 @@ def test_compute_one_from_run_dir(tmp_path: Path):
def test_compute_reduced_explicit_paths(tmp_path: Path):
run_dir = prep(_write_inputs(tmp_path), **_CTX)
run_dir = _prep(_write_inputs(tmp_path))
meta = RunMeta.load(run_dir / "run_meta.json")
out = compute_reduced(
"marginal_step_length",
@@ -103,7 +112,7 @@ def test_compute_reduced_explicit_paths(tmp_path: Path):
def test_write_submit_description(tmp_path: Path):
run_dir = prep(_write_inputs(tmp_path), **_CTX)
run_dir = _prep(_write_inputs(tmp_path))
cfg = SubmitConfig(run_dir=run_dir, accounting_group="cms", repo_dir=tmp_path)
txt = write_submit(cfg).read_text()
assert "universe = docker" in txt
@@ -119,7 +128,7 @@ def test_write_submit_description(tmp_path: Path):
def test_write_submit_remote_flag(tmp_path: Path):
run_dir = prep(_write_inputs(tmp_path), **_CTX)
run_dir = _prep(_write_inputs(tmp_path))
cfg = SubmitConfig(
run_dir=run_dir, accounting_group="cms", repo_dir=tmp_path, remote=True
)