Files
libretro/tests/test_required_only_twins.py
T
Abdessamad Derraz 057fd2d0f6 fix: isolate every test module however it runs
tests/__init__.py keeps a run offline, its scratch under tmp/ and its
installer cache its own, but only discover -s tests -t . imported it.
discover tests ran with RETROBIOS_OFFLINE unset, scratch on the /tmp
tmpfs and the user's real installer cache, the setting in which e2e
fixtures had written into the shared .cache/large. Every test module now
imports the package first, and a test fails on a module that does not.
test_verify_listing.py took its line with the previous commit.
2026-11-06 15:14:05 +01:00

107 lines
4.0 KiB
Python

"""A required declaration is never silenced by its optional twin.
RetroDECK declares the four Atari 5200 ROMs optional under atari-400-800 and
required under atari-5200, same md5. The preferred declaration for a shared
destination was chosen over the full set, then applied to a loop that had
already dropped the optional entries: under --required-only the preferred
(optional) entry was skipped for being optional and the required one for not
being preferred, and the destination left the pack, the status counts and
the manifest without a trace.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import hashlib
import sys
import tempfile
import unittest
import zipfile
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
import common # noqa: E402
import generate_db # noqa: E402
import generate_pack as builder # noqa: E402
class RequiredTwins(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.root = Path(self._tmp.name)
self.bios = self.root / "bios" / "Atari"
self.platforms = self.root / "platforms"
self.emulators = self.root / "emulators"
for directory in (self.bios, self.platforms, self.emulators):
directory.mkdir(parents=True)
payload = b"atari os"
(self.bios / "ATARIOSB.ROM").write_bytes(payload)
md5 = hashlib.md5(payload).hexdigest()
sha1 = hashlib.sha1(payload).hexdigest()
files = {
sha1: {
"path": str(self.bios / "ATARIOSB.ROM"), "name": "ATARIOSB.ROM",
"size": len(payload), "sha1": sha1, "md5": md5,
"sha256": hashlib.sha256(payload).hexdigest(), "crc32": "00000008",
}
}
self.db = {"files": files, "indexes": generate_db.build_indexes(files, {})}
platform = {
"platform": "Twins",
"version": "2.1",
"verification_mode": "md5",
"base_destination": "bios",
"cores": [],
"systems": {
# Sorted first: the optional declaration is the preferred one.
"atari-400-800": {"files": [
{"name": "ATARIOSB.ROM", "destination": "ATARIOSB.ROM",
"md5": md5, "required": False},
]},
"atari-5200": {"files": [
{"name": "ATARIOSB.ROM", "destination": "ATARIOSB.ROM",
"md5": md5, "required": True},
]},
},
}
(self.platforms / "twins.yml").write_text(yaml.dump(platform))
(self.platforms / "_registry.yml").write_text(
yaml.dump({"platforms": {"twins": {"config": "twins.yml"}}})
)
common._platform_config_cache.clear()
common._emulator_profiles_cache.clear()
def tearDown(self):
common._platform_config_cache.clear()
self._tmp.cleanup()
def test_the_required_only_pack_carries_the_required_file(self):
out = self.root / "dist"
out.mkdir()
zip_path = builder.generate_pack(
"twins", str(self.platforms), self.db, str(self.root / "bios"), str(out),
emulators_dir=str(self.emulators), emu_profiles={},
required_only=True, offline=True,
)
with zipfile.ZipFile(zip_path) as archive:
self.assertIn("ATARIOSB.ROM", archive.namelist())
def test_the_required_only_manifest_lists_it(self):
manifest = builder.generate_manifest(
"twins", str(self.platforms), self.db, str(self.root / "bios"),
str(self.platforms / "_registry.yml"),
emulators_dir=str(self.emulators), emu_profiles={},
required_only=True, offline=True,
)
listed = {entry["dest"] for entry in manifest["files"]}
self.assertIn("ATARIOSB.ROM", listed)
if __name__ == "__main__":
unittest.main()