Files
libretro/tests/test_owner_resolution.py
T
Abdessamad Derraz 8da4757538 fix: an unclaimed pcem ROM fails the owner test
The test skipped when slots stopped claiming pcem's ide_xt.bin. The profile declares it and the collection holds three copies, so that skip could only hide a claiming defect. It now skips only when the file is not collected and fails when it is not claimed.
2026-10-20 02:24:45 +02:00

69 lines
2.6 KiB
Python

"""Every reader of a profile entry names its owner, as the builder does.
The resolver prefers the owning profile's copy when a name has several. The
builder passes `source_profile`. The site's consumer index, the slot claims
and the agnostic scan did not, and resolved 95 entries to other files: the
site credited aethersx2's game_controller_db.txt to armsx2 and left the copy
armsx2's pack ships without a reader, and MAME's neogeo.zip without MAME.
"""
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"))
import cross_reference # noqa: E402
import slots # noqa: E402
from common import ( # noqa: E402
build_zip_contents_index,
load_database,
load_emulator_profiles,
)
class ReadersNameTheOwner(unittest.TestCase):
@classmethod
def setUpClass(cls):
db_path = REPO_ROOT / "database.json"
if not db_path.exists():
raise unittest.SkipTest("database.json is not built")
cls.db = load_database(str(db_path))
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
cls.sha1_by_path = {r["path"]: s for s, r in cls.db["files"].items()}
def test_the_site_credits_the_copy_the_pack_ships(self):
consumers = cross_reference.FileConsumers(
self.db, build_zip_contents_index(self.db)
)
consumers.add_emulators(self.profiles)
for path, owner in (
("bios/Other/armsx2/game_controller_db.txt", "armsx2"),
("bios/Arcade/MAME/neogeo.zip", "mame"),
):
with self.subTest(path=path):
sha1 = self.sha1_by_path.get(path)
if sha1 is None:
self.skipTest(f"{path} is not collected")
self.assertIn(owner, consumers.emulators.get(sha1, set()))
def test_slot_claims_resolve_the_owners_tree(self):
claims = slots.profile_claims({"pcem": self.profiles["pcem"]}, self.db)
held = {
claim.destination.rsplit("/", 1)[-1]: claim.local_path for claim in claims
}
# pcem declares ide_xt.bin and the collection holds it: an unclaimed
# file here is a claiming defect, not missing data.
if not any(e.get("path", "").endswith("/ide_xt.bin") for e in self.db["files"].values()):
self.skipTest("ide_xt.bin is not collected")
local = held.get("ide_xt.bin")
self.assertIsNotNone(local, "pcem's ide_xt.bin is not claimed")
self.assertTrue(local.startswith("bios/Other/pcem/"), local)
if __name__ == "__main__":
unittest.main()