Files
libretro/tests/test_pack_grouping.py
T
Abdessamad Derraz c42c756b4a fix: group packs on everything that shapes them
group_identical_platforms fingerprinted each file by destination, sha1 and md5. Two platforms whose lists differed only in required, zipped_file, size or crc32, or in how the frontend checks a file, would have shared the representative's pack and verify result. The fingerprint now carries every field of every entry and the platform's verification_mode and hash_rule. No current platform is regrouped.
2026-10-20 02:14:14 +02:00

108 lines
4.4 KiB
Python

"""--one-per-slot and --region read one grouping of a pack.
The slot pass put each core extra under every system of its profile. PicoDrive
ranks its Mega CD BIOSes within sega-megacd. Spread across sega-megadrive,
sega-32x and the rest, they shared a tier with unranked files, the tier was
ruled undecidable, and the keep overrode the drop.
"""
from __future__ import annotations
import os
import sys
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
class SlotPassReadsTheRegionGrouping(unittest.TestCase):
def test_ranked_mega_cd_alternatives_are_decided(self):
if not (REPO_ROOT / "database.json").is_file():
self.skipTest("database.json not built")
import generate_pack as gp
from common import load_database, load_emulator_profiles, load_platform_config
previous = os.getcwd()
os.chdir(REPO_ROOT)
self.addCleanup(os.chdir, previous)
db = load_database("database.json")
profiles = load_emulator_profiles("emulators")
config = load_platform_config("retroarch", "platforms")
drops, _fallbacks, _undecided = gp._select_variants(
config, config["systems"], "emulators", db,
config.get("base_destination", ""), profiles, None, "full", None, True,
)
names = {os.path.basename(d) for d in drops}
for name in ("jp_mcd1_9111.bin", "eu_mcd1_9210.bin"):
self.assertIn(name, names)
def test_one_grouping_function(self):
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
self.assertNotIn("def _pack_member_groups", source)
class VariantGroupSpansSystems(unittest.TestCase):
def test_us_request_withdraws_the_other_mega_cd_lists(self):
"""PicoDrive files US under sega-segacd and EU/JP under sega-megacd.
find_bios (platform/libretro/libretro.c:1296) fills one slot from one
of three lists. Grouped by system, sega-megacd had no US member and was
kept whole as a fallback.
"""
if not (REPO_ROOT / "database.json").is_file():
self.skipTest("database.json not built")
import generate_pack as gp
import region as region_mod
from common import load_database, load_emulator_profiles, load_platform_config
previous = os.getcwd()
os.chdir(REPO_ROOT)
self.addCleanup(os.chdir, previous)
db = load_database("database.json")
profiles = load_emulator_profiles("emulators")
config = load_platform_config("retroarch", "platforms")
drops, _fallbacks, _undecided = gp._select_variants(
config, config["systems"], "emulators", db,
config.get("base_destination", ""), profiles, None, "full",
region_mod.parse_requested("us"), False,
)
names = {os.path.basename(d) for d in drops}
for name in ("jp_mcd1_9111.bin", "eu_mcd2_9306.bin"):
self.assertIn(name, names)
for name in ("us_scd2_9306.bin", "us_scd1_9210.bin"):
self.assertNotIn(name, names)
class AFrontendCheckSeparatesPacks(unittest.TestCase):
"""Two lists of the same files under different checks are two packs: a
hash platform drops a file whose hash disagrees, an existence one ships
it. The fingerprint read destination, sha1 and md5 only."""
def test_verification_mode_and_entry_fields_split_groups(self):
import tempfile
import yaml
import common
files = [{"name": "a.bin", "destination": "a.bin", "md5": "0" * 32}]
with tempfile.TemporaryDirectory() as tmp:
for name, mode, extra in (("one", "existence", {}), ("two", "md5", {}),
("three", "existence", {"required": False})):
entry = {**files[0], **extra}
Path(tmp, f"{name}.yml").write_text(yaml.dump({
"platform": name, "verification_mode": mode,
"systems": {"s": {"files": [entry]}},
}))
Path(tmp, "_registry.yml").write_text(yaml.dump({"platforms": {}}))
common._platform_config_cache.clear()
self.addCleanup(common._platform_config_cache.clear)
groups = common.group_identical_platforms(["one", "two", "three"], tmp)
self.assertEqual(sorted(g for g, _ in groups), [["one"], ["three"], ["two"]])
if __name__ == "__main__":
unittest.main()