mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-18 23:57:55 -06:00
chore: merge tooling fixes, fourth pass
This commit is contained in:
commit
e491ff1bc6
45 files changed
+801
-153
No files matched your search
+11
-3
@@ -13,6 +13,7 @@ temporary directory instead of naming the missing parent.
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
os.environ.setdefault("RETROBIOS_OFFLINE", "1")
|
||||
@@ -22,9 +23,16 @@ os.environ.setdefault(
|
||||
str(Path(__file__).resolve().parent.parent / "tmp" / "tests" / "probe.lock"),
|
||||
)
|
||||
|
||||
(Path(__file__).resolve().parent.parent / "tmp" / "tests").mkdir(
|
||||
parents=True, exist_ok=True
|
||||
)
|
||||
_SCRATCH = Path(__file__).resolve().parent.parent / "tmp" / "tests"
|
||||
_SCRATCH.mkdir(parents=True, exist_ok=True)
|
||||
# A TemporaryDirectory() without dir= landed in /tmp, a 4 GB tmpfs here: once
|
||||
# another run filled it, modules unrelated to any change failed with ENOSPC.
|
||||
# The default is the repository's tmp/, for this process and its children.
|
||||
os.environ["TMPDIR"] = str(_SCRATCH)
|
||||
tempfile.tempdir = str(_SCRATCH)
|
||||
# A scratch directory is not part of this checkout: git run inside one must
|
||||
# not walk up to the repository, as it could not from /tmp.
|
||||
os.environ["GIT_CEILING_DIRECTORIES"] = str(_SCRATCH)
|
||||
# The installer's cache (the games index, what reading a card found) is the
|
||||
# suite's own: a run never reads nor fills the one of the person running it.
|
||||
os.environ.setdefault(
|
||||
|
||||
@@ -61,6 +61,28 @@ class ArtifactLockTest(unittest.TestCase):
|
||||
with artifact_lock(self.dir, exclusive=False):
|
||||
pass
|
||||
|
||||
def test_a_reader_never_creates_the_directory(self):
|
||||
"""A mistyped --output-dir given to --verify-packs or release_record
|
||||
was created holding a .lock, and the next run with the same typo no
|
||||
longer said the path did not exist."""
|
||||
from common import ArtifactDirectoryMissing # noqa: PLC0415
|
||||
|
||||
missing = os.path.join(self.dir, "sub", "dsit")
|
||||
with self.assertRaises(ArtifactDirectoryMissing):
|
||||
with artifact_lock(missing, exclusive=False):
|
||||
pass
|
||||
self.assertFalse(os.path.exists(os.path.join(self.dir, "sub")))
|
||||
|
||||
def test_split_refuses_a_missing_target_before_locking(self):
|
||||
missing = Path(self.dir) / "sub" / "dsit"
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "scripts/split_pack.py", str(missing)],
|
||||
cwd=REPO_ROOT, capture_output=True, text=True, check=False, timeout=60,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 1)
|
||||
self.assertIn("no such pack or directory", proc.stderr)
|
||||
self.assertFalse(missing.parent.exists())
|
||||
|
||||
def test_lock_is_released_on_exit(self):
|
||||
with artifact_lock(self.dir):
|
||||
pass
|
||||
|
||||
@@ -206,11 +206,16 @@ class AModuleRunAloneHasItsScratchDirectory(unittest.TestCase):
|
||||
)
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "-I", "-c",
|
||||
"import sys; sys.path.insert(0, '.'); import tests"],
|
||||
"import sys; sys.path.insert(0, '.'); import tests, tempfile, os;"
|
||||
" print(tempfile.gettempdir()); print(os.environ['TMPDIR'])"],
|
||||
cwd=clone, capture_output=True, text=True, timeout=60, check=False,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 0, proc.stderr)
|
||||
self.assertTrue((clone / "tmp" / "tests").is_dir())
|
||||
# 264 TemporaryDirectory() calls without dir= wrote to the /tmp
|
||||
# tmpfs, and a full tmpfs failed modules no change touched.
|
||||
scratch = str((clone / "tmp" / "tests").resolve())
|
||||
self.assertEqual(proc.stdout.split(), [scratch, scratch])
|
||||
|
||||
|
||||
class ReleaseSigningRegressions(unittest.TestCase):
|
||||
@@ -2291,7 +2296,9 @@ class EveryManifestEntryIsFetchable(unittest.TestCase):
|
||||
else "gitignored" if repo_path in ignored
|
||||
else "untracked, never committed"
|
||||
)
|
||||
if bool(entry.get("release_asset")) != (state == "gitignored"):
|
||||
if state == "untracked, never committed" or (
|
||||
bool(entry.get("release_asset")) != (state == "gitignored")
|
||||
):
|
||||
wrong.append((entry["dest"], repo_path, state))
|
||||
self.assertEqual(wrong, [], f"{name} picks the wrong source: {wrong[:3]}")
|
||||
|
||||
@@ -2305,6 +2312,36 @@ class EveryManifestEntryIsFetchable(unittest.TestCase):
|
||||
self.skipTest("not a git checkout")
|
||||
self.assertEqual(sorted(untracked)[:20], [], f"{len(untracked)} untracked files under bios/")
|
||||
|
||||
def test_every_database_path_is_committed_or_a_release_asset(self):
|
||||
"""A git mv under bios/ committed without regenerating anything left
|
||||
database.json and the manifests agreeing on the old path: the tests
|
||||
above compare them with each other, so all passed, and the installer
|
||||
got a 404 (issue 78, with the database stale too)."""
|
||||
database = ROOT / "database.json"
|
||||
if not database.is_file():
|
||||
self.skipTest("database.json not generated")
|
||||
files = json.loads(database.read_text(encoding="utf-8"))["files"]
|
||||
paths = {
|
||||
path
|
||||
for entry in files.values()
|
||||
for path in [entry.get("path"), *(entry.get("paths") or [])]
|
||||
if path
|
||||
}
|
||||
tracked = _git_paths("ls-files", "-z")
|
||||
if tracked is None:
|
||||
self.skipTest("not a git checkout")
|
||||
outside = sorted(paths - tracked)
|
||||
ignored = _git_paths("check-ignore", "-z", "--no-index", "--stdin", stdin=outside)
|
||||
if ignored is None:
|
||||
self.skipTest("not a git checkout")
|
||||
stale = [path for path in outside if path not in ignored]
|
||||
self.assertEqual(
|
||||
stale[:20], [],
|
||||
f"{len(stale)} database paths git neither holds nor ignores: "
|
||||
"python scripts/generate_db.py --force --bios-dir bios --output database.json, "
|
||||
"then the manifests",
|
||||
)
|
||||
|
||||
|
||||
class ReleaseAssetCriterion(unittest.TestCase):
|
||||
"""What decides whether the installer fetches from the release is git, not size.
|
||||
|
||||
@@ -891,6 +891,16 @@ class BiosIntegrity(Scratch):
|
||||
self.assertEqual([(f.path, f.verdict) for f in report.findings], [(rel, bib.SKIPPED)])
|
||||
self.assertEqual((self.repo / rel).read_bytes(), b"\x02" * 80)
|
||||
|
||||
def test_an_unreadable_index_stops_before_any_restore(self):
|
||||
"""git status failed on a corrupt index, its empty stdout read as
|
||||
"unmodified", and --apply wrote HEAD's bytes over the session's."""
|
||||
rel = "bios/Sony/edited.bin"
|
||||
(self.repo / rel).write_bytes(b"\x02" * 80)
|
||||
(self.repo / ".git" / "index").write_bytes(b"garbage\n")
|
||||
with self.assertRaises(bib.GitFailed):
|
||||
bib.check(self.repo, self.db, apply=True)
|
||||
self.assertEqual((self.repo / rel).read_bytes(), b"\x02" * 80)
|
||||
|
||||
def test_a_mismatch_the_second_read_does_not_confirm_is_a_misread(self):
|
||||
reads = {}
|
||||
expected = {e["path"]: e["sha1"] for e in self.db["files"].values()}
|
||||
|
||||
@@ -35,6 +35,14 @@ class NativeCacheTests(unittest.TestCase):
|
||||
self.root.mkdir()
|
||||
self.wanted = {"list.txt": "https://example.invalid/tag-2/list.txt"}
|
||||
|
||||
def test_an_unreadable_index_is_an_error_not_unrecorded(self):
|
||||
"""Read as empty, it named "no URL recorded" for every original."""
|
||||
self.index.write_text("{", encoding="utf-8")
|
||||
findings = cf.check_native(REPO_ROOT / "platforms", self.cache, self.cache)
|
||||
self.assertEqual([(f.subject, f.status) for f in findings],
|
||||
[(self.index.name, cf.ERROR)])
|
||||
self.assertIn("--refresh-cache", findings[0].detail)
|
||||
|
||||
def _cached(self, mtime: float) -> None:
|
||||
path = self.root / "list.txt"
|
||||
path.write_text("x", encoding="utf-8")
|
||||
@@ -734,6 +742,19 @@ class RowsSayAllTheyStandFor(unittest.TestCase):
|
||||
rows = [line for line in text.splitlines() if line.startswith(" STALE")]
|
||||
self.assertEqual(rows[0].index("no longer"), rows[1].index("is not what"))
|
||||
|
||||
def test_a_remote_value_keeps_the_detail_column(self):
|
||||
"""A row with a remote value pushed its detail past the column the
|
||||
rows without one used, in [coreinfo] by some fifteen characters."""
|
||||
text = cf.render([
|
||||
cf.Finding("coreinfo", "anybor", cf.STALE, detail="no profile claims"),
|
||||
cf.Finding("coreinfo", "amiberry", cf.STALE, local="e5d1f0f9a143",
|
||||
remote="ae545d85c06f", detail=".info changed"),
|
||||
cf.Finding("coreinfo", "x", cf.STALE, local="abc", remote="d", detail="third"),
|
||||
])
|
||||
rows = [line for line in text.splitlines() if line.startswith(" STALE")]
|
||||
columns = {row.index(word) for row, word in zip(rows, ("no profile", ".info", "third"))}
|
||||
self.assertEqual(len(columns), 1, rows)
|
||||
|
||||
def test_json_carries_every_unresolved_name(self):
|
||||
missing = {f"core{i:02d}": [] for i in range(50)}
|
||||
(row,) = cf._unresolved_findings("retropie", missing)
|
||||
|
||||
@@ -1005,6 +1005,22 @@ class CachedOriginal(unittest.TestCase):
|
||||
self._upstream("v1.txt", "moved")
|
||||
self.assertEqual(fetch(url, target, self.index), b"one")
|
||||
|
||||
def test_an_unreadable_index_serves_nothing(self):
|
||||
"""A truncated index read as empty: the cached batocera-41 file was
|
||||
served for a 43.1 URL, and the next download erased every other
|
||||
platform's recorded URL."""
|
||||
import export_native
|
||||
|
||||
old = self._upstream("batocera-41.txt", "old")
|
||||
target = self.cache / "plat" / "list.txt"
|
||||
fetch(old, target, self.index)
|
||||
self.index.write_text('{"plat/list.txt": "' + old + '",', encoding="utf-8")
|
||||
new = self._upstream("batocera-43.txt", "new")
|
||||
with self.assertRaises(export_native.SourcesIndexUnreadable) as caught:
|
||||
fetch(new, target, self.index)
|
||||
self.assertIn("--refresh-cache", str(caught.exception))
|
||||
self.assertTrue(self.index.read_text(encoding="utf-8").endswith(","))
|
||||
|
||||
def test_refresh_reads_a_branch_url_again(self):
|
||||
"""A branch URL keeps its name while the platform moves."""
|
||||
url = self._upstream("branch.txt", "one")
|
||||
|
||||
@@ -102,6 +102,17 @@ class FixtureImport(unittest.TestCase):
|
||||
twin = second / path.relative_to(first)
|
||||
self.assertEqual(path.read_bytes(), twin.read_bytes(), path.name)
|
||||
|
||||
def test_a_new_fetch_date_alone_rewrites_nothing(self) -> None:
|
||||
"""A refresh rewrote every catalog for the day it ran, and the diff
|
||||
read before commit no longer showed which DAT had moved."""
|
||||
self.assertEqual(run_import("redump", self.out).returncode, 0)
|
||||
path = self.out / "redump" / "sega-megacd.json"
|
||||
doc = json.loads(path.read_text())
|
||||
doc["fetched"] = "2000-01-01"
|
||||
path.write_text(importer.dump_catalog(doc))
|
||||
self.assertEqual(run_import("redump", self.out).returncode, 0)
|
||||
self.assertEqual(json.loads(path.read_text())["fetched"], "2000-01-01")
|
||||
|
||||
def test_floor_refuses_a_short_dat(self) -> None:
|
||||
result = run_import("no-intro", self.out, "--floor", "--dry-run")
|
||||
self.assertEqual(result.returncode, 1)
|
||||
|
||||
+29
-2
@@ -36,6 +36,9 @@ _spec.loader.exec_module(install)
|
||||
sys.path.insert(0, str(REPO_ROOT / "tests"))
|
||||
from netguard import module_guard # noqa: E402
|
||||
|
||||
# What a stale pin's failure says: the fix is one command.
|
||||
PIN_ADVICE = "install.py changed: python scripts/pin_installer.py rewrites both pins"
|
||||
|
||||
# No connection off the loopback and no card of the host reaches a test:
|
||||
# the module fails at its end otherwise.
|
||||
setUpModule, tearDownModule = module_guard("test_install")
|
||||
@@ -2201,7 +2204,7 @@ class TestAvailablePlatforms(unittest.TestCase):
|
||||
match = re.search(r'\$defaultInstallSha256 = "([0-9a-f]{64})"', content)
|
||||
self.assertIsNotNone(match, "install.ps1 must embed the installer SHA256")
|
||||
expected = hashlib.sha256((REPO_ROOT / "install.py").read_bytes()).hexdigest()
|
||||
self.assertEqual(match.group(1), expected)
|
||||
self.assertEqual(match.group(1), expected, PIN_ADVICE)
|
||||
|
||||
def test_powershell_wrapper_rejects_non_https_bootstrap(self):
|
||||
content = (REPO_ROOT / "install.ps1").read_text()
|
||||
@@ -2212,7 +2215,31 @@ class TestAvailablePlatforms(unittest.TestCase):
|
||||
match = re.search(r'DEFAULT_INSTALL_SHA256="([0-9a-f]{64})"', content)
|
||||
self.assertIsNotNone(match, "install.sh must embed the installer SHA256")
|
||||
expected = hashlib.sha256((REPO_ROOT / "install.py").read_bytes()).hexdigest()
|
||||
self.assertEqual(match.group(1), expected)
|
||||
self.assertEqual(match.group(1), expected, PIN_ADVICE)
|
||||
|
||||
def test_pin_script_writes_both_pins(self):
|
||||
"""Every edit to install.py meant a sha256sum pasted by hand into two
|
||||
files with two syntaxes, and the failing test named no command."""
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
import pin_installer # noqa: PLC0415
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory:
|
||||
root = Path(directory)
|
||||
for name in ("install.py", "install.sh", "install.ps1"):
|
||||
shutil.copy2(REPO_ROOT / name, root / name)
|
||||
(root / "install.py").write_text("# changed\n", encoding="utf-8")
|
||||
sh_mode = (root / "install.sh").stat().st_mode
|
||||
self.assertEqual(pin_installer.stale_pins(root), ["install.sh", "install.ps1"])
|
||||
self.assertEqual(pin_installer.write_pins(root), ["install.sh", "install.ps1"])
|
||||
self.assertEqual(pin_installer.stale_pins(root), [])
|
||||
digest = hashlib.sha256(b"# changed\n").hexdigest()
|
||||
for name in ("install.sh", "install.ps1"):
|
||||
before = (REPO_ROOT / name).read_text(encoding="utf-8").splitlines()
|
||||
after = (root / name).read_text(encoding="utf-8").splitlines()
|
||||
changed = [b for a, b in zip(before, after) if a != b]
|
||||
self.assertEqual(len(changed), 1, name)
|
||||
self.assertIn(digest, changed[0])
|
||||
self.assertEqual((root / "install.sh").stat().st_mode, sh_mode)
|
||||
|
||||
def test_shell_one_liner_downloads_verifies_and_forwards_arguments(self):
|
||||
scratch = REPO_ROOT / "tmp" / "tests"
|
||||
|
||||
@@ -373,6 +373,8 @@ class Helpers(unittest.TestCase):
|
||||
self.assertEqual(el.emulator_of_script("emuDeckXemu.sh"), "xemu")
|
||||
self.assertIsNone(el.emulator_of_script("RetroArch_maincfg.sh"))
|
||||
self.assertIsNone(el.emulator_of_script("README.md"))
|
||||
self.assertEqual(el.emulator_of_script("emuDeckPCSX2QT.ps1"), "pcsx2")
|
||||
self.assertIsNone(el.emulator_of_script("emuDeckTemplate.ps1"))
|
||||
|
||||
def test_the_revision_comes_from_the_pinned_url(self):
|
||||
url = (
|
||||
|
||||
@@ -118,6 +118,35 @@ class RefreshConcurrency(unittest.TestCase):
|
||||
self.assertTrue(finished, "the refresh waited for a reader")
|
||||
self.assertEqual(result, [False])
|
||||
|
||||
def test_a_waiting_refresh_names_the_lock_and_the_way_around(self):
|
||||
""""waiting for data/dolphin-sys: another run holds it" named
|
||||
neither the lock nor its holder, and the build waited unbounded."""
|
||||
import fcntl # noqa: PLC0415
|
||||
|
||||
self.cache.mkdir(parents=True)
|
||||
lock_path = self.cache.with_name(".pak.lock")
|
||||
entered = threading.Event()
|
||||
|
||||
def refresh() -> None:
|
||||
with rdd.cache_lock(self.cache):
|
||||
entered.set()
|
||||
|
||||
with open(lock_path, "a") as reader, self.assertLogs(rdd.log, "WARNING") as logs:
|
||||
fcntl.flock(reader, fcntl.LOCK_SH)
|
||||
worker = threading.Thread(target=refresh, daemon=True)
|
||||
worker.start()
|
||||
for _ in range(200):
|
||||
if logs.records:
|
||||
break
|
||||
worker.join(timeout=0.05)
|
||||
self.assertFalse(entered.is_set())
|
||||
fcntl.flock(reader, fcntl.LOCK_UN)
|
||||
worker.join(timeout=20)
|
||||
self.assertTrue(entered.is_set())
|
||||
message = logs.records[0].getMessage()
|
||||
self.assertIn(f"lsof {lock_path}", message)
|
||||
self.assertIn("--no-refresh-data", message)
|
||||
|
||||
def test_version_file_is_never_left_truncated(self):
|
||||
Path(self.versions).parent.mkdir(parents=True)
|
||||
Path(self.versions).write_text(json.dumps({"keep": {"sha": "1"}}))
|
||||
|
||||
@@ -162,6 +162,11 @@ class Planning(unittest.TestCase):
|
||||
self.assertEqual(jobs, [])
|
||||
self.assertEqual(len(surfaced), 3)
|
||||
|
||||
def test_the_installer_pin_is_written_by_its_script(self):
|
||||
jobs, surfaced, _ = self._plan(finding("ci", "install.py pin"))
|
||||
self.assertEqual([job.command[1:] for job in jobs], [["scripts/pin_installer.py"]])
|
||||
self.assertEqual(surfaced, [])
|
||||
|
||||
|
||||
class Running(unittest.TestCase):
|
||||
def test_a_child_starts_after_its_parent_ends(self):
|
||||
@@ -234,6 +239,38 @@ class SavedFindings(unittest.TestCase):
|
||||
findings = rs.load_findings(path, ("data", "catalogs"))
|
||||
self.assertEqual([f["subject"] for f in findings], ["dolphin-sys"])
|
||||
|
||||
def test_dry_run_json_prints_the_plan_as_json(self):
|
||||
"""--dry-run --json printed the text plan, and a caller parsing it
|
||||
as JSON failed on the first line."""
|
||||
import json # noqa: PLC0415
|
||||
import subprocess # noqa: PLC0415
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory:
|
||||
path = Path(directory) / "freshness.json"
|
||||
path.write_text(json.dumps([
|
||||
finding("catalogs", "mame recipes"), finding("coreinfo", "anybor"),
|
||||
]), encoding="utf-8")
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "scripts/refresh_stale.py", "--findings", str(path),
|
||||
"--dry-run", "--json"],
|
||||
cwd=REPO_ROOT, capture_output=True, text=True, check=False, timeout=120,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 0, proc.stderr)
|
||||
plan = json.loads(proc.stdout)
|
||||
self.assertEqual([(j["area"], j["subject"]) for j in plan["planned"]],
|
||||
[("catalogs", "mame recipes")])
|
||||
self.assertEqual([f["subject"] for f in plan["surfaced"]], ["anybor"])
|
||||
|
||||
def test_every_area_check_freshness_reports_is_known(self):
|
||||
"""romfolders was added to check_freshness and not here: its rows
|
||||
were dropped from a saved report without a word, and --only
|
||||
romfolders was refused."""
|
||||
import check_freshness # noqa: PLC0415
|
||||
|
||||
self.assertEqual(set(check_freshness.AREAS), set(rs.AUTO_AREAS + rs.MANUAL_AREAS))
|
||||
jobs, surfaced, _ = rs.plan_jobs([finding("romfolders", "muos")], REGISTRY, {})
|
||||
self.assertEqual((jobs, [f["subject"] for f in surfaced]), ([], ["muos"]))
|
||||
|
||||
def test_a_report_that_is_not_a_list_is_refused(self):
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory:
|
||||
path = Path(directory) / "freshness.json"
|
||||
|
||||
@@ -120,5 +120,31 @@ class DataRootIsKeyedBySystem(unittest.TestCase):
|
||||
self.assertTrue(self._errors({}))
|
||||
|
||||
|
||||
class WithoutJsonschema(unittest.TestCase):
|
||||
"""The documented command stopped on a bare ImportError traceback that
|
||||
named neither the install nor the format-nongpl extra."""
|
||||
|
||||
def test_the_command_names_the_install(self):
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
scratch = REPO_ROOT / "tmp" / "tests"
|
||||
scratch.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(dir=scratch) as directory:
|
||||
stub = Path(directory) / "jsonschema"
|
||||
stub.mkdir()
|
||||
(stub / "__init__.py").write_text(
|
||||
'raise ImportError("No module named jsonschema")\n', encoding="utf-8"
|
||||
)
|
||||
env = {**os.environ, "PYTHONPATH": directory}
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "scripts/validate_schemas.py", "--source-only"],
|
||||
capture_output=True, text=True, check=False, cwd=REPO_ROOT, env=env,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 1)
|
||||
self.assertNotIn("Traceback", proc.stderr)
|
||||
self.assertIn('pip install "jsonschema[format-nongpl]"', proc.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -724,7 +724,7 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
|
||||
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
|
||||
RuntimeError
|
||||
):
|
||||
emudeck_scraper.Scraper()._fetch_installed_emulators()
|
||||
emudeck_scraper.Scraper(checkbios_url="pinned")._fetch_installed_emulators("0" * 40)
|
||||
|
||||
def test_libretro_core_metadata_raises(self):
|
||||
"""libretro dropped every system name and manufacturer when the
|
||||
|
||||
@@ -509,6 +509,23 @@ class TestSelfContradictingDestinations(unittest.TestCase):
|
||||
self.assertEqual(len(collisions), 1)
|
||||
self.assertEqual(len(collisions[0].resolved), 2)
|
||||
|
||||
def test_the_line_names_each_system_and_the_file_packed(self):
|
||||
"""The line named two files and neither the system that declares
|
||||
each nor the one the pack ships: the reader went to the YAML."""
|
||||
config = {"systems": {
|
||||
"zeta": {"files": [{"name": "IPL.bin", "destination": "disk.rom",
|
||||
"md5": "m" * 32}]},
|
||||
"alpha": {"files": [{"name": "IPL.bin", "destination": "disk.rom",
|
||||
"md5": "n" * 32}]},
|
||||
}}
|
||||
collision = slots.find_collisions(config, REGIONS_DB)[0]
|
||||
line = slots.format_collision(collision)
|
||||
left, packed = collision.resolved
|
||||
# The builder walks the systems sorted: alpha's declaration ships.
|
||||
self.assertIn(f"{packed} (alpha) packed", line)
|
||||
self.assertIn(f"{left} (zeta) left out", line)
|
||||
self.assertEqual(collision.shipped, packed)
|
||||
|
||||
def test_one_archive_named_by_its_inner_roms_is_not_a_collision(self):
|
||||
# The documented zipped_file pattern: several md5s, one archive.
|
||||
config = self._config(
|
||||
|
||||
@@ -541,6 +541,59 @@ class TargetsReadThePlatformRevision(unittest.TestCase):
|
||||
self.assertTrue(steamos)
|
||||
self.assertTrue(all(u.endswith(f"?ref={pin}") for u in steamos), steamos)
|
||||
|
||||
def test_emudeck_platform_lists_its_installers_at_the_pin(self):
|
||||
"""cores: was read on master while launchers: and the SteamOS target
|
||||
were read at the pin: the YAML described two revisions."""
|
||||
from scripts.scraper import emudeck_scraper
|
||||
|
||||
pin = "d" * 40
|
||||
seen: list[str] = []
|
||||
|
||||
class _Body:
|
||||
def __init__(self, url):
|
||||
seen.append(url)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *_exc):
|
||||
return False
|
||||
|
||||
def read(self):
|
||||
return json.dumps([{"name": "emuDeckRMG.sh"}]).encode()
|
||||
|
||||
with mock.patch("urllib.request.urlopen", lambda req, **_kw: _Body(req.full_url)):
|
||||
cores = emudeck_scraper.Scraper(checkbios_url="pinned")._fetch_installed_emulators(pin)
|
||||
self.assertEqual(cores, ["mupen64plus_next"])
|
||||
self.assertEqual(len(seen), 1)
|
||||
self.assertTrue(seen[0].endswith(f"?ref={pin}"), seen)
|
||||
|
||||
|
||||
class EmuDeckScriptNamesHaveOneRule(unittest.TestCase):
|
||||
"""The target scraper kept its own copy of the EmuScripts-to-profile
|
||||
table: it published emudeck-we's template skeleton as a core, and a
|
||||
rename added to one copy only made --target filter that core out."""
|
||||
|
||||
def test_the_target_scraper_names_scripts_as_the_platform_does(self):
|
||||
from scripts.scraper.emudeck_launchers import emulator_of_script
|
||||
|
||||
listing = [
|
||||
"emuDeckRMG.sh",
|
||||
"emuDeckPCSX2QT.ps1",
|
||||
"emuDeckTemplate.ps1",
|
||||
"emuDeckRetroArch.ps1",
|
||||
"RetroArch_maincfg.sh",
|
||||
"emuDeckXemu.ps1",
|
||||
]
|
||||
scraper = emudeck_targets_scraper.Scraper(revision="0" * 40)
|
||||
with mock.patch.object(
|
||||
emudeck_targets_scraper, "_list_emuscripts", return_value=listing
|
||||
), mock.patch.object(scraper, "_load_retroarch_cores", return_value=["mgba"]):
|
||||
cores = scraper._fetch_cores_for_target("unused", "Windows")
|
||||
standalone = {emulator_of_script(name) for name in listing} - {None, "retroarch"}
|
||||
self.assertEqual(standalone, {"mupen64plus_next", "pcsx2", "xemu"})
|
||||
self.assertEqual(cores, sorted(standalone | {"mgba"}))
|
||||
|
||||
|
||||
class HashScrapersRefuseAnUnknownVersion(unittest.TestCase):
|
||||
"""mame_hash_scraper wrote core_version "unknown" after a failed API call
|
||||
|
||||
@@ -60,6 +60,22 @@ class ATargetedModelIsItsOwnArtifact(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
def test_a_named_platform_without_the_target_is_refused(self):
|
||||
"""bizhawk --target switch printed "skipped", then Done., exit 0,
|
||||
and wrote no model: the diff after it failed instead."""
|
||||
repo = pathlib.Path(__file__).resolve().parent.parent
|
||||
with tempfile.TemporaryDirectory(dir=str(repo / "tmp")) as directory:
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "scripts/generate_truth.py", "--platform", "bizhawk",
|
||||
"--target", "switch", "--output-dir", directory],
|
||||
capture_output=True, check=False, text=True, cwd=str(repo), timeout=400,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 1, proc.stdout + proc.stderr)
|
||||
self.assertIn("bizhawk has no hardware targets", proc.stderr)
|
||||
self.assertNotIn("Done.", proc.stdout)
|
||||
self.assertEqual(list(pathlib.Path(directory).iterdir()), [])
|
||||
|
||||
|
||||
class ADiffThatComparedNothingFails(unittest.TestCase):
|
||||
"""diff_truth --all skipped every platform without a model and exited 0."""
|
||||
|
||||
|
||||
@@ -269,6 +269,29 @@ class HashRecognition(_Fixture):
|
||||
self.assertIn("no platform list or emulator profile declares this file", markdown)
|
||||
self.assertIn("which emulator reads it", markdown)
|
||||
|
||||
def test_a_zip_of_bios_files_is_read_member_by_member(self):
|
||||
"""A card's BIOS folder zipped to upload it was hashed as one file,
|
||||
and its contributor was asked where that dump came from."""
|
||||
import hashlib # noqa: PLC0415
|
||||
import zipfile # noqa: PLC0415
|
||||
|
||||
held, declared = b"HELD BIOS", b"DECLARED BIOS"
|
||||
with zipfile.ZipFile(self.tmp / "mybios.zip", "w") as archive:
|
||||
archive.writestr("scph5501.bin", held)
|
||||
archive.writestr("sub/declared.bin", declared)
|
||||
archive.writestr("other.bin", b"noise")
|
||||
db = {"files": {hashlib.sha1(held).hexdigest(): {"path": "bios/Sony/PS/scph5501.bin"}}}
|
||||
known = {**EMPTY_HASHES, "md5": {hashlib.md5(declared).hexdigest()}}
|
||||
result = validate_pr.validate_file("mybios.zip", db, known)
|
||||
markdown = result.to_markdown()
|
||||
self.assertEqual(result.outcome, "unknown")
|
||||
self.assertIn("unzipped, not the archive", markdown)
|
||||
self.assertIn("`scph5501.bin` already held at `bios/Sony/PS/scph5501.bin`", markdown)
|
||||
self.assertIn("`sub/declared.bin` declared and not held", markdown)
|
||||
self.assertIn("`other.bin` not recognised", markdown)
|
||||
self.assertNotIn("where the dump comes from", markdown)
|
||||
self.assertNotIn("Place it in", markdown)
|
||||
|
||||
def test_a_duplicate_of_a_known_file_is_reported(self):
|
||||
"""A copy of a held file passed, and was sent to the folder that
|
||||
already holds it."""
|
||||
@@ -522,6 +545,15 @@ class FlagsAreAppliedOrRefused(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 2)
|
||||
self.assertIn("not allowed with", result.stderr)
|
||||
|
||||
def test_a_failed_file_is_not_reported_new(self):
|
||||
"""A path that does not exist came out as "outcome": "new", and a
|
||||
reader listing new contributions announced a BIOS nobody sent."""
|
||||
import json # noqa: PLC0415
|
||||
|
||||
result = self._run("--json", "bios/nope.bin")
|
||||
report = json.loads(result.stdout)
|
||||
self.assertEqual([(r["passed"], r["outcome"]) for r in report], [(False, "failed")])
|
||||
|
||||
|
||||
|
||||
class AFileOutsideBiosIsToldWhereToGo(unittest.TestCase):
|
||||
|
||||
@@ -173,6 +173,23 @@ class TheDestinationsFlagNeedsAPack(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 2, result.stdout[-300:])
|
||||
self.assertIn("--destinations", result.stderr)
|
||||
|
||||
def test_the_lock_stack_is_not_rebound(self):
|
||||
"""The --destinations branch reused `held`, the ExitStack that holds
|
||||
the data directory locks, for its dict: a later enter_context in
|
||||
that mode raised AttributeError."""
|
||||
import ast
|
||||
|
||||
tree = ast.parse((REPO_ROOT / "scripts" / "verify.py").read_text(encoding="utf-8"))
|
||||
body = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == "_main")
|
||||
stack = body.args.args[0].arg
|
||||
rebound = [
|
||||
node.lineno for node in ast.walk(body)
|
||||
if isinstance(node, (ast.Assign, ast.AnnAssign, ast.AugAssign))
|
||||
for target in (node.targets if isinstance(node, ast.Assign) else [node.target])
|
||||
if isinstance(target, ast.Name) and target.id == stack
|
||||
]
|
||||
self.assertEqual(rebound, [])
|
||||
|
||||
|
||||
class EveryGapCountedIsNamed(unittest.TestCase):
|
||||
"""verify --platform batocera --verbose counted 3 optional core files and
|
||||
|
||||
Reference in new issue
Block a user