mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-17 17:03:27 -05:00
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.
This commit is contained in:
1 parent
dbcd26d3ab
commit
0ea8bb4e99
3 files changed
+38
-22
No files matched your search
+9
-2
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user