From ceb8b752e6547ccecd9c7c797852d5a1c32f538d Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 21 Oct 2026 05:32:50 +0200 Subject: [PATCH] fix: count bundled gaps apart in each heading cross_reference.py --emulator abuse printed "Gaps: 3 missing" above three [BUNDLED] files, then "0 missing (need to be sourced)" in the total. The heading and the total now read one count: bundled files appear as "N bundled", never among the missing. --- scripts/cross_reference.py | 22 +++++++++++----------- tests/test_cross_reference_sources.py | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/scripts/cross_reference.py b/scripts/cross_reference.py index 25096341..d77c650d 100644 --- a/scripts/cross_reference.py +++ b/scripts/cross_reference.py @@ -809,11 +809,16 @@ def print_report( if gaps == 0 and not show_clean: continue - parts = [] - for key in ("bios", "data", "large_file", "missing"): - count = data.get(f"gap_{key}", 0) - if count: - parts.append(f"{count} {key}") + # Counted once, for the heading and the total alike: a file bundled + # with its emulator is not one to source. + emulator_bundled = sum( + 1 for g in data["gap_details"] + if g.get("bundled") and g.get("source") == "missing" + ) + counts = {key: data.get(f"gap_{key}", 0) for key in totals} + counts["missing"] -= emulator_bundled + counts["bundled"] = emulator_bundled + parts = [f"{count} {key}" for key, count in counts.items() if count] status = ", ".join(parts) if parts else "OK" systems = ", ".join(data["systems"]) @@ -842,13 +847,8 @@ def print_report( total_gaps += gaps for key in totals: - totals[key] += data.get(f"gap_{key}", 0) - emulator_bundled = sum( - 1 for g in data["gap_details"] - if g.get("bundled") and g.get("source") == "missing" - ) + totals[key] += counts[key] bundled += emulator_bundled - totals["missing"] -= emulator_bundled print(f"\n{'=' * 60}") print(f"Total: {total_gaps} undeclared files across {scope}") diff --git a/tests/test_cross_reference_sources.py b/tests/test_cross_reference_sources.py index 0f39afdd..40a6fa91 100644 --- a/tests/test_cross_reference_sources.py +++ b/tests/test_cross_reference_sources.py @@ -21,6 +21,7 @@ from cross_reference import ( # noqa: E402 _build_supplemental_index, cross_reference, entry_source, + print_report, ) @@ -54,6 +55,28 @@ class GapReportSources(unittest.TestCase): self.assertEqual(entry_source({"name": "ending.mid", "sha1": other}, index), "bios") self.assertEqual(entry_source({"name": "ending.mid", "md5": "1" * 32}, index), "bios") + def test_the_heading_and_the_total_count_bundled_files_alike(self): + """abuse printed "Gaps: 3 missing" above three [BUNDLED] files and + "0 missing (need to be sourced)" below.""" + import contextlib + import io + + report = {"abuse": { + "emulator": "Abuse", "systems": [], "gaps": 3, "total_files": 3, + "platform_covered": 0, "gap_missing": 3, + "gap_details": [ + {"name": f"f{i}", "required": True, "source": "missing", "bundled": True, + "note": ""} + for i in range(3) + ], + }} + with contextlib.redirect_stdout(io.StringIO()) as out: + print_report(report) + text = out.getvalue() + self.assertIn("Gaps: 3 bundled", text) + self.assertNotIn("3 missing", text) + self.assertIn("0 missing (need to be sourced)", text) + def test_a_directory_does_not_stand_for_a_file(self): with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: (Path(tmp) / "bios" / "cpcemu" / "ROM").mkdir(parents=True)