Add coverage for router-center seeding, geometry batch reader, material topN cache, and setup-cache corruption paths
CI / Lint (ruff check) (push) Successful in 28s
CI / Format (ruff format) (push) Successful in 29s
CI / Sync project version with tag (push) Has been skipped
CI / Lint (ruff check) (pull_request) Successful in 34s
CI / Type check (ty) (push) Successful in 35s
CI / Format (ruff format) (pull_request) Successful in 33s
CI / Sync project version with tag (pull_request) Has been skipped
CI / Type check (ty) (pull_request) Successful in 34s
CI / Tests (pull_request) Failing after 3m23s
CI / Tests (push) Failing after 3m32s
CI / Lint (ruff check) (push) Successful in 28s
CI / Format (ruff format) (push) Successful in 29s
CI / Sync project version with tag (push) Has been skipped
CI / Lint (ruff check) (pull_request) Successful in 34s
CI / Type check (ty) (push) Successful in 35s
CI / Format (ruff format) (pull_request) Successful in 33s
CI / Sync project version with tag (pull_request) Has been skipped
CI / Type check (ty) (pull_request) Successful in 34s
CI / Tests (pull_request) Failing after 3m23s
CI / Tests (push) Failing after 3m32s
Closes the highest-value coverage gaps found via pytest-cov: pipeline.py's EnergyRouter quantile-seeding (the roadmap's flagged fix for the failed MoE rollout benchmark) had zero coverage, geometry.py's real parquet-batch reader was always mocked, the material top-N-map cache-hit branch was untested (only pdg's was), and setup_cache.py was missing malformed-cache-body and unknown-axis error paths. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,6 +128,11 @@ def test_save_load_round_trip_topn_maps(tmp_path):
|
||||
assert mat_m.class_map == {"G4_AIR": 0, "PbWO4": 1}
|
||||
|
||||
|
||||
def test_topn_key_unknown_axis_raises():
|
||||
with pytest.raises(ValueError, match="unknown top-N map axis"):
|
||||
setup_cache.topn_key("process", 4)
|
||||
|
||||
|
||||
def test_load_missing_sidecar_returns_none(tmp_path):
|
||||
data = _touch_parquet(tmp_path / "shard.parquet")
|
||||
assert setup_cache.load(data, [data]) is None
|
||||
@@ -176,6 +181,25 @@ def test_load_invalidates_on_file_content_change(tmp_path):
|
||||
assert setup_cache.load(data, files) is None
|
||||
|
||||
|
||||
def test_load_returns_none_on_malformed_cache_body(tmp_path):
|
||||
"""format_version/dims/fingerprint all check out, but the cache body
|
||||
itself doesn't match SetupCache.from_json's expected shape (e.g. hand-
|
||||
edited or written by a version that changed a nested key) — a clean
|
||||
miss, not a crash."""
|
||||
data = _touch_parquet(tmp_path / "shard.parquet")
|
||||
files = [data]
|
||||
setup_cache.save(data, files, SetupCache.empty(files))
|
||||
|
||||
path = setup_cache.sidecar_path(data)
|
||||
raw = json.loads(path.read_text())
|
||||
raw["vocab"] = {"pdg_map": {"11": 0}} # missing required "mat_map" key
|
||||
path.write_text(json.dumps(raw))
|
||||
|
||||
echoed = []
|
||||
assert setup_cache.load(data, files, echo=echoed.append) is None
|
||||
assert any("malformed" in m for m in echoed)
|
||||
|
||||
|
||||
def test_load_soft_warns_on_git_hash_mismatch_but_still_hits(tmp_path, capsys):
|
||||
data = _touch_parquet(tmp_path / "shard.parquet")
|
||||
files = [data]
|
||||
@@ -352,3 +376,11 @@ def test_compute_event_index_from_files_single_file_unaffected(tmp_path):
|
||||
|
||||
np.testing.assert_array_equal(unique_ids, [5, 7])
|
||||
np.testing.assert_array_equal(counts, [2, 1])
|
||||
|
||||
|
||||
def test_compute_event_index_from_files_empty_file_list():
|
||||
unique_ids, counts = setup_cache.compute_event_index_from_files([])
|
||||
assert unique_ids.size == 0
|
||||
assert counts.size == 0
|
||||
assert unique_ids.dtype == np.int64
|
||||
assert counts.dtype == np.int64
|
||||
|
||||
Reference in New Issue
Block a user