mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-15 14:33:47 -06:00
chore: merge origin/main
This commit is contained in:
commit
2dc427d5d0
106 files changed
+5458
-13655
No files matched your search
@@ -459,7 +459,7 @@ systems:
|
||||
frames: 3600
|
||||
frame_hash_every: 10
|
||||
|
||||
snk-neogeo-pocket:
|
||||
snk-ngp:
|
||||
romfetch: ngp
|
||||
content:
|
||||
- name: "King of Fighters R-1 - Pocket Fighting Series (Japan, Europe) (En,Ja)"
|
||||
|
||||
@@ -252,6 +252,55 @@ class CommittedData(unittest.TestCase):
|
||||
unresolved += 1
|
||||
self.assertGreaterEqual((total - unresolved) / total, gi.FLOORS["folders_resolved_share"])
|
||||
|
||||
def test_a_folder_holds_a_machine_its_core_runs(self) -> None:
|
||||
"""muOS names its GBA folder gameboyadvance first: it resolved to
|
||||
ares's game-boy-advance, which mgba does not list, and an
|
||||
unrecognised GBA game got none of the nintendo-gba files. A CD
|
||||
folder run by mednafen_pce_fast, which lists nec-pc-engine, got no
|
||||
System Card."""
|
||||
from common import load_emulator_profiles
|
||||
from romfolders import ProfileResolver, folder_names
|
||||
|
||||
setups = load_setups(ROOT / "platforms" / "romfolders")
|
||||
if not setups:
|
||||
self.skipTest("no setup scraped")
|
||||
resolver = SystemResolver.from_repo(str(ROOT / "emulators"), str(ROOT / "platforms"))
|
||||
cores = ProfileResolver.from_repo(str(ROOT / "emulators"))
|
||||
loaded = load_emulator_profiles(str(ROOT / "emulators"))
|
||||
profiles = gi.Profiles(loaded, resolver)
|
||||
arcade = gi._arcade_profiles(ROOT / "games" / "arcade")
|
||||
apart = []
|
||||
for key, doc in sorted(setups.items()):
|
||||
for row in doc["folders"]:
|
||||
profile = cores.resolve(row.get("core"))
|
||||
if not profile or profile in arcade:
|
||||
continue
|
||||
runs = {sid for s in loaded[profile].get("systems") or []
|
||||
for sid in resolver.equivalents(str(s))}
|
||||
systems = gi.resolve_folder(row, doc["platform"], profile, resolver,
|
||||
profiles, arcade).systems
|
||||
if runs and systems and not runs & set(systems):
|
||||
apart.append(f"{key}/{row['folder']} {systems} by {profile}")
|
||||
self.assertEqual(apart, [])
|
||||
muos = next(row for row in setups["muos"]["folders"]
|
||||
if row["folder"] == "nintendogameboyadvance")
|
||||
self.assertIn("gameboyadvance", folder_names(muos))
|
||||
self.assertEqual(
|
||||
gi.resolve_folder(muos, "retroarch", "mgba", resolver, profiles, arcade).systems,
|
||||
["nintendo-gba"])
|
||||
|
||||
def test_an_unrecognised_gba_game_on_muos_gets_the_gba_bios(self) -> None:
|
||||
index = ROOT / "install" / "games"
|
||||
if not (index / "index.json").exists():
|
||||
self.skipTest("install/games/ not generated")
|
||||
setup = json.loads((index / "setups" / "muos.json").read_text())
|
||||
row = next(r for r in setup["folders"] if r["folder"] == "nintendogameboyadvance")
|
||||
self.assertEqual(row["systems"], ["nintendo-gba"])
|
||||
table = json.loads((index / "fallback" / "retroarch.json").read_text())
|
||||
dests = {table["files"][i][0] for key in row["fallback"]
|
||||
for i in table["sets"][key]["files"]}
|
||||
self.assertIn("gba_bios.bin", dests)
|
||||
|
||||
def test_a_folder_of_a_several_machine_core_holds_its_machines(self) -> None:
|
||||
from common import load_emulator_profiles
|
||||
|
||||
|
||||
+25
-12
@@ -4410,9 +4410,16 @@ class DataDirectoriesAreInstalled(unittest.TestCase):
|
||||
manifest = json.loads((REPO_ROOT / "install" / "retroarch.json").read_text())
|
||||
dirs = manifest.get("data_directories") or []
|
||||
files = sum(len(d["files"]) for d in dirs)
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
import generate_pack
|
||||
|
||||
written = generate_pack.PACK_DOCUMENTS + generate_pack.pack_markers(
|
||||
"retroarch", None, str(REPO_ROOT / "platforms"))
|
||||
self.assertEqual(written, ("README.txt", "manifest.json", ".nomedia"))
|
||||
self.assertEqual(
|
||||
manifest["pack_files"] - manifest["total_files"] - files,
|
||||
2, "the pack's two documents are the only files the installer lacks",
|
||||
manifest["pack_files"] - manifest["total_files"] - files, len(written),
|
||||
"the pack's two documents and its .nomedia are the only files the "
|
||||
"installer lacks",
|
||||
)
|
||||
|
||||
|
||||
@@ -4896,9 +4903,13 @@ class TheBoardSystemsAreNamedFromTheCode(unittest.TestCase):
|
||||
|
||||
|
||||
class TheInstallerFitsTheOneLiners(unittest.TestCase):
|
||||
"""install.sh and install.ps1 refuse an installer over 2 MiB, and
|
||||
install.py grew from 596 KB to 1.1 MB in twelve days with nothing
|
||||
holding it under that: past it, every one-line install would stop."""
|
||||
"""install.sh and install.ps1 refuse an installer over their cap, 8 MiB:
|
||||
the SHA-256 pin refuses any changed byte, and the cap only stops a page
|
||||
served in its place. install.py grew from 596 KB to 1.1 MB in twelve
|
||||
days: past REVIEW_BYTES its growth is looked at before it goes on."""
|
||||
|
||||
# The size past which install.py's growth is reviewed, well below the cap.
|
||||
REVIEW_BYTES = 3 * 1024 ** 2
|
||||
|
||||
def _caps(self) -> dict[str, int]:
|
||||
import re
|
||||
@@ -4910,14 +4921,16 @@ class TheInstallerFitsTheOneLiners(unittest.TestCase):
|
||||
return {"install.sh": int(re.search(r"^MAX_INSTALLER_BYTES=(\d+)$", shell, re.M)[1]),
|
||||
"install.ps1": int(number) * units[unit or ""]}
|
||||
|
||||
def test_a_quarter_of_each_cap_stays_free(self):
|
||||
def test_both_one_liners_accept_the_same_size(self):
|
||||
self.assertEqual(set(self._caps().values()), {8 * 1024 ** 2})
|
||||
|
||||
def test_install_py_stays_below_the_review_size(self):
|
||||
size = (REPO_ROOT / "install.py").stat().st_size
|
||||
for script, cap in self._caps().items():
|
||||
with self.subTest(script=script):
|
||||
self.assertLessEqual(
|
||||
size, cap * 3 // 4,
|
||||
f"install.py is {size} bytes, past three quarters of the {cap} {script} "
|
||||
"accepts: shrink it or raise the cap in both one-liners")
|
||||
self.assertLess(self.REVIEW_BYTES, min(self._caps().values()))
|
||||
self.assertLess(
|
||||
size, self.REVIEW_BYTES,
|
||||
f"install.py is {size} bytes, past the {self.REVIEW_BYTES} that call for a "
|
||||
"look at its growth: shrink it, or raise REVIEW_BYTES once reviewed")
|
||||
|
||||
def test_the_refusal_names_a_cause_and_a_way_out(self):
|
||||
for script in ("install.sh", "install.ps1"):
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
"""What an install does for the device and file system it lands on."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(REPO_ROOT))
|
||||
sys.path.insert(0, str(REPO_ROOT / "tests"))
|
||||
|
||||
import install # noqa: E402
|
||||
from test_install_selection import FakeRepository # noqa: E402
|
||||
|
||||
|
||||
class AndroidMediaScanner(unittest.TestCase):
|
||||
"""Without a .nomedia the BIOS folder's samples, overlays and videos
|
||||
showed in the phone's gallery and music apps."""
|
||||
|
||||
def setUp(self):
|
||||
self.repo = FakeRepository().__enter__()
|
||||
self.addCleanup(self.repo.__exit__)
|
||||
|
||||
def _run(self, os_name: str, *options: str):
|
||||
proc = subprocess.run(self.repo.command("--yes", "--no-input", *options),
|
||||
env={**self.repo.env(), "RETROBIOS_OS": os_name},
|
||||
capture_output=True, text=True, timeout=60,
|
||||
stdin=subprocess.DEVNULL)
|
||||
return self.repo, proc
|
||||
|
||||
def test_an_android_install_writes_one(self):
|
||||
repo, proc = self._run("android")
|
||||
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||
marker = repo.dest / ".nomedia"
|
||||
self.assertTrue(marker.is_file())
|
||||
self.assertEqual(marker.stat().st_size, 0)
|
||||
self.assertIn("Added .nomedia", proc.stdout)
|
||||
|
||||
def test_a_second_run_leaves_it_and_says_nothing(self):
|
||||
self._run("android")
|
||||
_, proc = self._run("android")
|
||||
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||
self.assertNotIn("Added .nomedia", proc.stdout)
|
||||
# The marker is not a file of the list: the check finds all in place.
|
||||
_, check = self._run("android", "--check")
|
||||
self.assertEqual(check.returncode, 0, check.stdout + check.stderr)
|
||||
|
||||
def test_a_check_and_a_dry_run_write_nothing(self):
|
||||
for options in (("--check",), ("--dry-run",)):
|
||||
with self.subTest(options=options):
|
||||
self._run("android", *options)
|
||||
self.assertFalse((self.repo.dest / ".nomedia").exists())
|
||||
|
||||
def test_other_systems_get_none(self):
|
||||
repo, proc = self._run("linux")
|
||||
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||
self.assertFalse((repo.dest / ".nomedia").exists())
|
||||
|
||||
|
||||
class NamesAFatCardCannotHold(unittest.TestCase):
|
||||
"""RetroDECK names three files with a colon (zxs:48.rom): on an exFAT
|
||||
card each write failed with EINVAL, on every run."""
|
||||
|
||||
def test_the_probe_reads_einval_as_a_refusal(self):
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
|
||||
refused = OSError(errno.EINVAL, "Invalid argument")
|
||||
closed = PermissionError(errno.EACCES, "Permission denied")
|
||||
with mock.patch.object(install.os, "name", "posix"):
|
||||
self.assertTrue(install.holds_fat_refused_names(Path(tmp) / "a" / "b"))
|
||||
with mock.patch.object(install.tempfile, "mkstemp", side_effect=refused):
|
||||
self.assertFalse(install.holds_fat_refused_names(Path(tmp)))
|
||||
with mock.patch.object(install.tempfile, "mkstemp", side_effect=closed):
|
||||
self.assertTrue(install.holds_fat_refused_names(Path(tmp)))
|
||||
self.assertEqual(os.listdir(tmp), [])
|
||||
|
||||
def test_windows_refuses_them_on_any_drive(self):
|
||||
with mock.patch.object(install.os, "name", "nt"):
|
||||
self.assertFalse(install.holds_fat_refused_names(Path(".")))
|
||||
|
||||
def _install(self, holds: bool) -> tuple[str, list[str]]:
|
||||
root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
|
||||
self.addCleanup(shutil.rmtree, root, True)
|
||||
old, dest = root / "old", root / "dest"
|
||||
old.mkdir()
|
||||
files = []
|
||||
for name, payload in (("zxs:48.rom", b"zx 48"), ("gba_bios.bin", b"gba")):
|
||||
(old / name.replace(":", "_")).write_bytes(payload)
|
||||
files.append({"dest": name, "sha1": hashlib.sha1(payload).hexdigest(),
|
||||
"sha256": hashlib.sha256(payload).hexdigest(),
|
||||
"size": len(payload), "repo_path": f"bios/{name}"})
|
||||
listed = root / "list.json"
|
||||
listed.write_text(json.dumps({"manifest_version": 2, "platform": "retrodeck",
|
||||
"files": files}))
|
||||
out = io.StringIO()
|
||||
argv = ["install.py", "--platform", "retrodeck", "--dest", str(dest),
|
||||
"--manifest", str(listed), "--from", str(old), "--no-input"]
|
||||
with mock.patch.object(install, "holds_fat_refused_names", return_value=holds), \
|
||||
mock.patch.object(install, "detect_os", return_value="linux"), \
|
||||
mock.patch("sys.argv", argv), contextlib.redirect_stdout(out), \
|
||||
contextlib.redirect_stderr(io.StringIO()):
|
||||
try:
|
||||
install.main()
|
||||
except SystemExit as exc:
|
||||
self.assertIn(exc.code, (0, None), out.getvalue())
|
||||
self.addCleanup(install.LOCAL.reset)
|
||||
return (" ".join(out.getvalue().split()),
|
||||
sorted(p.name for p in dest.iterdir()) if dest.is_dir() else [])
|
||||
|
||||
def test_the_names_are_left_out_and_said(self):
|
||||
said, installed = self._install(holds=False)
|
||||
self.assertEqual(installed, ["gba_bios.bin"])
|
||||
self.assertIn("1 file left out: the file system of", said)
|
||||
self.assertIn('cannot hold a name with any of < > : " | ? * (zxs:48.rom)', said)
|
||||
|
||||
def test_a_folder_that_holds_them_gets_them(self):
|
||||
said, installed = self._install(holds=True)
|
||||
self.assertEqual(installed, ["gba_bios.bin", "zxs:48.rom"])
|
||||
self.assertNotIn("left out", said)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -202,7 +202,8 @@ def _dumps(doc: object) -> bytes:
|
||||
|
||||
|
||||
def write_index(folder: Path, systems: dict | None = None, arcade: dict | None = None,
|
||||
setup: dict | None = None, extra_sets: dict | None = None) -> None:
|
||||
setup: dict | None = None, extra_sets: dict | None = None,
|
||||
more_setups: dict | None = None) -> None:
|
||||
"""install/games/ as the generator lays it out, every digest right."""
|
||||
rows = sorted({(dest, FILES[dest][0], "bios") for files, _o in SETS.values()
|
||||
for dest in files})
|
||||
@@ -213,7 +214,7 @@ def write_index(folder: Path, systems: dict | None = None, arcade: dict | None =
|
||||
"optional": [position[d] for d in optional],
|
||||
"bytes": 0, "required_bytes": 0}
|
||||
for key, (files, optional) in sets.items()}}
|
||||
docs = {"setups": {"retroarch": setup or SETUP}, "fallback": {"retroarch": fallback},
|
||||
docs = {"setups": {"retroarch": setup or SETUP, **(more_setups or {})}, "fallback": {"retroarch": fallback},
|
||||
"systems": {key: {"format_version": 1, "system": key, **value}
|
||||
for key, value in (systems or SYSTEMS).items()},
|
||||
"arcade": {"fbneo": {"profile": "fbneo", **(arcade or ARCADE)}}}
|
||||
@@ -912,6 +913,34 @@ class CommandLine(unittest.TestCase):
|
||||
self.assertTrue((self.card.cache / install.GAMES_SCAN_FILE).is_file())
|
||||
|
||||
|
||||
class AMuosCardNamedByItsList(unittest.TestCase):
|
||||
"""The full screen passes --platform=retroarch for a muOS card, and the
|
||||
run said no games folder was found beside MUOS/bios, where line mode,
|
||||
which had detected the card, read ROMS/."""
|
||||
|
||||
def test_the_card_its_bios_folder_is_on_names_its_rom_folders(self):
|
||||
card = Card()
|
||||
self.addCleanup(card.close)
|
||||
root = card.root / "MUOSCARD"
|
||||
card.bios = root / "MUOS" / "bios"
|
||||
card.bios.mkdir(parents=True)
|
||||
game = root / "ROMS" / "MD" / "eu.md"
|
||||
game.parent.mkdir(parents=True)
|
||||
game.write_bytes(MD_EU)
|
||||
muos = dict(SETUP, setup="muos", name="muOS",
|
||||
roms_root={"path": "/mnt/mmc/ROMS", "from_bios": "../../ROMS"})
|
||||
# RetroArch's own setup names no rom folder (configuration.c).
|
||||
retroarch = dict(SETUP, roms_root={"path": None, "from_bios": None})
|
||||
write_index(card.lists / "games", setup=retroarch, more_setups={"muos": muos})
|
||||
proc = run_cli(card, "--for-games", "--check", "--events")
|
||||
events = [json.loads(line) for line in proc.stdout.splitlines()
|
||||
if line.startswith("{")]
|
||||
self.assertEqual([e for e in events if e["event"] == "games_unavailable"], [])
|
||||
games = next(e for e in events if e["event"] == "games")
|
||||
self.assertEqual(games["folder"], str(root / "ROMS"))
|
||||
self.assertEqual(games["games"], 1)
|
||||
|
||||
|
||||
class ARunThatAsksNothing(unittest.TestCase):
|
||||
"""`--yes` alone installed the whole list (6.4 GB on a dArkOS card that
|
||||
held two games), while the screen offers what the games need first."""
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
"""The five journeys of the full screen, keys counted from launch.
|
||||
|
||||
Measured on 2026-11-09: a first install with RetroArch found, a muOS card
|
||||
in a reader holding a game, an update after a release, an install narrowed
|
||||
to one system then run again, a look at what is missing, and a folder for
|
||||
another device. Each test drives the real install.py --tui on a
|
||||
pseudo-terminal against a loopback repository, every key counted, typed
|
||||
letters included. A journey that takes another number of keys than
|
||||
JOURNEY_KEYS fails: a change that shortens one lowers its count here, and
|
||||
one that lengthens it has to say so here too.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
|
||||
|
||||
import functools
|
||||
import hashlib
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(REPO_ROOT))
|
||||
sys.path.insert(0, str(REPO_ROOT / "tests"))
|
||||
|
||||
import install # noqa: E402
|
||||
import test_install_games as games # noqa: E402
|
||||
from test_install_tui import DOWN, UP, Pty, pty, pyte # noqa: E402
|
||||
|
||||
END = "\x1b[F"
|
||||
ESC = "\x1b"
|
||||
|
||||
# (keys to start the install or reach the answer, keys in all). One system
|
||||
# is reached through None and the filter, the other device's folder typed
|
||||
# as ~/bios.
|
||||
JOURNEY_KEYS = {
|
||||
"first_install": (2, 3),
|
||||
"card_with_games": (2, 3),
|
||||
"update": (2, 3),
|
||||
"one_system": (14, 15),
|
||||
"one_system_again": (2, 3),
|
||||
"what_is_missing": (5, 6),
|
||||
"another_device": (19, 20),
|
||||
}
|
||||
|
||||
# Runs install.py with the mounted drives a reader would show, none or the
|
||||
# card named: the drives of the machine running the tests (WSL's /mnt/d)
|
||||
# changed the screens. Only the screen's own process looks for cards: the
|
||||
# runs it starts are given --platform and --dest.
|
||||
_WITH_CARDS = (
|
||||
"import os, sys\n"
|
||||
"from pathlib import Path\n"
|
||||
"sys.argv[0] = {script!r}\n"
|
||||
"sys.path.insert(0, os.path.dirname(sys.argv[0]))\n"
|
||||
"import install\n"
|
||||
"card = os.environ.get('JOURNEY_CARD')\n"
|
||||
"install._mounted_cards = lambda: [Path(card)] if card else []\n"
|
||||
"install._line_buffered_stdout()\n"
|
||||
"install.main()\n"
|
||||
)
|
||||
|
||||
|
||||
class _Quiet(http.server.SimpleHTTPRequestHandler):
|
||||
def log_message(self, format, *args): # noqa: A002 - stdlib signature
|
||||
return
|
||||
|
||||
|
||||
class Repository:
|
||||
"""The games fixture of test_install_games served on loopback: a
|
||||
RetroArch list, the same list for Batocera, the games index with a
|
||||
muOS setup, and every payload."""
|
||||
|
||||
def __init__(self, test: unittest.TestCase) -> None:
|
||||
(REPO_ROOT / "tmp").mkdir(exist_ok=True)
|
||||
self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
|
||||
test.addCleanup(shutil.rmtree, self.root, True)
|
||||
self.site = self.root / "site"
|
||||
(self.site / "install" / "games").mkdir(parents=True)
|
||||
(self.site / "bios").mkdir()
|
||||
self.listed = games.manifest()
|
||||
self.write_list()
|
||||
muos = dict(games.SETUP, setup="muos", name="muOS",
|
||||
roms_root={"path": "/mnt/mmc/ROMS", "from_bios": "../../ROMS"})
|
||||
retroarch = dict(games.SETUP, roms_root={"path": None, "from_bios": None})
|
||||
games.write_index(self.site / "install" / "games", setup=retroarch,
|
||||
more_setups={"muos": muos})
|
||||
handler = functools.partial(_Quiet, directory=str(self.site))
|
||||
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
test.addCleanup(server.server_close)
|
||||
test.addCleanup(server.shutdown)
|
||||
self.home = self.root / "home"
|
||||
self.home.mkdir()
|
||||
self.env = {**os.environ, "TERM": "xterm", "HOME": str(self.home),
|
||||
"RETROBIOS_OS": "linux", "XDG_CONFIG_HOME": str(self.home / ".config"),
|
||||
"RETROBIOS_BASE_URL": f"http://127.0.0.1:{server.server_address[1]}",
|
||||
"RETROBIOS_CACHE": str(self.root / "cache")}
|
||||
for name in ("DISPLAY", "WAYLAND_DISPLAY", "SSH_CONNECTION", "SSH_TTY", "NO_COLOR",
|
||||
install.TUI_PAD_ENV, install.OFFLINE_VARIABLE, *install._STEAM_MARKERS):
|
||||
self.env.pop(name, None)
|
||||
|
||||
def write_list(self) -> None:
|
||||
for entry in self.listed["files"]:
|
||||
payload = entry["dest"].encode().ljust(entry["size"], b".")[:entry["size"]]
|
||||
entry["sha1"] = hashlib.sha1(payload).hexdigest()
|
||||
entry["sha256"] = hashlib.sha256(payload).hexdigest()
|
||||
(self.site / entry["repo_path"]).write_bytes(payload)
|
||||
for plat in ("retroarch", "batocera"):
|
||||
(self.site / "install" / f"{plat}.json").write_text(
|
||||
json.dumps({**self.listed, "platform": plat}))
|
||||
|
||||
def retroarch_here(self) -> Path:
|
||||
"""A RetroArch whose configuration names its system folder."""
|
||||
dest = self.root / "retroarch" / "system"
|
||||
dest.mkdir(parents=True)
|
||||
config = self.home / ".config" / "retroarch"
|
||||
config.mkdir(parents=True)
|
||||
(config / "retroarch.cfg").write_text(f'system_directory = "{dest}"\n')
|
||||
return dest
|
||||
|
||||
|
||||
def written(folder: Path) -> list[str]:
|
||||
return sorted(p.relative_to(folder).as_posix() for p in folder.rglob("*") if p.is_file())
|
||||
|
||||
|
||||
@unittest.skipUnless(pyte and pty, "the journeys need pyte and a pty")
|
||||
class Journeys(unittest.TestCase):
|
||||
def start(self, repo: Repository, *args: str, env: dict | None = None) -> Pty:
|
||||
program = [sys.executable, "-c",
|
||||
_WITH_CARDS.format(script=str(REPO_ROOT / "install.py"))]
|
||||
term = Pty(list(args), {**repo.env, **(env or {})}, 80, 24, program=program)
|
||||
self.addCleanup(lambda: term.status is None and os.kill(term.pid, 9))
|
||||
self.keys = 0
|
||||
return term
|
||||
|
||||
def press(self, term: Pty, *keys: str) -> None:
|
||||
"""Each key sent, a typed word counted letter by letter."""
|
||||
for key in keys:
|
||||
if len(key) > 1 and not key.startswith(ESC):
|
||||
for letter in key:
|
||||
term.send(letter)
|
||||
self.keys += 1
|
||||
else:
|
||||
term.send(key)
|
||||
self.keys += 1
|
||||
|
||||
def counted(self, journey: str, started: int, total: int) -> None:
|
||||
self.assertEqual((started, total), JOURNEY_KEYS[journey],
|
||||
f"{journey} takes {(started, total)} keys now: longer is a step "
|
||||
"back, shorter lowers JOURNEY_KEYS")
|
||||
|
||||
def finish(self, term: Pty) -> int:
|
||||
term.wait("A/Enter Exit", timeout=60)
|
||||
self.press(term, "\r")
|
||||
return term.close()
|
||||
|
||||
def test_first_install_with_retroarch_found(self):
|
||||
repo = Repository(self)
|
||||
dest = repo.retroarch_here()
|
||||
term = self.start(repo)
|
||||
screen = term.wait("Where to install?", timeout=40)
|
||||
self.assertIn("> RetroArch", screen)
|
||||
self.press(term, "\r")
|
||||
term.wait("files to download", timeout=40)
|
||||
self.press(term, "\r")
|
||||
started = self.keys
|
||||
self.assertEqual(self.finish(term), 0)
|
||||
self.counted("first_install", started, self.keys)
|
||||
self.assertEqual(written(dest), sorted(e["dest"] for e in repo.listed["files"]))
|
||||
|
||||
def test_a_muos_card_holding_a_game(self):
|
||||
"""The screen passes --platform=retroarch to its runs: the card's
|
||||
games were not read, and the plan offered the whole list."""
|
||||
repo = Repository(self)
|
||||
card = repo.root / "MUOS"
|
||||
bios = card / "MUOS" / "bios"
|
||||
bios.mkdir(parents=True)
|
||||
(card / "ROMS" / "GBA").mkdir(parents=True)
|
||||
(card / "ROMS" / "GBA" / "unknown.gba").write_bytes(b"not in any catalog")
|
||||
term = self.start(repo, env={"JOURNEY_CARD": str(card)})
|
||||
term.wait("Where to install?", timeout=40)
|
||||
self.press(term, "\r")
|
||||
screen = term.wait("For the games on this card: yes", timeout=60)
|
||||
self.assertIn("For the 1 game on this card.", screen)
|
||||
self.press(term, "\r")
|
||||
started = self.keys
|
||||
self.assertEqual(self.finish(term), 0)
|
||||
self.counted("card_with_games", started, self.keys)
|
||||
self.assertEqual(written(bios), ["gba_bios.bin"])
|
||||
|
||||
def test_an_update_after_a_release(self):
|
||||
repo = Repository(self)
|
||||
dest = repo.retroarch_here()
|
||||
first = subprocess.run(
|
||||
[sys.executable, str(REPO_ROOT / "install.py"), "--platform", "retroarch",
|
||||
"--dest", str(dest), "--all-files", "--yes"],
|
||||
env=repo.env, capture_output=True, text=True, timeout=120, check=False,
|
||||
stdin=subprocess.DEVNULL)
|
||||
self.assertEqual(first.returncode, 0, first.stdout + first.stderr)
|
||||
# The release changes one file.
|
||||
changed = next(e for e in repo.listed["files"] if e["dest"] == "md_eu.bin")
|
||||
changed["size"] += 1
|
||||
repo.write_list()
|
||||
term = self.start(repo)
|
||||
term.wait("Where to install?", timeout=40)
|
||||
self.press(term, "\r")
|
||||
term.wait("1 file to download", timeout=40)
|
||||
self.press(term, "\r")
|
||||
started = self.keys
|
||||
self.assertEqual(self.finish(term), 0)
|
||||
self.counted("update", started, self.keys)
|
||||
self.assertEqual((dest / "md_eu.bin").stat().st_size, changed["size"])
|
||||
|
||||
def test_one_system_then_the_same_again(self):
|
||||
repo = Repository(self)
|
||||
dest = repo.retroarch_here()
|
||||
term = self.start(repo)
|
||||
term.wait("Where to install?", timeout=40)
|
||||
self.press(term, "\r")
|
||||
term.wait("files to download", timeout=40)
|
||||
for _step in range(12):
|
||||
if "> Choose systems" in term.settle():
|
||||
break
|
||||
self.press(term, DOWN)
|
||||
self.press(term, "\r")
|
||||
term.wait("RetroBIOS: Choose systems")
|
||||
# None, the filter, the system ticked, Esc clearing the filter,
|
||||
# Esc for Done.
|
||||
self.press(term, "n", "/", "gba", "\r", "\r", ESC, ESC)
|
||||
term.wait("for 1 of", timeout=20)
|
||||
self.press(term, "\r")
|
||||
term.wait("Counted again for these choices", timeout=40)
|
||||
self.press(term, "\r")
|
||||
started = self.keys
|
||||
self.assertEqual(self.finish(term), 0)
|
||||
self.counted("one_system", started, self.keys)
|
||||
self.assertEqual(written(dest), ["gba_bios.bin"])
|
||||
# The next release: the earlier choice is not kept, and two keys
|
||||
# install the whole list.
|
||||
term = self.start(repo)
|
||||
term.wait("Where to install?", timeout=40)
|
||||
self.press(term, "\r")
|
||||
term.wait("files to download", timeout=40)
|
||||
self.press(term, "\r")
|
||||
started = self.keys
|
||||
self.assertEqual(self.finish(term), 0)
|
||||
self.counted("one_system_again", started, self.keys)
|
||||
self.assertEqual(written(dest), sorted(e["dest"] for e in repo.listed["files"]))
|
||||
|
||||
def test_what_is_missing(self):
|
||||
repo = Repository(self)
|
||||
repo.retroarch_here()
|
||||
term = self.start(repo)
|
||||
term.wait("Where to install?", timeout=40)
|
||||
self.press(term, "\r")
|
||||
term.wait("files to download", timeout=40)
|
||||
self.press(term, "o")
|
||||
term.wait("Each row is an option")
|
||||
self.press(term, END, UP)
|
||||
term.wait("> Preview the file list")
|
||||
self.press(term, "\r")
|
||||
term.wait("md_eu.bin", timeout=40)
|
||||
started = self.keys
|
||||
self.press(term, "q")
|
||||
self.assertEqual(term.close(), 2)
|
||||
self.counted("what_is_missing", started, self.keys)
|
||||
|
||||
def test_a_folder_for_another_device(self):
|
||||
repo = Repository(self)
|
||||
repo.retroarch_here()
|
||||
term = self.start(repo)
|
||||
term.wait("Where to install?", timeout=40)
|
||||
for _step in range(12):
|
||||
if "> Another setup or folder" in term.settle():
|
||||
break
|
||||
self.press(term, DOWN)
|
||||
self.press(term, "\r")
|
||||
term.wait("Which setup?")
|
||||
# The filter's Enter takes the one setup it leaves.
|
||||
self.press(term, "/", "bato", "\r")
|
||||
term.wait("Which folder?", timeout=40)
|
||||
self.press(term, DOWN, "\r")
|
||||
term.wait("RetroBIOS: Type a path")
|
||||
self.press(term, "~/bios", "\r")
|
||||
term.wait("Create the folder?")
|
||||
self.press(term, "\r")
|
||||
screen = term.wait("files to download", timeout=40)
|
||||
self.assertIn("RetroBIOS: Batocera", screen)
|
||||
self.press(term, "\r")
|
||||
started = self.keys
|
||||
self.assertEqual(self.finish(term), 0)
|
||||
self.counted("another_device", started, self.keys)
|
||||
self.assertEqual(written(repo.home / "bios"),
|
||||
sorted(e["dest"] for e in repo.listed["files"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -913,6 +913,57 @@ class InstallMatchesASystemPack(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class DataTreesFollowTheSystemsTheyServe(InstallMatchesASystemPack):
|
||||
"""The data trees a system choice keeps, installer against pack. GBA
|
||||
alone took FBNeo's cheats and samples, 3,472 files, because the trees
|
||||
listed every FBNeo system. The Mega Drive took no cheat: the tree said
|
||||
sega-megadrive where RetroArch's list says sega-mega-drive."""
|
||||
|
||||
CASES = ((["nintendo-gba"], []), (["sega-mega-drive"], []), (["arcade"], []))
|
||||
|
||||
def _packed(self, systems, regions) -> set[str]:
|
||||
import zipfile
|
||||
|
||||
from common import load_data_dir_registry
|
||||
|
||||
# The trees come from the registry the manifest reads by itself.
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out:
|
||||
zip_path = self.gp.generate_pack(
|
||||
self.PLATFORM, str(REPO_ROOT / "platforms"), self.db,
|
||||
str(REPO_ROOT / "bios"), out,
|
||||
emulators_dir=str(REPO_ROOT / "emulators"),
|
||||
emu_profiles=self.profiles, system_filter=systems,
|
||||
regions=regions or None, offline=True,
|
||||
data_registry=load_data_dir_registry(str(REPO_ROOT / "platforms")),
|
||||
)
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
names = set(zf.namelist())
|
||||
prefix = f"{self.base}/" if self.base else ""
|
||||
return {n[len(prefix):] if prefix and n.startswith(prefix) else n for n in names}
|
||||
|
||||
def _members(self, trees) -> set[str]:
|
||||
return {f"{tree['dest']}/{rel}" if tree["dest"] else rel
|
||||
for tree in trees for rel in tree["files"]}
|
||||
|
||||
def test_each_case(self):
|
||||
everything = self._members(self.full.get("data_directories") or [])
|
||||
for systems, regions in self.CASES:
|
||||
with self.subTest(systems=systems):
|
||||
files, _omitted = install.narrow(
|
||||
self.full["files"], self.full["omitted_files"], systems, [], regions)
|
||||
trees = install.select_data_directories(self.full, files, True, systems=systems)
|
||||
refs = {tree["ref"] for tree in trees}
|
||||
if systems == ["nintendo-gba"]:
|
||||
self.assertFalse({"fbneo-cheats", "fbneo-samples"} & refs)
|
||||
if systems == ["sega-mega-drive"]:
|
||||
self.assertIn("fbneo-cheats", refs)
|
||||
self.assertNotIn("fbneo-samples", refs)
|
||||
if systems == ["arcade"]:
|
||||
self.assertTrue({"fbneo-cheats", "fbneo-samples"} <= refs)
|
||||
self.assertEqual(self._members(trees),
|
||||
self._packed(systems, regions) & everything)
|
||||
|
||||
|
||||
class InstallMatchesATargetManifest(unittest.TestCase):
|
||||
"""`install.py --target T` against the manifest the builder writes for T.
|
||||
|
||||
|
||||
@@ -1729,6 +1729,23 @@ class TicksBarAndPaths(unittest.TestCase):
|
||||
rows = install.tui_rows(state)
|
||||
return rows[state.focus[state.screen]]
|
||||
|
||||
def test_install_says_the_size_the_headline_says(self):
|
||||
"""One system ticked: the headline said About 3479 files, 82.2 MB
|
||||
and the row Install 6.6 GB, the whole list's size."""
|
||||
big = 6 * 1024 ** 3
|
||||
state = checked_state()
|
||||
state.files[0] = {**state.files[0], "size": big}
|
||||
state.check = {**state.check, "bytes_needed": state.check["bytes_needed"] + big}
|
||||
self.assertEqual(install.tui_rows(state)[0].label, "Install 6.0 GB")
|
||||
for system, label, head in (("nintendo-gba", "Install", "About 1 file, 16.0 KB"),
|
||||
("sony-playstation", "Install 6.0 GB",
|
||||
"About 3 files, 6.0 GB")):
|
||||
with self.subTest(system=system):
|
||||
state.ticked = {system}
|
||||
self.assertTrue(install._tui_estimating(state))
|
||||
self.assertEqual(install.tui_rows(state)[0].label, label)
|
||||
self.assertIn(head, "\n".join(install.tui_view(state, 80, 24)))
|
||||
|
||||
def test_the_filter_never_changes_the_ticks(self):
|
||||
state = self.systems()
|
||||
press(state, "n")
|
||||
@@ -3802,6 +3819,22 @@ class BackTicksAndSaveFolder(unittest.TestCase):
|
||||
text = " ".join(install.tui_view(state, 80, 24))
|
||||
self.assertNotIn("No system is ticked", text)
|
||||
|
||||
def test_the_page_says_where_the_list_opens(self):
|
||||
"""wiki/installer.md said a long list opens on None, where A
|
||||
unticked every system as the first press: the focus moved to the
|
||||
first system, and the page kept the old words."""
|
||||
state = self.long_list()
|
||||
self.assertGreater(len(state.systems), install.TUI_LONG_LIST)
|
||||
press(state, "down", "enter")
|
||||
rows = install.tui_rows(state)
|
||||
self.assertEqual(state.focus["systems"],
|
||||
next(i for i, row in enumerate(rows) if row.action == "system"))
|
||||
self.assertEqual([row.action for row in rows][-3:], ["all", "none", "done"])
|
||||
page = " ".join((REPO_ROOT / "wiki" / "installer.md").read_text(encoding="utf-8").split())
|
||||
self.assertNotIn("opens on **None**", page)
|
||||
self.assertIn("It opens on its first system, every system ticked", page)
|
||||
self.assertIn("**None** (`a` and `n`) sit at the end of the list", page)
|
||||
|
||||
def test_back_after_a_choice_keeps_the_choice(self):
|
||||
state = self.long_list()
|
||||
press(state, "down", "enter", "enter")
|
||||
|
||||
@@ -301,6 +301,60 @@ RECORD = {
|
||||
}
|
||||
|
||||
|
||||
class APackForAndroidHidesItsMedia(PackCountFixture):
|
||||
"""RetroArch Android writes no .nomedia, and its system folder held the
|
||||
samples, overlays and videos the gallery and music apps then showed."""
|
||||
|
||||
def _pack(self, target: str | None) -> dict[str, int]:
|
||||
targets = self.platforms / "targets"
|
||||
targets.mkdir(exist_ok=True)
|
||||
(targets / "demo.yml").write_text(yaml.dump({"platform": "demo", "targets": {
|
||||
"android-arm64-v8a": {"architecture": "aarch64", "cores": ["demo"]},
|
||||
"linux-x86_64": {"architecture": "x86_64", "cores": ["demo"]},
|
||||
}}))
|
||||
out = self.root / f"dist-{target}"
|
||||
out.mkdir()
|
||||
zip_path = builder.generate_pack(
|
||||
"demo", str(self.platforms), self.db, str(self.bios), str(out),
|
||||
emulators_dir=str(self.emulators), emu_profiles=self.profiles,
|
||||
data_registry=self.registry, offline=True, target_name=target,
|
||||
)
|
||||
with zipfile.ZipFile(zip_path) as archive:
|
||||
return {m.filename: m.file_size for m in archive.infolist()}
|
||||
|
||||
def test_the_whole_pack_and_an_android_one_carry_it(self):
|
||||
for target in (None, "android-arm64-v8a"):
|
||||
with self.subTest(target=target):
|
||||
self.assertEqual(self._pack(target).get(".nomedia"), 0)
|
||||
|
||||
def test_a_pack_for_another_target_does_not(self):
|
||||
self.assertNotIn(".nomedia", self._pack("linux-x86_64"))
|
||||
|
||||
def test_the_manifest_counts_it(self):
|
||||
members = self._pack(None)
|
||||
manifest = builder.generate_manifest(
|
||||
"demo", str(self.platforms), self.db, str(self.bios),
|
||||
str(self.platforms / "_registry.yml"),
|
||||
emulators_dir=str(self.emulators), emu_profiles=self.profiles,
|
||||
offline=True, data_registry=self.registry,
|
||||
)
|
||||
self.assertEqual(manifest["pack_files"], len(set(members) | {"manifest.json"}))
|
||||
|
||||
def test_the_integrity_check_takes_it_for_a_marker(self):
|
||||
import packverify
|
||||
|
||||
buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(buffer, "w") as archive:
|
||||
archive.writestr(".nomedia", b"")
|
||||
archive.writestr("empty.bin", b"")
|
||||
with zipfile.ZipFile(buffer) as archive:
|
||||
errors = packverify._structural_errors(archive, set(archive.namelist()))
|
||||
self.assertEqual(errors, ["zero-byte: empty.bin"])
|
||||
|
||||
def test_a_platform_without_android_gets_none(self):
|
||||
self.assertEqual(builder.pack_markers("demo", None, str(self.platforms)), ())
|
||||
|
||||
|
||||
class TheTableDescribesTheRelease(unittest.TestCase):
|
||||
"""The Download link gives the last release, not what main would build.
|
||||
|
||||
|
||||
Reference in new issue
Block a user