From 0ea8bb4e9934066b723c1ce355c5f91af36b6316 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 17 Oct 2026 13:21:14 +0200 Subject: [PATCH] fix: list a short set of names in full The declared-names test now builds its own platform: Batocera files the BK under elektronika-bk since its slug map was completed, so the real data no longer shows two ids for one name. --- scripts/common.py | 11 +++++++-- tests/test_declared_names.py | 44 +++++++++++++++++++--------------- tests/test_system_selection.py | 5 +++- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index 2234d7b5..5e832784 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -350,6 +350,10 @@ def list_registered_platforms( return platforms +# A list this short is printed whole rather than pointed at. +SHORT_LIST = 12 + + def suggest_names(typed: list[str], available: list[str], listing_flag: str) -> str: """The closest known names to what was typed, and how to see them all. @@ -360,8 +364,11 @@ def suggest_names(typed: list[str], available: list[str], listing_flag: str) -> close = sorted({m for name in typed for m in difflib.get_close_matches(name, available, n=3, cutoff=0.6)}) - hint = f"Did you mean: {', '.join(close)}? " if close else "" - return f"{hint}{listing_flag} lists all {len(available)}." + if close: + return f"Did you mean: {', '.join(close)}? {listing_flag} lists all {len(available)}." + if len(available) <= SHORT_LIST: + return f"Known: {', '.join(available)}." + return f"{listing_flag} lists all {len(available)}." def require_platform(name: str, platforms_dir: str = "platforms") -> None: diff --git a/tests/test_declared_names.py b/tests/test_declared_names.py index c6bed17f..eb3a5607 100644 --- a/tests/test_declared_names.py +++ b/tests/test_declared_names.py @@ -15,9 +15,7 @@ from pathlib import Path REPO_ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(REPO_ROOT / "scripts")) -from common import load_database, load_emulator_profiles # noqa: E402 from cross_reference import ( # noqa: E402 - _build_supplemental_index, cross_reference, declared_names, load_platform_files, @@ -26,24 +24,32 @@ from cross_reference import ( # noqa: E402 class FlatDeclaredSet(unittest.TestCase): def test_a_name_declared_under_another_system_id_is_not_a_gap(self): - if not (REPO_ROOT / "database.json").is_file(): - self.skipTest("no database.json") - db = load_database(str(REPO_ROOT / "database.json")) - platforms = str(REPO_ROOT / "platforms") - profiles = {k: v for k, v in load_emulator_profiles(str(REPO_ROOT / "emulators")).items() if k == "bk"} - if not profiles: - self.skipTest("no bk profile") - declared, data_dirs = load_platform_files(platforms, ["batocera"]) - names = _build_supplemental_index() - per_system = cross_reference(profiles, declared, db, data_dirs, names) - flat = cross_reference( - profiles, declared, db, data_dirs, names, - all_declared=declared_names(platforms, ["batocera"], db), - ) - gaps = {g["name"] for g in flat["bk"]["gap_details"]} - self.assertNotIn("MONIT10.ROM", gaps) - self.assertLess(flat["bk"]["gaps"], per_system["bk"]["gaps"]) + """A platform files the Super Game Boy BIOS under nintendo-sgb, the + profile under nintendo-super-game-boy: the ids never meet.""" + import tempfile # noqa: PLC0415 + with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + platforms = Path(tmp) + (platforms / "fx.yml").write_text( + "platform: Fx\nverification_mode: existence\nsystems:\n" + " nintendo-sgb:\n files:\n - name: sgb.boot.rom\n" + " destination: sgb.boot.rom\n" + ) + profiles = {"sgbcore": { + "emulator": "SGB", "type": "libretro", "systems": ["nintendo-super-game-boy"], + "files": [{"name": "sgb.boot.rom", "system": "nintendo-super-game-boy"}], + }} + db = {"files": {}, "indexes": {"by_name": {}, "by_md5": {}, "by_crc32": {}, + "by_path_suffix": {}}} + declared, data_dirs = load_platform_files(str(platforms), ["fx"]) + per_system = cross_reference(profiles, declared, db, data_dirs, set()) + flat = cross_reference( + profiles, declared, db, data_dirs, set(), + all_declared=declared_names(str(platforms), ["fx"], db), + ) + self.assertEqual([g["name"] for g in per_system["sgbcore"]["gap_details"]], + ["sgb.boot.rom"]) + self.assertEqual(flat["sgbcore"]["gap_details"], []) class AnAliasIsADeclaration(unittest.TestCase): diff --git a/tests/test_system_selection.py b/tests/test_system_selection.py index e9adfc9a..6a7fa0df 100644 --- a/tests/test_system_selection.py +++ b/tests/test_system_selection.py @@ -173,7 +173,10 @@ class ATypoGetsTheNearestNames(unittest.TestCase): ["3do", "apple-ii", "sony-playstation"], "--list-systems") self.assertEqual(hint, "Did you mean: sony-playstation? --list-systems lists all 3.") self.assertEqual(common.suggest_names(["zzz"], ["3do"], "--list-systems"), - "--list-systems lists all 1.") + "Known: 3do.") + many = [f"system-{i}" for i in range(40)] + self.assertEqual(common.suggest_names(["zzz"], many, "--list-systems"), + "--list-systems lists all 40.") if __name__ == "__main__": unittest.main()