mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
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.
119 lines
4.7 KiB
Python
119 lines
4.7 KiB
Python
"""A custom pack built from hashes follows the emulator it names, or refuses.
|
|
|
|
`--from-md5 --emulator` accepted any name: an unknown one produced a generic
|
|
pack in the layout of no emulator, rc 0, where `--emulator` alone refuses it.
|
|
With a known one and `--standalone`, a profile without pack_structure kept
|
|
the bare file names under a pack called Standalone.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tests
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def _pack(*options: str) -> tuple[subprocess.CompletedProcess, list[str]]:
|
|
with tempfile.TemporaryDirectory() as out:
|
|
proc = subprocess.run(
|
|
[sys.executable, "scripts/generate_pack.py", *options, "--offline",
|
|
"--output-dir", out],
|
|
cwd=REPO_ROOT, capture_output=True, text=True, timeout=600, check=False,
|
|
)
|
|
names = []
|
|
for archive in Path(out).glob("*.zip"):
|
|
with zipfile.ZipFile(archive) as zf:
|
|
names.extend(zf.namelist())
|
|
return proc, names
|
|
|
|
|
|
class TheEmulatorContextIsChecked(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 = json.loads(db_path.read_text(encoding="utf-8"))
|
|
|
|
def test_an_unknown_emulator_is_refused(self):
|
|
md5 = next(iter(self.db["files"].values()))["md5"]
|
|
proc, names = _pack("--from-md5", md5, "--emulator", "no_such_core")
|
|
self.assertNotEqual(proc.returncode, 0, proc.stdout)
|
|
self.assertIn("not found", proc.stderr)
|
|
self.assertEqual(names, [])
|
|
|
|
|
|
def test_the_standalone_layout_reaches_a_profile_without_structure(self):
|
|
"""BBKEmu has no pack_structure, and its A4980 8.BIN goes to
|
|
system/bbkemu/a4980/ standalone, the lowercase folder its code
|
|
matches exactly. The hash pack kept the bare name,
|
|
then, once laid out, sent it to the A4988 folder whose entry shares
|
|
the name."""
|
|
md5 = "ddfc001a6859d63ed46368ea7fe9f20c"
|
|
if not any(record.get("md5") == md5 for record in self.db["files"].values()):
|
|
self.skipTest("the A4980 8.BIN is not collected")
|
|
proc, names = _pack("--from-md5", md5, "--emulator", "bbkemu", "--standalone")
|
|
self.assertEqual(proc.returncode, 0, proc.stderr)
|
|
self.assertEqual(names, ["system/bbkemu/a4980/8.BIN"])
|
|
|
|
|
|
class SystemAndEmulatorPacksKeepTheirNames(unittest.TestCase):
|
|
"""`--system sega-triforce` and `--emulator triforce` both wrote
|
|
Triforce_BIOS_Pack.zip: whichever ran second replaced the other."""
|
|
|
|
def test_the_two_selections_write_two_files(self):
|
|
import hashlib
|
|
|
|
import yaml
|
|
|
|
from model.profiles import emulator_profiles_cache
|
|
import generate_db
|
|
from packs import emulatorpack
|
|
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
(root / "bios").mkdir()
|
|
(root / "emulators").mkdir()
|
|
out = root / "dist"
|
|
payload = b"triforce bios"
|
|
(root / "bios" / "segaboot.gcm").write_bytes(payload)
|
|
sha1 = hashlib.sha1(payload).hexdigest()
|
|
files = {sha1: {
|
|
"path": str(root / "bios" / "segaboot.gcm"), "name": "segaboot.gcm",
|
|
"size": len(payload), "sha1": sha1,
|
|
"md5": hashlib.md5(payload).hexdigest(),
|
|
"sha256": hashlib.sha256(payload).hexdigest(), "crc32": "0",
|
|
}}
|
|
db = {"files": files, "indexes": generate_db.build_indexes(files, {})}
|
|
(root / "emulators" / "triforce.yml").write_text(yaml.dump({
|
|
"emulator": "Triforce", "type": "libretro", "cores": ["triforce"],
|
|
"systems": ["sega-triforce"],
|
|
"files": [{"name": "segaboot.gcm", "required": True}],
|
|
}))
|
|
emulator_profiles_cache.clear()
|
|
try:
|
|
emulator_pack = emulatorpack.generate_emulator_pack(
|
|
["triforce"], str(root / "emulators"), db, str(root / "bios"),
|
|
str(out), offline=True,
|
|
)
|
|
system_pack = emulatorpack.generate_system_pack(
|
|
["sega-triforce"], str(root / "emulators"), db,
|
|
str(root / "bios"), str(out), offline=True,
|
|
)
|
|
finally:
|
|
emulator_profiles_cache.clear()
|
|
self.assertNotEqual(Path(emulator_pack).name, Path(system_pack).name)
|
|
self.assertTrue(Path(emulator_pack).exists())
|
|
self.assertTrue(Path(system_pack).exists())
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|