Files
libretro/tests/test_system_ids.py
T
Abdessamad Derraz a0c560479b fix: join platform system names to profiles
The rom folder survey joined 463 folders to their default core's whole
profile, no system of it matching. SYSTEM_ALIASES, the one table
_norm_system_id reads, now folds ten more spellings of one machine:
apple2gs, astrocade, astrocde, creativision, gamepocketcomputer,
nintendo-super-game-boy, cps1, cps2, cps3 and pgm. The profiles that
used them take the canonical id (mame, groovymame, mamemess, mame0258,
mame0278, bsnes, mesen-s, mesence, jollycv, fbalpha2012 and its three
CPS cores, fbneo_cps12), as test_system_ids requires.

With bsnes and bsnes-hd now filing SGB1.sfc under one system, their
claims fold onto one report entry. _names_content read only the first
claim, hashless, and nSide's SGB1.sfc/ tree took the path before the
file. A hash on any folded claim now counts: every pack keeps the
destinations it had.

The site drops the eight display names the canonical ids replace and
names tvgames. README counts 533 systems instead of 541.
2026-11-03 15:23:30 +01:00

113 lines
4.2 KiB
Python

"""A machine has one system id in the profiles, and a file goes to its own.
picodrive filed the Mega CD as sega-segacd and fbneo the disk system as
nes-fds, where every other profile and every platform says sega-megacd and
nintendo-fds. On RomM, which keeps firmware per system folder, picodrive's
Mega CD BIOS went to gamegear/, the first of its systems, and fbneo's
channelf.zip and SNES DSP sets to colecovision/.
"""
from __future__ import annotations
import sys
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from common import SYSTEM_ALIASES, _norm_system_id, load_emulator_profiles # noqa: E402
from packextras import _names_content, _slug_for # noqa: E402
class ProfilesSpellEachMachineOnce(unittest.TestCase):
def test_no_profile_uses_an_alias_spelling(self):
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
found = sorted(
f"{name}: {sid}"
for name, profile in profiles.items()
for sid in [
*profile.get("systems", []),
*(f.get("system") for f in profile.get("files", []) if f.get("system")),
]
if str(sid).lower() in SYSTEM_ALIASES
)
self.assertEqual(sorted(set(found)), [])
class PlatformNamesReachTheProfileSystem(unittest.TestCase):
"""Folder and system names a platform gives a machine, joined to the
profile that runs it there. Each pair fell back to the whole profile in
a survey of the rom folders of 38 setups, the two spellings not meeting
once normalized."""
# (name a platform uses, profile running it there)
PAIRS = [
("apple-iigs", "mame"),
("apple2gs", "gsplus-legacy"),
("astrocde", "mame"),
("astrocade", "mame"),
("creativision", "mame"),
("gamepocketcomputer", "mame"),
("nintendo-sgb", "bsnes"),
("nintendo-sgb", "mesen-s"),
("capcom-cps1", "fbalpha2012_cps1"),
("capcom-cps2", "fbalpha2012_cps2"),
("capcom-cps3", "fbalpha2012_cps3"),
("capcom-cps1", "fbalpha2012"),
("igs-pgm", "fbalpha2012"),
]
def test_each_name_meets_a_system_of_its_profile(self):
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
unmet = [
f"{name} -> {emulator}"
for name, emulator in self.PAIRS
if _norm_system_id(name)
not in {_norm_system_id(str(s)) for s in profiles[emulator].get("systems", [])}
]
self.assertEqual(unmet, [])
def test_both_spellings_normalize_alike(self):
for alias, canonical in SYSTEM_ALIASES.items():
with self.subTest(alias=alias):
self.assertEqual(_norm_system_id(alias), _norm_system_id(canonical))
class AFoldedClaimKeepsItsProof(unittest.TestCase):
"""One spelling per machine folds bsnes-hd's SGB1.sfc onto bsnes's: the
entry still pins the bytes, so it is placed before nSide's SGB1.sfc/
tree and the file keeps its path."""
def test_a_hash_on_a_folded_claim_counts(self):
entry = {
"name": "SGB1.sfc", "md5": None, "sha1": None,
"other_claims": [{"name": "SGB1.sfc", "md5": "b15ddb15721c657d82c5bab6db982ee9"}],
}
self.assertTrue(_names_content(entry))
def test_names_alone_name_no_content(self):
self.assertFalse(_names_content({"name": "SGB1.sfc", "other_claims": [{"name": "SGB1.sfc"}]}))
class AFileGoesToItsOwnSystemFolder(unittest.TestCase):
PROFILES = {"picodrive": {"systems": ["sega-game-gear", "sega-megacd"]}}
SYSTEMS = {"sega-game-gear", "sega-mega-cd"}
NORM = {"gamegear": "sega-game-gear", "megacd": "sega-mega-cd"}
SLUGS = {"sega-game-gear": "gamegear", "sega-mega-cd": "segacd"}
def slug(self, entry):
return _slug_for(entry, self.PROFILES, self.SYSTEMS, self.NORM, self.SLUGS)
def test_the_entry_system_decides(self):
self.assertEqual(
self.slug({"profile": "picodrive", "system": "sega-megacd"}), "segacd"
)
def test_without_one_the_emulator_systems_decide(self):
self.assertEqual(self.slug({"profile": "picodrive"}), "gamegear")
if __name__ == "__main__":
unittest.main()