Files
libretro/tests/test_region_held.py
T
Abdessamad Derraz fbbb941e38 refactor: one owner for the test scratch folder
Test modules passed dir= the repository's tmp/ or a hard-coded tmp/tests by hand, and seven modules kept their own _tempdir copy. Under run_tests.py the literal tmp/tests did not exist in a fresh clone (FileNotFoundError in test_core_probe and scratch_checkout), and dir=tmp/ wrote beside the per-module scratch folders. Every temporary directory now lands in the folder tests/__init__ sets, and scratch_dir() replaces the copies. The X socket binds by a relative name, since a scratch path can exceed the 108-byte AF_UNIX limit. The journeys keep the short tmp/ root: their word budgets count the printed card path.
2026-11-21 06:04:40 +01:00

109 lines
3.9 KiB
Python

"""A dump the frontend refuses does not hold a regional slot.
platform_region_groups counted a declaration as held as soon as a file
answered it, hash_mismatch included. On a md5 platform the builder leaves
that file out as unsafe, so a US file with the wrong md5 displaced a correct
Japanese one, and the system shipped no BIOS at all.
"""
from __future__ import annotations
import tests
import hashlib
import os
import shutil
import tempfile
import unittest
from pathlib import Path
from packs.extras import _ships
REPO_ROOT = Path(__file__).resolve().parents[1]
class ARefusedDumpHoldsNothing(unittest.TestCase):
def test_held_follows_the_frontend(self):
root = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, root, True)
previous = os.getcwd()
os.chdir(root)
self.addCleanup(os.chdir, previous)
Path("bios").mkdir()
data = b"US BIOS, ANOTHER REVISION"
Path("bios/us.bin").write_bytes(data)
sha1 = hashlib.sha1(data).hexdigest()
db = {
"files": {sha1: {"path": "bios/us.bin", "name": "us.bin", "size": len(data),
"md5": hashlib.md5(data).hexdigest(), "crc32": ""}},
"indexes": {"by_md5": {}, "by_name": {"us.bin": [sha1]}, "by_crc32": {},
"by_path_suffix": {}},
}
entry = {"name": "us.bin", "md5": "0" * 32}
def ships(config: dict, fe: dict) -> bool:
return _ships(config, fe, db, None, None, None)
self.assertFalse(ships({"verification_mode": "md5"}, entry))
self.assertTrue(ships({"verification_mode": "existence"}, entry))
self.assertTrue(ships({"verification_mode": "md5"}, {"name": "us.bin"}))
class ADataDirectoryCopyIsHeld(unittest.TestCase):
"""The region pass resolves with the builder's inputs.
Without the data directories, AmberELEC's config.ini (served from the
bluemsx tree) and dolphin-mmjr2's nwc24msg.cfg (served from the Dolphin
Sys tree) read as missing while both packs held them.
"""
@classmethod
def setUpClass(cls):
if not (REPO_ROOT / "data" / "bluemsx").is_dir() or not (
REPO_ROOT / "data" / "dolphin-sys"
).is_dir():
raise unittest.SkipTest("data/ not refreshed")
previous = os.getcwd()
os.chdir(REPO_ROOT)
try:
from model.registry import load_data_dir_registry
from model.database import load_database
from model.profiles import load_emulator_profiles
from model.platforms import load_platform_config
cls.db = load_database("database.json")
cls.registry = load_data_dir_registry("platforms")
cls.profiles = load_emulator_profiles("emulators")
cls.amberelec = load_platform_config("amberelec", "platforms")
finally:
os.chdir(previous)
def setUp(self):
previous = os.getcwd()
os.chdir(REPO_ROOT)
self.addCleanup(os.chdir, previous)
def test_platform_declaration_from_a_data_tree(self):
entry = next(
fe for fe in self.amberelec["systems"]["coleco-colecovision"]["files"]
if fe["destination"].endswith("Dina/config.ini")
)
self.assertTrue(
_ships(self.amberelec, entry, self.db, {}, self.registry, None)
)
def test_emulator_entry_from_a_data_tree(self):
from packs.extras import _emulator_ships
from resolve.validation import build_validation_index
profile = self.profiles["dolphin-mmjr2"]
entry = next(
fe for fe in profile["files"] if fe.get("name") == "nwc24msg.cfg"
)
index = build_validation_index({"dolphin-mmjr2": profile})
self.assertTrue(_emulator_ships(
entry, "dolphin-mmjr2", profile, self.db, index, {}, self.registry,
))
if __name__ == "__main__":
unittest.main()