mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: point tests at the packs modules
This commit is contained in:
1 parent
f48b66b540
commit
74207e25fc
50 files changed
+321
-259
No files matched your search
+1
-1
@@ -55,4 +55,4 @@ def generator_sources() -> list[Path]:
|
||||
moved out of generate_site.py stays under the guards that read it."""
|
||||
scripts = REPO_ROOT / "scripts"
|
||||
return sorted({*scripts.glob("site*.py"), scripts / "generate_site.py",
|
||||
scripts / "packreadme.py"})
|
||||
scripts / "packs" / "readme.py"})
|
||||
@@ -0,0 +1,42 @@
|
||||
"""The source text of a script, read across the package modules that hold its code.
|
||||
|
||||
A test that reads a tool's code to hold an invariant (one decision function,
|
||||
no hand-built pack name) reads every module the tool's code lives in: a
|
||||
command keeps its options, the packages keep the rest.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
|
||||
|
||||
# Each command whose library code lives in packages, with those modules.
|
||||
COMMANDS = {
|
||||
"generate_pack.py": (
|
||||
"packs/archive.py", "packs/naming.py", "packs/scope.py", "packs/datatrees.py",
|
||||
"packs/platformpack.py", "packs/emulatorpack.py", "packs/md5pack.py", "packs/targets.py",
|
||||
"packs/manifestentry.py", "packs/manifestcores.py", "packs/standalone.py",
|
||||
"packs/manifest.py", "packs/finalize.py",
|
||||
),
|
||||
"verify.py": (
|
||||
"packs/verdicts.py", "packs/gaps.py", "packs/coverage.py", "packs/emulatorcheck.py",
|
||||
"packs/report.py",
|
||||
),
|
||||
"cross_reference.py": ("packs/crossref.py",),
|
||||
"slots.py": ("packs/slots.py", "resolve/collisions.py"),
|
||||
"validate_pr.py": ("resolve/review.py", "core/gitclone.py"),
|
||||
"refresh_data_dirs.py": ("packs/datadirs.py",),
|
||||
"split_pack.py": ("packs/parts.py",),
|
||||
"dedup.py": ("model/nodedup.py",),
|
||||
}
|
||||
|
||||
|
||||
def script_paths(name: str) -> tuple[Path, ...]:
|
||||
"""A script under scripts/, then the package modules that hold its code."""
|
||||
return tuple(SCRIPTS / n for n in (name, *COMMANDS.get(name, ())))
|
||||
|
||||
|
||||
def script_source(name: str) -> str:
|
||||
"""The text of a script and of the package modules that hold its code."""
|
||||
return "\n".join(path.read_text(encoding="utf-8") for path in script_paths(name))
|
||||
@@ -21,7 +21,6 @@ from pathlib import Path
|
||||
|
||||
from model.profiles import load_emulator_profiles, _emulator_profiles_cache
|
||||
from resolve.localfile import resolve_local_file
|
||||
import generate_pack as builder
|
||||
from packs import extras as packextras
|
||||
|
||||
SIZE = 1024
|
||||
@@ -99,7 +98,7 @@ class AgnosticScanStaysInItsTree(unittest.TestCase):
|
||||
return load_emulator_profiles(str(self.root / "emulators"))
|
||||
|
||||
def _scan(self, profiles):
|
||||
extras = builder._collect_emulator_extras(
|
||||
extras = packextras._collect_emulator_extras(
|
||||
self.config, str(self.root / "emulators"), self.db, set(), "",
|
||||
profiles,
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ the slot missing and the manifest omitted it.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import re
|
||||
import tempfile
|
||||
@@ -45,8 +46,8 @@ class AgnosticSubstitute(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_every_reader_calls_it_behind_the_existence_gate(self):
|
||||
builder = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
verify = (REPO_ROOT / "scripts" / "verify.py").read_text(encoding="utf-8")
|
||||
builder = script_source("generate_pack.py")
|
||||
verify = script_source("verify.py")
|
||||
self.assertEqual(builder.count("agnostic_substitute(file_entry, sys_id"), 2)
|
||||
self.assertEqual(verify.count("agnostic_substitute(file_entry, sys_id"), 1)
|
||||
for source in (builder, verify):
|
||||
|
||||
@@ -8,6 +8,7 @@ seven of the eight members Batocera checks were missing.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
@@ -23,7 +24,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
class PreferredArchive(unittest.TestCase):
|
||||
def test_the_archive_most_declarations_accept_wins(self):
|
||||
import generate_pack
|
||||
from resolve import packfiles
|
||||
|
||||
roms = {f"r{i}.bin": bytes([i]) * 32 for i in range(3)}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -55,10 +56,10 @@ class PreferredArchive(unittest.TestCase):
|
||||
for name, md5 in member_md5.items()
|
||||
]
|
||||
systems = {"s": {"files": declarations}}
|
||||
preferred = generate_pack._preferred_entries(
|
||||
preferred = packfiles.preferred_entries(
|
||||
systems, db, "bios", "", False, {}, True)
|
||||
chosen = next(fe for fe in declarations if id(fe) == preferred["set.zip"])
|
||||
path, _status = generate_pack.resolve_file(chosen, db, "bios", {}, offline=True)
|
||||
path, _status = packfiles.resolve_file(chosen, db, "bios", {}, offline=True)
|
||||
self.assertEqual(path, "bios/b/set.zip")
|
||||
|
||||
|
||||
@@ -70,9 +71,9 @@ class OneWinnerRuleForEveryReader(unittest.TestCase):
|
||||
def test_the_rule_reads_no_data_directory(self):
|
||||
import inspect
|
||||
|
||||
import generate_pack
|
||||
from resolve import packfiles
|
||||
|
||||
parameters = inspect.signature(generate_pack._preferred_entries).parameters
|
||||
parameters = inspect.signature(packfiles.preferred_entries).parameters
|
||||
self.assertFalse([name for name in parameters if "registry" in name])
|
||||
|
||||
|
||||
@@ -215,7 +216,7 @@ class TheArchiveHoldingTheCoreMembers(unittest.TestCase):
|
||||
|
||||
def test_verify_and_the_pack_read_one_entry(self):
|
||||
for module in ("verify.py", "generate_pack.py"):
|
||||
source = (REPO_ROOT / "scripts" / module).read_text()
|
||||
source = script_source(module)
|
||||
with self.subTest(module=module):
|
||||
self.assertIn("archive_entry(", source)
|
||||
self.assertNotIn('{"name": archive', source)
|
||||
@@ -451,9 +452,9 @@ class AnArchiveRankedByWhatItHolds(unittest.TestCase):
|
||||
"hod2bios.zip", "dc/hod2bios.zip")
|
||||
self.assertEqual(extra["contents"], contents)
|
||||
# The second pass builds its extra from the profile entry itself.
|
||||
source = (REPO_ROOT / "scripts" / "packextras.py").read_text()
|
||||
source = (REPO_ROOT / "scripts" / "packs" / "extras.py").read_text()
|
||||
self.assertEqual(source.count('extra["contents"] = '), 2)
|
||||
report = (REPO_ROOT / "scripts" / "verify.py").read_text()
|
||||
report = script_source("verify.py")
|
||||
self.assertIn('entry["contents"] = f["contents"]', report)
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ path in bios/: a scan running beside the copy hashed the truncated file.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import os
|
||||
import sys
|
||||
@@ -56,10 +57,10 @@ class EveryWriterGoesThroughIt(unittest.TestCase):
|
||||
("release_record.py", "write_text_atomic("),
|
||||
("restore_large_files.py", "copy_file_atomic("),
|
||||
):
|
||||
source = (scripts / name).read_text(encoding="utf-8")
|
||||
source = script_source(name)
|
||||
with self.subTest(script=name):
|
||||
self.assertIn(helper, source)
|
||||
pack = (scripts / "generate_pack.py").read_text(encoding="utf-8")
|
||||
pack = script_source("generate_pack.py")
|
||||
self.assertNotIn('with open(path, "w") as f:\n f.write(new_json)', pack)
|
||||
self.assertNotIn("json.dump(result, f", pack)
|
||||
self.assertNotIn("args.output.write_text(", (scripts / "release_record.py").read_text())
|
||||
@@ -312,7 +313,7 @@ class ATerminatedBuildLeavesNoScratch(unittest.TestCase):
|
||||
"import sys, time\n"
|
||||
"sys.path.insert(0, 'scripts')\n"
|
||||
"from core.cli import run_cli\n"
|
||||
"from generate_pack import _writing_pack\n"
|
||||
"from packs.archive import _writing_pack\n"
|
||||
"def main():\n"
|
||||
" with _writing_pack(sys.argv[1]) as zf:\n"
|
||||
" zf.writestr('a.bin', b'x')\n"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import ast
|
||||
import contextlib
|
||||
@@ -569,7 +570,7 @@ class VerboseAppliesToJson(unittest.TestCase):
|
||||
self.assertIn("ok", {d["status"] for d in verbose["details"]})
|
||||
|
||||
def test_every_json_branch_reads_the_flag(self):
|
||||
source = (ROOT / "scripts" / "verify.py").read_text()
|
||||
source = script_source("verify.py")
|
||||
self.assertEqual(source.count("_json_details("), 4)
|
||||
self.assertNotIn('if d["status"] != Status.OK\n ]', source)
|
||||
|
||||
@@ -651,7 +652,7 @@ class APackIsSwappedInWhole(unittest.TestCase):
|
||||
self.assertEqual(sorted(p.name for p in directory.iterdir()), ["Pack.zip"])
|
||||
|
||||
def test_no_pack_is_opened_on_its_final_name(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text()
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn('ZipFile(zip_path, "w"', source)
|
||||
|
||||
|
||||
@@ -1042,7 +1043,7 @@ class FaqRegressions(unittest.TestCase):
|
||||
)
|
||||
self.assertIn(
|
||||
'result["discrepancy"]',
|
||||
(ROOT / "scripts" / "verify.py").read_text(encoding="utf-8"),
|
||||
script_source("verify.py"),
|
||||
"verify.py no longer raises the discrepancy the FAQ advertises",
|
||||
)
|
||||
|
||||
@@ -1528,7 +1529,7 @@ class OneBaselineVerdict(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_the_builder_and_the_manifest_read_the_same_rules(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
tree = ast.parse(source)
|
||||
for name in ("generate_pack", "generate_manifest"):
|
||||
function = next(
|
||||
@@ -1547,8 +1548,8 @@ class OneBaselineVerdict(unittest.TestCase):
|
||||
gives: a gitignored file absent from bios/ read as missing in verify
|
||||
while the pack shipped its cached release asset."""
|
||||
for module, name in (("verify.py", "_resolve_for_platform"),
|
||||
("packextras.py", "_ships")):
|
||||
source = (ROOT / "scripts" / module).read_text(encoding="utf-8")
|
||||
("packs/extras.py", "_ships")):
|
||||
source = script_source(module)
|
||||
function = next(
|
||||
node for node in ast.parse(source).body
|
||||
if isinstance(node, ast.FunctionDef) and node.name == name
|
||||
@@ -3385,11 +3386,11 @@ class APackNameFitsAFileName(unittest.TestCase):
|
||||
def test_two_hash_lists_get_two_names(self):
|
||||
"""--from-md5 named its pack after the context only: a second list
|
||||
overwrote the first pack in the same directory."""
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertIn('_Custom_{selection}', source)
|
||||
|
||||
def test_the_system_pack_names_itself(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertIn("pack_name=final_name", source)
|
||||
|
||||
|
||||
@@ -3400,7 +3401,7 @@ class AGroupPackIsWrittenUnderItsOwnName(unittest.TestCase):
|
||||
on Windows."""
|
||||
|
||||
def test_no_pack_is_renamed_after_its_build(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn("os.rename(", source)
|
||||
self.assertIn("pack_name=group_name", source)
|
||||
|
||||
@@ -3634,7 +3635,7 @@ class GeneratedModelsAreWrittenWhole(unittest.TestCase):
|
||||
|
||||
def test_both_writers_replace_their_file_atomically(self):
|
||||
for module in ("generate_truth.py", "dedup.py"):
|
||||
source = (ROOT / "scripts" / module).read_text(encoding="utf-8")
|
||||
source = script_source(module)
|
||||
with self.subTest(module=module):
|
||||
self.assertIn("write_text_atomic(", source)
|
||||
self.assertNotIn('open(out_path, "w")', source)
|
||||
@@ -3677,7 +3678,7 @@ class APackNoteBesideItsSlotIsANote(unittest.TestCase):
|
||||
self.assertTrue(result[0], result)
|
||||
|
||||
def test_verify_reads_the_rule_where_it_is_defined(self):
|
||||
source = (ROOT / "scripts" / "verify.py").read_text(encoding="utf-8")
|
||||
source = script_source("verify.py")
|
||||
self.assertNotIn("from generate_pack import _preferred_entries", source)
|
||||
|
||||
|
||||
@@ -3709,7 +3710,7 @@ class AnArchiveShipsWholeUnderARegion(unittest.TestCase):
|
||||
required changed, while the emulator pack ships the archive whole."""
|
||||
|
||||
def test_verify_filters_loose_files_only(self):
|
||||
source = (ROOT / "scripts" / "verify.py").read_text(encoding="utf-8")
|
||||
source = script_source("verify.py")
|
||||
self.assertIn(
|
||||
'if fe.get("archive")\n or _resolve_destination(fe, standalone) not in region_drops',
|
||||
source,
|
||||
@@ -3722,7 +3723,7 @@ class APathConflictKeepsTheMainVerdict(unittest.TestCase):
|
||||
counted excluded while verify counted it OK."""
|
||||
|
||||
def test_the_branch_reads_baseline_verdict(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
branch = source[source.index("Content ships under the conflicting shape"):]
|
||||
branch = branch[: branch.index("storage = file_entry.get")]
|
||||
self.assertIn("baseline_verdict(", branch)
|
||||
@@ -4052,7 +4053,7 @@ class AnAcceptedVersionIsNoCoreDiscrepancy(unittest.TestCase):
|
||||
self._extra(), str(held), {"eduke32": profile}))
|
||||
|
||||
def test_the_pack_consults_the_alternatives(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text()
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertRegex(source, r'status == "hash_mismatch" and not _matches_an_alternative\(')
|
||||
|
||||
|
||||
@@ -4415,8 +4416,8 @@ class ADataDirectoryIsHeldWhileRead(unittest.TestCase):
|
||||
fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
|
||||
def test_both_entry_points_hold_the_trees(self):
|
||||
pack = (ROOT / "scripts" / "generate_pack.py").read_text()
|
||||
verify_src = (ROOT / "scripts" / "verify.py").read_text()
|
||||
pack = script_source("generate_pack.py")
|
||||
verify_src = script_source("verify.py")
|
||||
self.assertIn("hold_data_dirs(held,", verify_src)
|
||||
refresh = pack.index("results = refresh_all(")
|
||||
self.assertIn("hold_data_dirs(held, data_registry)", pack[refresh:])
|
||||
@@ -4424,7 +4425,7 @@ class ADataDirectoryIsHeldWhileRead(unittest.TestCase):
|
||||
def test_verify_packs_alone_holds_the_trees(self):
|
||||
# --verify-packs returned before the hold and resolved core files
|
||||
# against data/ while a refresh could swap a tree.
|
||||
pack = (ROOT / "scripts" / "generate_pack.py").read_text()
|
||||
pack = script_source("generate_pack.py")
|
||||
branch = pack.index("if args.verify_packs and not args.all_variants:")
|
||||
run = pack.index("_run_verify_packs(args)", branch)
|
||||
self.assertIn("hold_data_dirs(held,", pack[branch:run])
|
||||
@@ -4447,7 +4448,7 @@ class EachRootReadsItsOwnRegistry(unittest.TestCase):
|
||||
|
||||
def test_one_parser_reads_the_registry(self):
|
||||
for module in ("generate_pack.py", "generate_db.py"):
|
||||
source = (ROOT / "scripts" / module).read_text()
|
||||
source = script_source(module)
|
||||
with self.subTest(module=module):
|
||||
self.assertIn("load_registered_paths", source)
|
||||
self.assertNotIn('startswith("bios/")\n }', source)
|
||||
@@ -4792,7 +4793,7 @@ class VerifyPacksSaysWhatItExcluded(unittest.TestCase):
|
||||
exclusions (352/353 shown as OK with no reason) and printed 5 errors."""
|
||||
|
||||
def test_the_result_is_unpacked_whole_and_every_error_printed(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text()
|
||||
source = script_source("generate_pack.py")
|
||||
body = source[source.index("def _run_verify_packs"):]
|
||||
body = body[:body.index("\ndef ")]
|
||||
self.assertIn("bl_excluded, bl_absent) = result", body)
|
||||
@@ -4939,7 +4940,6 @@ class AManifestHashesAFileOnce(unittest.TestCase):
|
||||
calls for 15 011 files, 163 s of a 218 s step."""
|
||||
|
||||
def test_verified_hashes_are_reused(self):
|
||||
from scripts import generate_pack
|
||||
from scripts.packs import manifestentry
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp:
|
||||
@@ -4948,13 +4948,13 @@ class AManifestHashesAFileOnce(unittest.TestCase):
|
||||
sha1 = hashlib.sha1(b"abc").hexdigest()
|
||||
db = {"files": {sha1: {"path": str(path)}}}
|
||||
calls = []
|
||||
real = generate_pack.compute_hashes
|
||||
real = manifestentry.compute_hashes
|
||||
|
||||
def counting(file_path, algorithms=None):
|
||||
calls.append(algorithms)
|
||||
return real(file_path, algorithms)
|
||||
|
||||
with mock.patch.object(generate_pack, "compute_hashes", counting):
|
||||
with mock.patch.object(manifestentry, "compute_hashes", counting):
|
||||
first = manifestentry._stable_hashes(str(path), db)
|
||||
second = manifestentry._stable_hashes(str(path), db)
|
||||
self.assertEqual(first, second)
|
||||
@@ -5456,11 +5456,11 @@ class BundledFilesAreNotToSource(unittest.TestCase):
|
||||
"data_directories": [{"ref": "dolphin-sys", "installed_on": ["lakka"]}]}))
|
||||
self.assertEqual(installed_data_refs("lakka", tmp), frozenset({"dolphin-sys"}))
|
||||
self.assertEqual(installed_data_refs("retroarch", tmp), frozenset())
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertIn("if ref_key in installed_data_refs(platform_name):", source)
|
||||
|
||||
def test_the_pack_builder_skips_it(self):
|
||||
source = (ROOT / "scripts" / "packextras.py").read_text(encoding="utf-8")
|
||||
source = (ROOT / "scripts" / "packs" / "extras.py").read_text(encoding="utf-8")
|
||||
self.assertIn('if u.get("bundled"):', source)
|
||||
|
||||
|
||||
@@ -5928,8 +5928,8 @@ class ZippedFileMd5IsParsedOnce(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_the_three_sites_share_the_parser(self):
|
||||
for module in ("resolve/validation.py", "packverify.py", "verify.py"):
|
||||
source = (ROOT / "scripts" / module).read_text()
|
||||
for module in ("resolve/validation.py", "packs/integrity.py", "verify.py"):
|
||||
source = script_source(module)
|
||||
self.assertIn("parse_md5_list(", source, module)
|
||||
|
||||
|
||||
@@ -6209,7 +6209,7 @@ class AFailedVerificationIsAnError(unittest.TestCase):
|
||||
exit 1: a warning that fails the run, naming no pack."""
|
||||
|
||||
def test_the_last_line_names_the_packs(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text()
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn("WARNING: some packs have verification errors", source)
|
||||
self.assertIn('print(f"ERROR: packs failed verification: {\', \'.join(failing)}", file=sys.stderr)', source)
|
||||
|
||||
@@ -7088,7 +7088,7 @@ class AFileTheLauncherNeverOpens(unittest.TestCase):
|
||||
self.assertEqual(deliverable([entry], True, "batocera"), [entry])
|
||||
|
||||
def test_the_gap_report_reads_it(self):
|
||||
source = (ROOT / "scripts" / "verify.py").read_text(encoding="utf-8")
|
||||
source = script_source("verify.py")
|
||||
self.assertIn('unread_on(f, config.get("_key", ""))', source)
|
||||
|
||||
|
||||
@@ -7130,7 +7130,7 @@ class RequiredOnlyReachesDataDirectories(unittest.TestCase):
|
||||
self.assertEqual(self._members(True), ["a/needed.bin"])
|
||||
|
||||
def test_every_tree_walk_reads_the_flag(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
# The pack's walk and the manifest's, which records the flag for
|
||||
# install.py --required-only.
|
||||
self.assertEqual(source.count('if required_only and dd.get("required") is False:'), 1)
|
||||
@@ -7282,7 +7282,7 @@ class ErrorsGoToStderr(unittest.TestCase):
|
||||
|
||||
def test_no_error_line_is_printed_to_stdout(self):
|
||||
for script in ("generate_pack.py", "pipeline.py"):
|
||||
tree = ast.parse((ROOT / "scripts" / script).read_text(encoding="utf-8"))
|
||||
tree = ast.parse(script_source(script))
|
||||
seen = 0
|
||||
for node in ast.walk(tree):
|
||||
if not (isinstance(node, ast.Call) and getattr(node.func, "id", "") == "print"
|
||||
@@ -7502,7 +7502,7 @@ class ExternalDownloadsFollowTheRunPolicy(unittest.TestCase):
|
||||
self.assertFalse(target.exists())
|
||||
|
||||
def test_scratch_files_stay_in_the_repository(self):
|
||||
source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn("def download_external", source)
|
||||
self.assertNotIn("urlopen", source)
|
||||
for call in re.findall(r"NamedTemporaryFile\(([^)]*)\)", source):
|
||||
|
||||
@@ -87,14 +87,14 @@ class ThePackReadmeNamesTheSpellingsItLeavesOut(unittest.TestCase):
|
||||
}}}))
|
||||
_platform_config_cache.clear()
|
||||
texts: dict[str, str] = {}
|
||||
real = archive._write_generated_member
|
||||
real = platformpack._write_generated_member
|
||||
|
||||
def capture(zf, arcname, text):
|
||||
texts[arcname] = text
|
||||
return real(zf, arcname, text)
|
||||
|
||||
archive._write_generated_member = capture
|
||||
self.addCleanup(setattr, self.gp, "_write_generated_member", real)
|
||||
platformpack._write_generated_member = capture
|
||||
self.addCleanup(setattr, platformpack, "_write_generated_member", real)
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
platformpack.generate_pack(
|
||||
"p", "platforms", self.db, "bios", "", emulators_dir="emulators",
|
||||
|
||||
@@ -22,7 +22,6 @@ from pathlib import Path
|
||||
from model.profiles import _emulator_profiles_cache, load_emulator_profiles
|
||||
from resolve.content import content_fits, size_fits, _masked_sha1_verdict
|
||||
from resolve.localfile import resolve_local_file
|
||||
import generate_pack as builder
|
||||
from packs import extras as packextras
|
||||
from core.romdir import romdir_accepts, walk
|
||||
from resolve.validation import _build_validation_index, check_file_validation
|
||||
@@ -280,7 +279,7 @@ class ScannerVerifyManifestAgree(unittest.TestCase):
|
||||
"SCPH-70004.nvm", "246C.mec"})
|
||||
|
||||
def test_platform_pack_and_manifest_scan(self):
|
||||
extras = builder._collect_emulator_extras(
|
||||
extras = packextras._collect_emulator_extras(
|
||||
self.config, str(self.root / "emulators"), self.db, set(), "", self.profiles,
|
||||
)
|
||||
placed = {e["name"] for e in extras if e.get("source_profile") == "demo"}
|
||||
|
||||
@@ -9,6 +9,7 @@ frontend sees a file at the path. verify kept it MISSING, so the pack said
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import hashlib
|
||||
import contextlib
|
||||
@@ -366,7 +367,7 @@ class TheManifestResolvesLikeThePack(unittest.TestCase):
|
||||
def test_every_platform_resolution_reads_the_data_directories(self):
|
||||
import ast
|
||||
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
missing = []
|
||||
for fn in ast.walk(ast.parse(source)):
|
||||
if not isinstance(fn, ast.FunctionDef) or fn.name == "generate_md5_pack":
|
||||
|
||||
@@ -10,6 +10,7 @@ a directory called ROM).
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -155,7 +156,7 @@ class PlatformScopedEntries(unittest.TestCase):
|
||||
def test_the_report_reads_the_shared_rules(self):
|
||||
"""One rule, one function: a local `bool(f.get("bundled"))` answered
|
||||
differently from verify for every installed_on/not_bundled_on entry."""
|
||||
source = (REPO_ROOT / "scripts" / "cross_reference.py").read_text()
|
||||
source = script_source("cross_reference.py")
|
||||
self.assertNotIn('bool(f.get("bundled"))', source)
|
||||
self.assertIn("installed_with_emulator(f, platform)", source)
|
||||
self.assertIn("unread_on(f, platform)", source)
|
||||
|
||||
@@ -384,7 +384,7 @@ class TestPackDeterminism(unittest.TestCase):
|
||||
|
||||
def test_injected_manifest_is_pinned_to_the_database(self):
|
||||
from scripts.packs.finalize import inject_manifest
|
||||
from scripts.generate_pack import verify_pack
|
||||
from scripts.packs.integrity import verify_pack
|
||||
|
||||
pack = self._build("out1")
|
||||
ok, manifest = verify_pack(str(pack), self.db)
|
||||
@@ -407,7 +407,6 @@ class ManifestInjectionIsAtomic(unittest.TestCase):
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
|
||||
from scripts.packs import archive as packs_archive
|
||||
from scripts.packs import finalize
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as d:
|
||||
@@ -422,7 +421,7 @@ class ManifestInjectionIsAtomic(unittest.TestCase):
|
||||
zf.fp.flush()
|
||||
raise KeyboardInterrupt
|
||||
|
||||
with mock.patch.object(packs_archive, "_write_generated_member", die), \
|
||||
with mock.patch.object(finalize, "_write_generated_member", die), \
|
||||
self.assertRaises(KeyboardInterrupt):
|
||||
finalize.inject_manifest(str(pack), {"files": ["x"] * 2000})
|
||||
self.assertEqual(pack.read_bytes(), before)
|
||||
|
||||
@@ -8,6 +8,7 @@ code moves, and nothing else notices.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import ast
|
||||
import hashlib
|
||||
@@ -1982,7 +1983,6 @@ class NoTextClaimsAScheduledScrape(unittest.TestCase):
|
||||
`schedule:`."""
|
||||
|
||||
def test_no_text_ties_the_registry_to_automation(self):
|
||||
import generate_pack
|
||||
import generate_readme
|
||||
import generate_site
|
||||
import list_platforms
|
||||
@@ -1991,7 +1991,7 @@ class NoTextClaimsAScheduledScrape(unittest.TestCase):
|
||||
"adding-a-platform.md": (WIKI / "adding-a-platform.md").read_text(encoding="utf-8"),
|
||||
"generate_readme": inspect.getsource(generate_readme),
|
||||
"generate_site": inspect.getsource(generate_site),
|
||||
"generate_pack": inspect.getsource(generate_pack),
|
||||
"generate_pack": script_source("generate_pack.py"),
|
||||
"list_platforms": inspect.getsource(list_platforms),
|
||||
"_guides.yml": (ROOT / "platforms" / "_guides.yml").read_text(encoding="utf-8"),
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ tool prints, and a size is the one the release record holds.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import ast
|
||||
import contextlib
|
||||
@@ -342,7 +343,7 @@ class ShownOutputIsPrintedOutput(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_the_shapes_are_verify_output(self):
|
||||
source = _read("scripts/verify.py")
|
||||
source = script_source("verify.py")
|
||||
for _pattern, literal in self.SHAPES:
|
||||
if literal:
|
||||
with self.subTest(literal=literal):
|
||||
|
||||
+66
-64
@@ -18,6 +18,7 @@ Covers:
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import contextlib
|
||||
import hashlib
|
||||
@@ -1126,7 +1127,7 @@ class TestE2E(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_60_storage_external(self):
|
||||
from generate_pack import resolve_file
|
||||
from resolve.packfiles import resolve_file
|
||||
|
||||
entry = {"name": "large.pup", "storage": "external"}
|
||||
path, status = resolve_file(entry, self.db, self.bios_dir)
|
||||
@@ -1134,7 +1135,7 @@ class TestE2E(unittest.TestCase):
|
||||
self.assertEqual(status, "external")
|
||||
|
||||
def test_61_storage_user_provided(self):
|
||||
from generate_pack import resolve_file
|
||||
from resolve.packfiles import resolve_file
|
||||
|
||||
entry = {"name": "user.bin", "storage": "user_provided"}
|
||||
path, status = resolve_file(entry, self.db, self.bios_dir)
|
||||
@@ -2266,7 +2267,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_130_required_only_excludes_optional(self):
|
||||
"""--required-only excludes files with required: false from pack."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_reqonly")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -2315,7 +2316,7 @@ class TestE2E(unittest.TestCase):
|
||||
import contextlib
|
||||
import io
|
||||
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_mismatch")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -2358,7 +2359,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_131_required_only_keeps_default_required(self):
|
||||
"""--required-only keeps files with no required field (default = required)."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_reqdef")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -2392,7 +2393,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_132_platform_system_filter(self):
|
||||
"""--platform + --system filters systems within a platform pack."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_sysfilter")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -2549,7 +2550,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from model.profiles import load_emulator_profiles
|
||||
from generate_pack import generate_split_packs
|
||||
from packs.platformpack import generate_split_packs
|
||||
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
emu_profiles = load_emulator_profiles(emu_dir)
|
||||
@@ -2606,7 +2607,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_137_group_systems_by_manufacturer(self):
|
||||
"""_group_systems_by_manufacturer groups correctly."""
|
||||
from generate_pack import _group_systems_by_manufacturer
|
||||
from packs.platformpack import _group_systems_by_manufacturer
|
||||
|
||||
systems = {
|
||||
"sony-playstation": {"files": [{"name": "a.bin"}]},
|
||||
@@ -2775,7 +2776,7 @@ class TestE2E(unittest.TestCase):
|
||||
yaml.dump(plat_cfg, f)
|
||||
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from generate_pack import generate_md5_pack
|
||||
from packs.md5pack import generate_md5_pack
|
||||
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
|
||||
@@ -2825,7 +2826,7 @@ class TestE2E(unittest.TestCase):
|
||||
import io
|
||||
import tempfile
|
||||
|
||||
from generate_pack import generate_md5_pack
|
||||
from packs.md5pack import generate_md5_pack
|
||||
|
||||
db = {
|
||||
"files": {
|
||||
@@ -3069,7 +3070,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_157_path_conflict_helpers(self):
|
||||
"""_has_path_conflict detects file/directory naming collisions."""
|
||||
from generate_pack import _has_path_conflict, _register_path
|
||||
from packs.paths import _has_path_conflict, _register_path
|
||||
|
||||
seen_files: set[str] = set()
|
||||
seen_parents: set[str] = set()
|
||||
@@ -3104,7 +3105,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_158_pack_skips_file_directory_conflict(self):
|
||||
"""Pack generation skips entries that conflict with existing paths."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_conflict")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -3263,7 +3264,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_164_pack_extras_use_archive_name(self):
|
||||
"""Pack extras for archived files use archive name, not individual ROM."""
|
||||
from generate_pack import _collect_emulator_extras
|
||||
from packs.extras import _collect_emulator_extras
|
||||
|
||||
config = load_platform_config("test_existence", self.platforms_dir)
|
||||
profiles = load_emulator_profiles(self.emulators_dir)
|
||||
@@ -3285,7 +3286,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_165_pack_extras_multi_dest_cross_ref(self):
|
||||
"""Same file at different paths from two profiles produces both destinations."""
|
||||
from generate_pack import _collect_emulator_extras
|
||||
from packs.extras import _collect_emulator_extras
|
||||
|
||||
config = load_platform_config("test_existence", self.platforms_dir)
|
||||
profiles = load_emulator_profiles(self.emulators_dir)
|
||||
@@ -3305,7 +3306,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_166_pack_extras_multi_dest_platform_declared(self):
|
||||
"""Profile with path different from platform destination adds alternative."""
|
||||
from generate_pack import _collect_emulator_extras
|
||||
from packs.extras import _collect_emulator_extras
|
||||
|
||||
config = load_platform_config("test_existence", self.platforms_dir)
|
||||
profiles = load_emulator_profiles(self.emulators_dir)
|
||||
@@ -3640,7 +3641,7 @@ class TestE2E(unittest.TestCase):
|
||||
required set, and --all-variants wrote three manifests that duplicated
|
||||
their non-required twins.
|
||||
"""
|
||||
from generate_pack import generate_manifest
|
||||
from packs.manifest import generate_manifest
|
||||
|
||||
registry_path = os.path.join(self.platforms_dir, "_test_registry.yml")
|
||||
with open(registry_path, "w") as fh:
|
||||
@@ -3672,7 +3673,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_91_generate_manifest(self):
|
||||
"""generate_manifest returns valid manifest dict with expected fields."""
|
||||
from generate_pack import generate_manifest
|
||||
from packs.manifest import generate_manifest
|
||||
|
||||
# Create a minimal registry file for the test
|
||||
registry_path = os.path.join(self.platforms_dir, "_test_registry.yml")
|
||||
@@ -3739,7 +3740,7 @@ class TestE2E(unittest.TestCase):
|
||||
than written with a stand-in or its parent's version.
|
||||
"""
|
||||
from model.platforms import _platform_config_cache
|
||||
from generate_pack import generate_manifest
|
||||
from packs.manifest import generate_manifest
|
||||
|
||||
registry_path = os.path.join(self.platforms_dir, "_test_registry_version.yml")
|
||||
with open(registry_path, "w") as fh:
|
||||
@@ -3780,7 +3781,7 @@ class TestE2E(unittest.TestCase):
|
||||
install.py builds its download URL from repo_path, so an upstream
|
||||
hash that resolves to nothing leaves the file unfetchable.
|
||||
"""
|
||||
from generate_pack import generate_manifest
|
||||
from packs.manifest import generate_manifest
|
||||
|
||||
registry_path = os.path.join(self.platforms_dir, "_test_registry2.yml")
|
||||
with open(registry_path, "w") as fh:
|
||||
@@ -3828,7 +3829,8 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_92_manifest_matches_zip(self):
|
||||
"""Manifest file destinations match ZIP contents (excluding metadata)."""
|
||||
from generate_pack import generate_manifest, generate_pack
|
||||
from packs.manifest import generate_manifest
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
registry_path = os.path.join(self.platforms_dir, "_test_registry.yml")
|
||||
registry_data = {
|
||||
@@ -4650,7 +4652,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_181_agnostic_extras_scan(self):
|
||||
"""Agnostic profiles add all matching DB files as extras."""
|
||||
from generate_pack import _collect_emulator_extras
|
||||
from packs.extras import _collect_emulator_extras
|
||||
|
||||
config = load_platform_config("test_existence", self.platforms_dir)
|
||||
profiles = load_emulator_profiles(self.emulators_dir)
|
||||
@@ -4673,7 +4675,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_182_agnostic_rename_readme(self):
|
||||
"""_build_agnostic_rename_readme generates correct text."""
|
||||
from generate_pack import _build_agnostic_rename_readme
|
||||
from packs.readme import _build_agnostic_rename_readme
|
||||
|
||||
result = _build_agnostic_rename_readme(
|
||||
"dsi_nand.bin",
|
||||
@@ -5033,7 +5035,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_201_collect_emulator_extras_include_all(self):
|
||||
"""include_all=True passes through to find_undeclared_files."""
|
||||
from generate_pack import _collect_emulator_extras
|
||||
from packs.extras import _collect_emulator_extras
|
||||
|
||||
config = self._load_config("test_existence")
|
||||
profiles = load_emulator_profiles(self.emulators_dir)
|
||||
@@ -5063,7 +5065,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_202_pack_source_platform(self):
|
||||
"""source='platform' skips core extras."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_platform")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -5083,7 +5085,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_203_pack_source_truth(self):
|
||||
"""source='truth' uses emulator profile files."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_truth")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -5103,7 +5105,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_204_pack_source_full_unchanged(self):
|
||||
"""source='full' (default) has no source tag in filename."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_full")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -5126,7 +5128,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_205_pack_source_platform_required(self):
|
||||
"""source='platform' + required_only=True."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_plat_req")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -5151,7 +5153,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_206_pack_source_truth_required(self):
|
||||
"""source='truth' + required_only=True."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_truth_req")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -5172,7 +5174,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_207_manifest_source(self):
|
||||
"""generate_manifest respects source param."""
|
||||
from generate_pack import generate_manifest
|
||||
from packs.manifest import generate_manifest
|
||||
|
||||
profiles = load_emulator_profiles(self.emulators_dir)
|
||||
registry_path = os.path.join(self.platforms_dir, "_registry.yml")
|
||||
@@ -5195,7 +5197,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_208_split_source_tag_in_dirname(self):
|
||||
"""generate_split_packs uses source tag in split directory name."""
|
||||
from generate_pack import generate_split_packs
|
||||
from packs.platformpack import generate_split_packs
|
||||
|
||||
output_dir = os.path.join(self.root, "split_src")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -5211,7 +5213,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_209_all_variants_generates_6_zips(self):
|
||||
"""All 6 source x required combinations produce unique ZIPs."""
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output_dir = os.path.join(self.root, "pack_allvar")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
@@ -5283,7 +5285,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
"""md5-declared ZIPs are copied unchanged, never rebuilt."""
|
||||
import tempfile
|
||||
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
plat_dir, bios_root, out_dir, db, h, hl = self._make_hash_zip_fixture(
|
||||
@@ -5303,7 +5305,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
import io
|
||||
import tempfile
|
||||
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
plat_dir, bios_root, out_dir, db, h, hl = self._make_hash_zip_fixture(
|
||||
@@ -5367,7 +5369,8 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
errors, while firmware the collection lacks stays one."""
|
||||
import tempfile
|
||||
|
||||
from generate_pack import generate_pack, verify_pack_against_platform
|
||||
from packs.platformpack import generate_pack
|
||||
from generate_pack import verify_pack_against_platform
|
||||
|
||||
profiles = {"eng": {"emulator": "Eng", "type": "game", "cores": ["eng"],
|
||||
"systems": ["arcade-sys"],
|
||||
@@ -5799,7 +5802,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
"""The manifest is deflated whichever injection path runs."""
|
||||
import json as _json
|
||||
|
||||
from generate_pack import inject_manifest
|
||||
from packs.finalize import inject_manifest
|
||||
|
||||
manifest = {"files": [{"path": f"f{i}.bin"} for i in range(200)]}
|
||||
raw = _json.dumps(manifest, indent=2, ensure_ascii=False)
|
||||
@@ -5876,7 +5879,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
yaml.safe_dump(config, fh)
|
||||
|
||||
def _region_pack(self, **kwargs) -> str:
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
self._create_region_fixtures()
|
||||
out = generate_pack(
|
||||
@@ -5954,7 +5957,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertIn("rgn_plain.bin", names)
|
||||
|
||||
def test_region_composes_with_split(self):
|
||||
from generate_pack import generate_split_packs
|
||||
from packs.platformpack import generate_split_packs
|
||||
|
||||
self._create_region_fixtures()
|
||||
paths = generate_split_packs(
|
||||
@@ -5975,7 +5978,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertNotIn("rgn_eu.bin", names)
|
||||
|
||||
def test_region_composes_with_split_and_target(self):
|
||||
from generate_pack import generate_split_packs
|
||||
from packs.platformpack import generate_split_packs
|
||||
|
||||
self._create_region_fixtures()
|
||||
paths = generate_split_packs(
|
||||
@@ -6000,7 +6003,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
)
|
||||
|
||||
def test_region_composes_with_manifest(self):
|
||||
from generate_pack import generate_manifest
|
||||
from packs.manifest import generate_manifest
|
||||
|
||||
self._create_region_fixtures()
|
||||
registry_path = os.path.join(self.platforms_dir, "_registry.yml")
|
||||
@@ -6023,7 +6026,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertNotIn("rgn_eu.bin", packed)
|
||||
|
||||
def test_manifest_without_region_keeps_every_variant(self):
|
||||
from generate_pack import generate_manifest
|
||||
from packs.manifest import generate_manifest
|
||||
|
||||
self._create_region_fixtures()
|
||||
registry_path = os.path.join(self.platforms_dir, "_registry.yml")
|
||||
@@ -6044,7 +6047,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertIn(expected, packed)
|
||||
|
||||
def test_region_composes_with_system_pack(self):
|
||||
from generate_pack import generate_system_pack
|
||||
from packs.emulatorpack import generate_system_pack
|
||||
|
||||
self._create_region_fixtures()
|
||||
os.makedirs(self.emulators_dir, exist_ok=True)
|
||||
@@ -6092,7 +6095,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertTrue(checked.issubset(packed), checked - packed)
|
||||
|
||||
def test_verify_emulator_region_matches_the_pack(self):
|
||||
from generate_pack import generate_emulator_pack
|
||||
from packs.emulatorpack import generate_emulator_pack
|
||||
from packs.emulatorcheck import verify_emulator
|
||||
|
||||
self._create_region_fixtures()
|
||||
@@ -6123,7 +6126,8 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
def test_every_narrowing_names_itself_and_says_so(self):
|
||||
"""A dimension that removes files must show in the pack name and in the
|
||||
README. Both are built from _narrowings, so this holds for any new one."""
|
||||
from generate_pack import _build_readme, _narrowings
|
||||
from packs.readme import _build_readme
|
||||
from packs.naming import _narrowings
|
||||
|
||||
dimensions = [
|
||||
{"source": "platform"},
|
||||
@@ -6317,7 +6321,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
import inspect
|
||||
|
||||
from packs import integrity as packverify
|
||||
from generate_pack import _narrows_contents, _narrowings
|
||||
from packs.naming import _narrows_contents, _narrowings
|
||||
|
||||
source = inspect.getsource(packverify.verify_pack_against_platform)
|
||||
self.assertIn(
|
||||
@@ -6347,7 +6351,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
def test_standalone_mode_names_itself(self):
|
||||
"""--emulator --standalone ships a different file set, and without a tag it
|
||||
overwrote the pack built without it."""
|
||||
from generate_pack import _narrowings
|
||||
from packs.naming import _narrowings
|
||||
|
||||
applied = _narrowings("full", None, None, False, False, standalone=True)
|
||||
self.assertEqual([tag for tag, _l in applied], ["_Standalone"])
|
||||
@@ -6355,11 +6359,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
def test_every_name_builder_uses_the_same_list(self):
|
||||
"""Four places name a pack or a manifest. None may assemble tags by
|
||||
hand: that is how --one-per-slot reached --split unnamed."""
|
||||
import inspect
|
||||
|
||||
import generate_pack
|
||||
|
||||
source = inspect.getsource(generate_pack)
|
||||
source = script_source("generate_pack.py")
|
||||
for hand_rolled in (
|
||||
'req_tag = "_Required"',
|
||||
'source_tag = {"platform": "_Platform"',
|
||||
@@ -6473,7 +6473,8 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertFalse(os.listdir(out) if os.path.isdir(out) else [])
|
||||
|
||||
def test_a_full_pack_is_not_announced_as_narrowed(self):
|
||||
from generate_pack import _build_readme, _narrowings
|
||||
from packs.readme import _build_readme
|
||||
from packs.naming import _narrowings
|
||||
|
||||
self.assertEqual(_narrowings("full", None, None, False, False), [])
|
||||
self.assertNotIn(
|
||||
@@ -6481,7 +6482,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
)
|
||||
|
||||
def test_system_filter_is_announced_too(self):
|
||||
from generate_pack import _build_readme
|
||||
from packs.readme import _build_readme
|
||||
|
||||
readme = _build_readme(
|
||||
"p", "P", "", 1, 1, system_filter=["sony-playstation"]
|
||||
@@ -6578,7 +6579,8 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
import inspect
|
||||
import typing
|
||||
|
||||
from generate_pack import generate_pack, verify_pack_against_platform
|
||||
from packs.platformpack import generate_pack
|
||||
from generate_pack import verify_pack_against_platform
|
||||
|
||||
self._create_region_fixtures()
|
||||
profiles = self._region_profiles()
|
||||
@@ -6601,7 +6603,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertEqual(len(result), len(annotated))
|
||||
|
||||
def test_narrowed_variants_skip_conformance(self):
|
||||
from generate_pack import _narrows_contents
|
||||
from packs.naming import _narrows_contents
|
||||
|
||||
for narrowed in (
|
||||
"EmuDeck_2.3.8_Required_BIOS_Pack.zip",
|
||||
@@ -6619,7 +6621,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertFalse(_narrows_contents(full), full)
|
||||
|
||||
def test_target_tag_formats_hardware_names(self):
|
||||
from generate_pack import _target_tag
|
||||
from packs.naming import _target_tag
|
||||
|
||||
self.assertEqual(_target_tag("switch"), "Switch")
|
||||
self.assertEqual(_target_tag("rpi4"), "Rpi4")
|
||||
@@ -6641,7 +6643,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertIn("Switch", name)
|
||||
|
||||
def test_readme_region_section_lists_fallback_systems(self):
|
||||
from generate_pack import _build_readme
|
||||
from packs.readme import _build_readme
|
||||
|
||||
text = _build_readme(
|
||||
"regionplat",
|
||||
@@ -6659,7 +6661,7 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertNotIn("All are included", text)
|
||||
|
||||
def test_readme_without_region_keeps_the_regional_note(self):
|
||||
from generate_pack import _build_readme
|
||||
from packs.readme import _build_readme
|
||||
|
||||
text = _build_readme("regionplat", "RegionPlat", "", 10, 2)
|
||||
self.assertNotIn("PACK TYPE: Region Filtered", text)
|
||||
@@ -6746,16 +6748,16 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
|
||||
def test_gap_analysis_resolves_renamed_mame_set(self):
|
||||
"""A renamed set is held under the name dedup kept, as verify reads it."""
|
||||
import cross_reference
|
||||
from packs import crossref
|
||||
|
||||
db = self._gap_db("v4bios.zip", "a" * 40, "465c4e1c")
|
||||
original = cross_reference.get_mame_clone_map
|
||||
cross_reference.get_mame_clone_map = lambda *_a: {"bctvidbs.zip": "v4bios.zip"}
|
||||
original = crossref.get_mame_clone_map
|
||||
crossref.get_mame_clone_map = lambda *_a: {"bctvidbs.zip": "v4bios.zip"}
|
||||
try:
|
||||
entry = {"name": "bctvidbs.zip", "required": True}
|
||||
self.assertEqual(self._gap_source(entry, db), "bios")
|
||||
finally:
|
||||
cross_reference.get_mame_clone_map = original
|
||||
crossref.get_mame_clone_map = original
|
||||
|
||||
|
||||
class StandaloneModeRequiresAStandaloneBuild(unittest.TestCase):
|
||||
@@ -6883,7 +6885,7 @@ class OneOfASearchList(unittest.TestCase):
|
||||
self.assertIn("1 required file(s) missing: none_a.bin", err.getvalue())
|
||||
|
||||
def test_pack_and_verify_agree(self):
|
||||
from generate_pack import generate_emulator_pack
|
||||
from packs.emulatorpack import generate_emulator_pack
|
||||
|
||||
result = self._verify()
|
||||
out = io.StringIO()
|
||||
@@ -7023,7 +7025,7 @@ class OneOfASearchList(unittest.TestCase):
|
||||
"""second.bin and third.bin are both held: a --required-only pack
|
||||
carries second.bin, the first the code reads among those held, and
|
||||
verify reports the same single file."""
|
||||
from generate_pack import generate_emulator_pack
|
||||
from packs.emulatorpack import generate_emulator_pack
|
||||
|
||||
result = verify_emulator(["seq"], "emulators", self.db,
|
||||
platforms_dir="platforms", required_only=True)
|
||||
@@ -7104,7 +7106,7 @@ class AnArchiveIsAMemberOfASet(unittest.TestCase):
|
||||
self.assertEqual(result["status_counts"].get("missing"), 1)
|
||||
|
||||
def test_required_only_carries_the_archive_the_code_reads_first(self):
|
||||
from generate_pack import generate_emulator_pack
|
||||
from packs.emulatorpack import generate_emulator_pack
|
||||
|
||||
self._fixture(held=True)
|
||||
full = verify_emulator(["stv"], "emulators", self.db, platforms_dir="platforms")
|
||||
|
||||
@@ -9,6 +9,7 @@ Galaksija ROM and a PS2 ROM2.BIN.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -54,8 +55,8 @@ class IdentityTravels(unittest.TestCase):
|
||||
self.assertEqual(item.get(field), ENTRY[field])
|
||||
|
||||
def test_every_hop_reads_the_shared_list(self):
|
||||
for name in ("packextras.py", "verify.py"):
|
||||
source = (REPO_ROOT / "scripts" / name).read_text(encoding="utf-8")
|
||||
for name in ("packs/extras.py", "verify.py"):
|
||||
source = script_source(name)
|
||||
with self.subTest(module=name):
|
||||
self.assertIn("PROFILE_IDENTITY_FIELDS", source)
|
||||
self.assertNotIn('("sha1", "md5", "sha256", "crc32", "size"', source)
|
||||
|
||||
@@ -8,6 +8,7 @@ it. RetroArch names Galaksija's 4 KiB galaksija/rom1.bin, so DOSBox's
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -41,7 +42,7 @@ class OneRule(unittest.TestCase):
|
||||
|
||||
def test_both_sides_call_it(self):
|
||||
for module in ("verify.py", "cross_reference.py"):
|
||||
source = (REPO_ROOT / "scripts" / module).read_text(encoding="utf-8")
|
||||
source = script_source(module)
|
||||
self.assertIn("declaration_settles(", source, module)
|
||||
|
||||
|
||||
@@ -105,7 +106,7 @@ class EveryGapReportFoldsCase(unittest.TestCase):
|
||||
import ast
|
||||
|
||||
for script in ("cross_reference.py", "generate_site.py"):
|
||||
source = (REPO_ROOT / "scripts" / script).read_text(encoding="utf-8")
|
||||
source = script_source(script)
|
||||
calls = [
|
||||
node for node in ast.walk(ast.parse(source))
|
||||
if isinstance(node, ast.Call)
|
||||
|
||||
@@ -10,6 +10,7 @@ ROCKNIX's higan SGB1.sfc/program.rom under the file SGB1.sfc.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import os
|
||||
import unittest
|
||||
@@ -41,19 +42,17 @@ class OneRule(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_builder_and_report_read_it(self):
|
||||
for module in ("generate_pack.py", "packextras.py"):
|
||||
source = (REPO_ROOT / "scripts" / module).read_text(encoding="utf-8")
|
||||
for module in ("generate_pack.py", "packs/extras.py"):
|
||||
source = script_source(module)
|
||||
self.assertIn("placement_block(", source, module)
|
||||
builder = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
builder = script_source("generate_pack.py")
|
||||
self.assertNotIn("if full_dest.lower() in seen_lower and case_insensitive", builder)
|
||||
|
||||
def test_a_refused_declaration_occupies_nothing(self):
|
||||
"""verify counted a declaration whose hash the frontend refuses as
|
||||
occupying its path, but the builder leaves it out, and the core file
|
||||
that then takes the path was reported missing from the pack."""
|
||||
source = (REPO_ROOT / "scripts" / "verify.py").read_text(encoding="utf-8")
|
||||
source = script_source("verify.py")
|
||||
compact = " ".join(source.split())
|
||||
self.assertRegex(
|
||||
compact,
|
||||
@@ -67,7 +66,7 @@ class TheIntegrityCheckFoldsCaseLikeTheBuilder(unittest.TestCase):
|
||||
of the two passed step 6."""
|
||||
|
||||
def test_case_folding_reads_the_platform(self):
|
||||
source = (REPO_ROOT / "scripts" / "packverify.py").read_text(encoding="utf-8")
|
||||
source = (REPO_ROOT / "scripts" / "packs" / "integrity.py").read_text(encoding="utf-8")
|
||||
compact = " ".join(source.split())
|
||||
self.assertRegex(
|
||||
compact,
|
||||
@@ -153,7 +152,7 @@ class TheGapReportIsComputedOnce(unittest.TestCase):
|
||||
os.chdir(REPO_ROOT)
|
||||
try:
|
||||
from packs import coverage
|
||||
from packs import gaps
|
||||
from packs import coverage as packs_coverage, gaps
|
||||
from model.database import load_database
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
@@ -163,7 +162,7 @@ class TheGapReportIsComputedOnce(unittest.TestCase):
|
||||
config = load_platform_config("emudeck", "platforms")
|
||||
with mock.patch.object(
|
||||
gaps, "find_undeclared_files", wraps=gaps.find_undeclared_files
|
||||
) as counted:
|
||||
) as counted, mock.patch.object(packs_coverage, "find_undeclared_files", counted):
|
||||
coverage.verify_platform(config, db, "emulators", profiles)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
|
||||
@@ -8,6 +8,7 @@ honours Retry-After, and large files that resume where they stopped.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
@@ -266,7 +267,7 @@ class ManifestHashesMatchTheScan(unittest.TestCase):
|
||||
def test_the_cache_is_keyed_by_what_was_checked(self):
|
||||
"""Keyed by id(db), a database freed and replaced at the same address
|
||||
got hashes verified against the first one back, unchecked."""
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
body = source[source.index("def _stable_hashes("):]
|
||||
body = body[: body.index("\ndef ")]
|
||||
key_line = next(line for line in body.splitlines() if line.strip().startswith("key ="))
|
||||
|
||||
@@ -10,6 +10,7 @@ to one answer.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import contextlib
|
||||
import functools
|
||||
@@ -1365,7 +1366,7 @@ class ThePlatformsOwnSystemNamesAreAccepted(unittest.TestCase):
|
||||
))
|
||||
|
||||
def test_the_builder_writes_them_into_the_manifest(self):
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertIn('"system_names": platform_system_names(config, list(pack_systems))',
|
||||
source)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ installs it).
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
@@ -9259,7 +9260,7 @@ class PacksWordingAndDocs(unittest.TestCase):
|
||||
self.assertEqual([entry.get("systems") for entry in manifest["files"]],
|
||||
[["3do"], [], None])
|
||||
self.assertEqual(manifest["system_titles"], {"3do": "3DO Interactive Multiplayer"})
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertIn("pack_systems_by_name=systems_for", source)
|
||||
schema = json.loads((REPO_ROOT / "schemas" / "pack-manifest.schema.json").read_text())
|
||||
self.assertIn("systems", schema["properties"]["files"]["items"]["properties"])
|
||||
|
||||
@@ -287,7 +287,7 @@ class LauncherGapTest(unittest.TestCase):
|
||||
with_rows = coverage.verify_platform(
|
||||
self.config, self.db, self.emulators_dir, self.profiles, data_dir_registry={}
|
||||
)
|
||||
with mock.patch.object(verify, "launcher_reads_not_held", return_value=[]):
|
||||
with mock.patch.object(coverage, "launcher_reads_not_held", return_value=[]):
|
||||
without = coverage.verify_platform(
|
||||
self.config, self.db, self.emulators_dir, self.profiles,
|
||||
data_dir_registry={},
|
||||
|
||||
@@ -9,6 +9,7 @@ and a fixed path the launcher passes (Batocera's x16emu shape).
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import hashlib
|
||||
import inspect
|
||||
@@ -23,7 +24,8 @@ import yaml
|
||||
from model.profiles import _emulator_profiles_cache, load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
from resolve.launchers import LauncherLayer, launcher_places, suffixed_stem
|
||||
from verify import find_undeclared_files, verify_platform
|
||||
from packs.gaps import find_undeclared_files
|
||||
from packs.coverage import verify_platform
|
||||
|
||||
CONTENT = {
|
||||
"b.bin": b"REGION_B_IMAGE",
|
||||
@@ -140,7 +142,7 @@ class LauncherLayerTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def _pack_names(self) -> set[str]:
|
||||
from generate_pack import generate_pack
|
||||
from packs.platformpack import generate_pack
|
||||
|
||||
output = os.path.join(self.root, "dist")
|
||||
os.makedirs(output)
|
||||
@@ -452,23 +454,25 @@ class LauncherLayerTest(unittest.TestCase):
|
||||
|
||||
def test_one_decision_for_verify_and_pack(self) -> None:
|
||||
"""The layer is applied once, in the report both sides read."""
|
||||
import generate_pack
|
||||
from packs import extras as packextras
|
||||
import verify
|
||||
from packs import gaps as packs_gaps
|
||||
|
||||
self.assertIn("LauncherLayer(", inspect.getsource(verify.find_undeclared_files))
|
||||
self.assertIn(".settle(", inspect.getsource(verify.find_undeclared_files))
|
||||
self.assertIn("LauncherLayer(", inspect.getsource(packs_gaps.find_undeclared_files))
|
||||
self.assertIn(".settle(", inspect.getsource(packs_gaps.find_undeclared_files))
|
||||
self.assertIn(
|
||||
"undeclared_report(", inspect.getsource(packextras._collect_emulator_extras)
|
||||
)
|
||||
self.assertIn(
|
||||
"find_undeclared_files(", inspect.getsource(packextras.undeclared_report)
|
||||
)
|
||||
for module in (generate_pack, packextras, verify):
|
||||
source = inspect.getsource(module)
|
||||
with self.subTest(module=module.__name__):
|
||||
for name, source in (
|
||||
("generate_pack", script_source("generate_pack.py")),
|
||||
("packs.extras", inspect.getsource(packextras)),
|
||||
("verify", script_source("verify.py")),
|
||||
):
|
||||
with self.subTest(module=name):
|
||||
self.assertNotIn("launcher_places(", source)
|
||||
if module is not verify:
|
||||
if name != "verify":
|
||||
self.assertNotIn("LauncherLayer(", source)
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ from model.registry import list_registered_platforms, load_data_dir_registry
|
||||
from resolve.localfile import resolve_local_file
|
||||
from resolve.ownership import BUCKET_FOLDERS, names_manufacturer
|
||||
import generate_db
|
||||
import generate_pack as builder
|
||||
from packs import manifest as packs_manifest, md5pack, naming as packs_naming, platformpack
|
||||
import generate_site
|
||||
from packs.coverage import verify_platform
|
||||
|
||||
@@ -118,7 +118,7 @@ class _Collection(unittest.TestCase):
|
||||
return self.config["systems"][system]["files"][0]
|
||||
|
||||
def _manifest(self) -> dict:
|
||||
return builder.generate_manifest(
|
||||
return packs_manifest.generate_manifest(
|
||||
"handheld", "platforms", self.db, "bios", "platforms/_registry.yml",
|
||||
emulators_dir="emulators", emu_profiles=self.profiles, offline=True,
|
||||
)
|
||||
@@ -186,7 +186,7 @@ class DiskRomGoesToThePc88File(_Collection):
|
||||
)
|
||||
|
||||
def test_pack(self):
|
||||
zip_path = builder.generate_pack(
|
||||
zip_path = platformpack.generate_pack(
|
||||
"handheld", "platforms", self.db, "bios", "out",
|
||||
emulators_dir="emulators", emu_profiles=self.profiles, offline=True,
|
||||
)
|
||||
@@ -198,7 +198,7 @@ class DiskRomGoesToThePc88File(_Collection):
|
||||
manifest = self._manifest()
|
||||
original = (platforms.load_platform_config, localfile.system_makers)
|
||||
# Every module that reads the loader by its own name sees the stub.
|
||||
readers = (builder, platforms, cliargs, cores, grouping)
|
||||
readers = (packs_manifest, md5pack, packs_naming, platformpack, platforms, cliargs, cores, grouping)
|
||||
|
||||
def untagged(*args, **kwargs):
|
||||
config = original[0](*args, **kwargs)
|
||||
|
||||
@@ -10,6 +10,7 @@ an empty repo_path, and the installer refused the whole manifest.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import ast
|
||||
import json
|
||||
@@ -17,7 +18,6 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
import generate_pack as gp
|
||||
from packs import manifestcores
|
||||
from packs import manifestentry
|
||||
from packs.manifestselect import SelectionIndex
|
||||
@@ -65,7 +65,7 @@ class AnEntryWithoutSourceIsAnOmission(unittest.TestCase):
|
||||
def record(full_dest, entry, system, reason, cores):
|
||||
omitted[full_dest] = reason
|
||||
|
||||
with mock.patch.object(gp, "compute_hashes", return_value=hashes):
|
||||
with mock.patch.object(manifestentry, "compute_hashes", return_value=hashes):
|
||||
manifestcores._manifest_core_entries(
|
||||
[extra], {}, self.db, str(REPO_ROOT / "bios"), "", str(REPO_ROOT),
|
||||
{}, True,
|
||||
@@ -105,7 +105,7 @@ class OneBuilderForEveryEntry(unittest.TestCase):
|
||||
"""Two copies of the entry let one drift: the guard lived in one only."""
|
||||
|
||||
def test_the_download_record_is_built_in_one_place(self):
|
||||
tree = ast.parse((REPO_ROOT / "scripts" / "generate_pack.py").read_text())
|
||||
tree = ast.parse(script_source("generate_pack.py"))
|
||||
builders = [
|
||||
node.lineno
|
||||
for node in ast.walk(tree)
|
||||
|
||||
@@ -12,6 +12,7 @@ profiles, placed below that folder.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import contextlib
|
||||
import hashlib
|
||||
@@ -458,7 +459,7 @@ class TheWholeTreeKeepsCoresMinUILeavesOut(unittest.TestCase):
|
||||
|
||||
def test_both_readers_build_the_set_the_same_way(self):
|
||||
for script in ("cross_reference.py", "generate_site.py"):
|
||||
source = (REPO_ROOT / "scripts" / script).read_text(encoding="utf-8")
|
||||
source = script_source(script)
|
||||
with self.subTest(script=script):
|
||||
self.assertIn("merged_standalone_set(", source)
|
||||
self.assertNotIn("set().union(*(\n standalone_set(", source)
|
||||
|
||||
@@ -11,6 +11,7 @@ it, and these tests make the agreement checkable instead of reviewable.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
@@ -475,9 +476,8 @@ class OneProfileSelector(unittest.TestCase):
|
||||
|
||||
def test_both_entry_points_route_through_it(self):
|
||||
"""A copy would let one accept what the other refuses."""
|
||||
scripts = Path(__file__).resolve().parent.parent / "scripts"
|
||||
for name in ("verify.py", "generate_pack.py"):
|
||||
text = (scripts / name).read_text()
|
||||
text = script_source(name)
|
||||
self.assertIn(
|
||||
"select_emulator_profiles", text,
|
||||
f"{name} must ask common, not re-derive the refusal",
|
||||
|
||||
@@ -18,7 +18,6 @@ from unittest import mock
|
||||
|
||||
import generate_pack as gp
|
||||
from packs import finalize as packs_finalize
|
||||
from packs import naming
|
||||
from packs import integrity as packverify
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -44,7 +43,7 @@ class ConformanceUsesTheRunDirectories(unittest.TestCase):
|
||||
if split:
|
||||
Path(self.tmp.name, "X_Split").mkdir(exist_ok=True)
|
||||
with self.subTest(split=split), mock.patch.object(
|
||||
packs_finalize, "verify_and_finalize_packs", return_value=True
|
||||
gp, "verify_and_finalize_packs", return_value=True
|
||||
) as finalize:
|
||||
gp._run_platform_packs(
|
||||
self._args(split), [], {}, {}, {}, {}, {}, None
|
||||
@@ -63,21 +62,21 @@ class ConformanceUsesTheRunDirectories(unittest.TestCase):
|
||||
seen.update(kwargs)
|
||||
return True, 0, 0, [], 0, 0, 0, 0, 0, 0
|
||||
|
||||
with mock.patch.object(gp, "list_registered_platforms", return_value=["fix"]), \
|
||||
with mock.patch.object(packs_finalize, "list_registered_platforms", return_value=["fix"]), \
|
||||
mock.patch.object(
|
||||
naming, "_expected_pack_names",
|
||||
packs_finalize, "_expected_pack_names",
|
||||
return_value={"fix": {"Fix_BIOS_Pack.zip"}},
|
||||
), \
|
||||
mock.patch.object(naming, "_pack_archives", return_value=["Fix_BIOS_Pack.zip"]), \
|
||||
mock.patch.object(packs_finalize, "_pack_archives", return_value=["Fix_BIOS_Pack.zip"]), \
|
||||
mock.patch.object(
|
||||
gp, "verify_pack",
|
||||
packs_finalize, "verify_pack",
|
||||
return_value=(True, {"summary": {
|
||||
"verified": 0, "total_files": 0, "untracked": 0, "errors": 0,
|
||||
}, "errors": []}),
|
||||
), \
|
||||
mock.patch.object(packs_finalize, "inject_manifest"), \
|
||||
mock.patch.object(packs_finalize, "_target_cores_for", return_value=None), \
|
||||
mock.patch.object(gp, "verify_pack_against_platform", record), \
|
||||
mock.patch.object(packs_finalize, "verify_pack_against_platform", record), \
|
||||
mock.patch.object(packverify, "verify_pack_against_platform", record):
|
||||
packs_finalize.verify_and_finalize_packs(
|
||||
str(out), {"files": {}, "indexes": {}},
|
||||
|
||||
@@ -17,7 +17,6 @@ from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
import generate_pack as gp
|
||||
from packs import finalize
|
||||
from packs import manifest
|
||||
from packs import platformpack
|
||||
|
||||
@@ -47,8 +46,9 @@ class FailedPlatformFailsTheRun(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_pack_mode(self):
|
||||
with mock.patch.object(platformpack, "generate_pack", _boom), \
|
||||
mock.patch.object(finalize, "verify_and_finalize_packs", return_value=True), \
|
||||
with mock.patch.object(gp, "generate_pack", _boom), \
|
||||
mock.patch.object(platformpack, "generate_pack", _boom), \
|
||||
mock.patch.object(gp, "verify_and_finalize_packs", return_value=True), \
|
||||
self.assertRaises(SystemExit) as ctx:
|
||||
gp._run_platform_packs(
|
||||
self._args(), [(["retropie"], "retropie")], {}, {}, {}, {}, {}, None
|
||||
@@ -56,7 +56,9 @@ class FailedPlatformFailsTheRun(unittest.TestCase):
|
||||
self.assertEqual(ctx.exception.code, 1)
|
||||
|
||||
def test_manifest_mode(self):
|
||||
with mock.patch.object(manifest, "generate_manifest", _boom), self.assertRaises(SystemExit) as ctx:
|
||||
with mock.patch.object(gp, "generate_manifest", _boom), \
|
||||
mock.patch.object(manifest, "generate_manifest", _boom), \
|
||||
self.assertRaises(SystemExit) as ctx:
|
||||
gp._run_manifest_mode(
|
||||
self._args(), [(["retropie"], "retropie")], {}, {}, {}, {}
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ ruled undecidable, and the keep overrode the drop.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import os
|
||||
import unittest
|
||||
@@ -42,7 +43,7 @@ class SlotPassReadsTheRegionGrouping(unittest.TestCase):
|
||||
self.assertIn(name, names)
|
||||
|
||||
def test_one_grouping_function(self):
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn("def _pack_member_groups", source)
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class SchemaAcceptsEveryStatus(unittest.TestCase):
|
||||
"""verified_members reached every pack manifest and the schema refused it."""
|
||||
|
||||
def test_each_status_packverify_writes_is_in_the_schema(self):
|
||||
source = (REPO_ROOT / "scripts" / "packverify.py").read_text(encoding="utf-8")
|
||||
source = (REPO_ROOT / "scripts" / "packs" / "integrity.py").read_text(encoding="utf-8")
|
||||
written = set(re.findall(r'status = "([a-z_]+)"', source))
|
||||
schema = json.loads(
|
||||
(REPO_ROOT / "schemas" / "pack-manifest.schema.json").read_text(encoding="utf-8")
|
||||
@@ -113,7 +113,7 @@ class OneComparisonOfArchiveMembers(unittest.TestCase):
|
||||
self.assertTrue(_same_members(zf, "same.zip", str(held)))
|
||||
self.assertFalse(_same_members(zf, "other.zip", str(held)))
|
||||
self.assertFalse(_same_members(zf, "broken.zip", str(held)))
|
||||
source = (Path(__file__).resolve().parents[1] / "scripts" / "packverify.py").read_text()
|
||||
source = (Path(__file__).resolve().parents[1] / "scripts" / "packs" / "integrity.py").read_text()
|
||||
self.assertNotIn("import io as _io", source)
|
||||
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class ACardOpenedOnAComputerShowsItsShareDrive(unittest.TestCase):
|
||||
class GuidesNameShippedInstallers(unittest.TestCase):
|
||||
def test_every_installer_named_exists(self):
|
||||
"""RetroBat's guide sent users to an install.bat no release carries."""
|
||||
source = (REPO_ROOT / "scripts" / "packreadme.py").read_text(encoding="utf-8")
|
||||
source = (REPO_ROOT / "scripts" / "packs" / "readme.py").read_text(encoding="utf-8")
|
||||
for name in set(re.findall(r"install\.(?:bat|ps1|sh|py)", source)):
|
||||
with self.subTest(installer=name):
|
||||
self.assertTrue((REPO_ROOT / name).is_file())
|
||||
@@ -120,7 +120,7 @@ class TheOneLinerFollowsTheRegistry(unittest.TestCase):
|
||||
import sitebootstrap
|
||||
from siteguides import INSTALL_BASE
|
||||
|
||||
source = (REPO_ROOT / "scripts" / "packreadme.py").read_text(encoding="utf-8")
|
||||
source = (REPO_ROOT / "scripts" / "packs" / "readme.py").read_text(encoding="utf-8")
|
||||
self.assertNotIn("raw.githubusercontent.com", source)
|
||||
self.assertNotIn("abdess.github.io", source)
|
||||
self.assertEqual(packreadme.INSTALL_SH, f"{INSTALL_BASE}/{sitebootstrap.SH_NAME}")
|
||||
|
||||
@@ -57,9 +57,9 @@ class RefreshConcurrency(unittest.TestCase):
|
||||
self.cache.mkdir(parents=True)
|
||||
(self.cache / "a.bin").write_bytes(b"old")
|
||||
with mock.patch.object(
|
||||
rdd.urllib.request, "urlopen", lambda *a, **k: _Response(payload)
|
||||
datadirs.urllib.request, "urlopen", lambda *a, **k: _Response(payload)
|
||||
), mock.patch.object(
|
||||
rdd.shutil, "move", side_effect=AssertionError("copy across filesystems")
|
||||
datadirs.shutil, "move", side_effect=AssertionError("copy across filesystems")
|
||||
):
|
||||
count = datadirs._download_and_extract_zip("https://x/pak.zip", str(self.cache))
|
||||
self.assertEqual(count, 1)
|
||||
@@ -87,7 +87,7 @@ class RefreshConcurrency(unittest.TestCase):
|
||||
|
||||
entry = {"source_type": "zip", "source_url": "https://x/pak.zip",
|
||||
"local_cache": str(self.cache)}
|
||||
with mock.patch.object(rdd.urllib.request, "urlopen", fake_urlopen), \
|
||||
with mock.patch.object(datadirs.urllib.request, "urlopen", fake_urlopen), \
|
||||
mock.patch.object(datadirs, "_get_remote_etag", return_value="e1"):
|
||||
self.assertTrue(
|
||||
datadirs.refresh_entry("pak", entry, force=True, versions_path=self.versions)
|
||||
@@ -101,7 +101,7 @@ class RefreshConcurrency(unittest.TestCase):
|
||||
payload = _zip_bytes({"a.bin": b"x" * 100})
|
||||
entry = {"source_type": "zip", "source_url": "https://x/pak.zip",
|
||||
"local_cache": str(self.cache)}
|
||||
with mock.patch.object(rdd.urllib.request, "urlopen",
|
||||
with mock.patch.object(datadirs.urllib.request, "urlopen",
|
||||
lambda *a, **k: _Response(payload)), \
|
||||
mock.patch.object(datadirs, "_get_remote_etag", return_value="e1"):
|
||||
self.assertTrue(datadirs.refresh_entry("pak", entry, versions_path=self.versions))
|
||||
@@ -171,7 +171,7 @@ class RefreshConcurrency(unittest.TestCase):
|
||||
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"}}))
|
||||
with mock.patch.object(rdd.json, "dump", side_effect=OSError("disk full")), self.assertRaises(OSError):
|
||||
with mock.patch.object(datadirs.json, "dump", side_effect=OSError("disk full")), self.assertRaises(OSError):
|
||||
datadirs._save_versions({"keep": {"sha": "2"}}, self.versions)
|
||||
self.assertEqual(json.loads(Path(self.versions).read_text()), {"keep": {"sha": "1"}})
|
||||
|
||||
@@ -235,7 +235,7 @@ class EmulatorPackHoldsTheCache(unittest.TestCase):
|
||||
fcntl.flock(handle, fcntl.LOCK_UN)
|
||||
held.append(False)
|
||||
|
||||
with mock.patch("packs.archive._add_pack_member", member):
|
||||
with mock.patch("packs.datatrees._add_pack_member", member):
|
||||
_pack_data_tree(None, str(cache), "scummvm", set(), set(), set())
|
||||
self.assertEqual(held, [True])
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
import check_buildbot_system
|
||||
import refresh_data_dirs
|
||||
from packs import datadirs
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -39,7 +38,7 @@ class GitThatCannotAnswer(unittest.TestCase):
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "-c", (
|
||||
f"import sys; sys.path.insert(0, {str(REPO_ROOT / 'scripts')!r}); "
|
||||
"import verify; verify.work_from_repo_root = lambda *a: None; "
|
||||
"from model import cliargs; cliargs.work_from_repo_root = lambda *a: None; "
|
||||
"import validate_pr; sys.argv = ['validate_pr.py', '--changed']; "
|
||||
"validate_pr.main()"
|
||||
)],
|
||||
@@ -106,8 +105,8 @@ class AForkPushedToItsOwnMain(unittest.TestCase):
|
||||
return subprocess.run(
|
||||
[sys.executable, "-c", (
|
||||
f"import sys; sys.path.insert(0, {str(REPO_ROOT / 'scripts')!r}); "
|
||||
"import validate_pr; "
|
||||
f"validate_pr.PROJECT_URLS = ({project!r},); "
|
||||
"import validate_pr; from core import gitclone; "
|
||||
f"gitclone.PROJECT_URLS = ({project!r},); "
|
||||
"print(validate_pr.get_changed_files())"
|
||||
)],
|
||||
cwd=clone, capture_output=True, text=True, timeout=60, check=False,
|
||||
@@ -237,9 +236,9 @@ class ABadResponseIsTriedAgain(unittest.TestCase):
|
||||
raise outcome
|
||||
return outcome
|
||||
|
||||
with mock.patch.object(self.rdd, "_get_remote_etag", lambda _url: "tag"), \
|
||||
mock.patch.object(self.rdd, "_download_and_extract_zip", download), \
|
||||
mock.patch.object(refresh_data_dirs.time, "sleep", self.waits.append):
|
||||
with mock.patch.object(datadirs, "_get_remote_etag", lambda _url: "tag"), \
|
||||
mock.patch.object(datadirs, "_download_and_extract_zip", download), \
|
||||
mock.patch.object(datadirs.time, "sleep", self.waits.append):
|
||||
return datadirs._refresh_entry("s", self.entry, True, False, self.versions)
|
||||
|
||||
def test_a_bad_archive_then_a_good_one_refreshes(self):
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
@@ -698,14 +699,14 @@ class TestReportAndBuilderNarrowTogether(unittest.TestCase):
|
||||
def test_the_report_withdraws_what_the_builder_withdraws(self):
|
||||
from model import profiles as model_profiles
|
||||
from model.profiles import _emulator_profiles_cache
|
||||
import generate_pack as builder
|
||||
from packs import extras as packs_extras
|
||||
from packs import coverage
|
||||
|
||||
tmp, root, db, config = self._fixture()
|
||||
try:
|
||||
_emulator_profiles_cache.clear()
|
||||
profiles = model_profiles.load_emulator_profiles(str(root / "emulators"))
|
||||
groups, extra_dests = builder.platform_region_groups(
|
||||
groups, extra_dests = packs_extras.platform_region_groups(
|
||||
config, config["systems"], str(root / "emulators"),
|
||||
db, "", profiles,
|
||||
)
|
||||
@@ -797,11 +798,11 @@ class TestReportAndBuilderNarrowTogether(unittest.TestCase):
|
||||
|
||||
Every module is read, not only the two that once held a copy: the
|
||||
builder was split into several modules and a grouping can move with
|
||||
it. packextras.py holds the two shared passes, platform and emulator.
|
||||
it. packs/extras.py holds the two shared passes, platform and emulator.
|
||||
"""
|
||||
scripts = Path(__file__).resolve().parent.parent / "scripts"
|
||||
for path in sorted(scripts.rglob("*.py")):
|
||||
if path.name == "packextras.py":
|
||||
if path == scripts / "packs" / "extras.py":
|
||||
continue
|
||||
with self.subTest(module=path.name):
|
||||
self.assertNotIn(
|
||||
@@ -814,11 +815,9 @@ class TestReportAndBuilderNarrowTogether(unittest.TestCase):
|
||||
"""Imported through the builder's CLI module, the verdict of a
|
||||
--region run depended on that module compiling, and seven scripts
|
||||
entered the site workflow's trigger paths for one function."""
|
||||
source = (Path(__file__).resolve().parent.parent / "scripts" / "verify.py").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
source = script_source("verify.py")
|
||||
self.assertNotIn("from generate_pack import platform_region_groups", source)
|
||||
self.assertIn("from packextras import platform_region_groups", source)
|
||||
self.assertIn("from packs.extras import platform_region_groups", source)
|
||||
|
||||
def test_emulator_report_keeps_what_the_emulator_pack_keeps(self):
|
||||
"""O2EM: --region us left the Videopac BIOSes in the pack, not in the report."""
|
||||
|
||||
@@ -9,6 +9,7 @@ voided the [europe] tag Genesis Plus GX and PicoDrive give it, and
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -33,8 +34,8 @@ class OnlyThePlatformsCores(unittest.TestCase):
|
||||
self.assertTrue(regions.build_region_index(PROFILES)["bios_CD_E.bin"]["has_untagged"])
|
||||
|
||||
def test_every_platform_site_reads_it(self):
|
||||
for module in ("verify.py", "generate_pack.py", "packverify.py"):
|
||||
source = (REPO_ROOT / "scripts" / module).read_text(encoding="utf-8")
|
||||
for module in ("verify.py", "generate_pack.py", "packs/integrity.py"):
|
||||
source = script_source(module)
|
||||
self.assertNotIn("build_region_index(emu_profiles", source, module)
|
||||
self.assertNotIn("build_region_index(profiles)", source, module)
|
||||
self.assertIn("platform_region_index(", source, module)
|
||||
@@ -64,7 +65,7 @@ class OnlyThePlatformsCoresRankASlot(unittest.TestCase):
|
||||
self.assertEqual(slot_mod.build_slot_index(self.PROFILES)["scph100.bin"]["rank"], 10)
|
||||
|
||||
def test_the_pack_reads_it(self):
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn("build_slot_index(", source)
|
||||
self.assertIn("platform_slot_index(", source)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ the optional winner: the slot shipped empty.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import ast
|
||||
import unittest
|
||||
@@ -32,7 +33,7 @@ class RequiredOnlyBeforeRegion(unittest.TestCase):
|
||||
self.assertEqual(groups["vic20"], [("Vic20/kernel-ntsc.bin", "kernel-ntsc.bin")])
|
||||
|
||||
def test_every_caller_passes_it(self):
|
||||
tree = ast.parse((REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8"))
|
||||
tree = ast.parse(script_source("generate_pack.py"))
|
||||
calls = [
|
||||
node for node in ast.walk(tree)
|
||||
if isinstance(node, ast.Call)
|
||||
|
||||
@@ -105,7 +105,7 @@ class GuidesLiveInYaml(unittest.TestCase):
|
||||
# A table of prose keyed by platform: what the guides file replaced.
|
||||
_PLATFORM_BRANCH = re.compile(r"""(?:==|!=)\s*["']([a-z0-9-]+)["']|["']([a-z0-9-]+)["']\s*(?:==|!=)""")
|
||||
# The modules that write the site and the pack README.
|
||||
_RENDERERS = ("generate_site.py", "packreadme.py", "generate_readme.py")
|
||||
_RENDERERS = ("generate_site.py", "packs/readme.py", "generate_readme.py")
|
||||
|
||||
|
||||
class NoPlatformProseInScripts(unittest.TestCase):
|
||||
|
||||
+2
-3
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import os
|
||||
import unittest
|
||||
@@ -314,9 +315,7 @@ class AnAbsentRankOneDisplacesNothing(unittest.TestCase):
|
||||
self.assertEqual(drops, {"bios/us_scd1_9210.bin"})
|
||||
|
||||
def test_the_builder_passes_held(self):
|
||||
from pathlib import Path
|
||||
|
||||
source = (Path(__file__).resolve().parents[1] / "scripts" / "generate_pack.py").read_text()
|
||||
source = script_source("generate_pack.py")
|
||||
compact = " ".join(source.split())
|
||||
self.assertRegex(compact, r"resolve_slot_drops\( slot_groups, slot_mod\.platform_slot_index\([^)]*\), held, \)")
|
||||
|
||||
|
||||
+15
-13
@@ -263,8 +263,7 @@ class TestConflicts(unittest.TestCase):
|
||||
"""
|
||||
import inspect
|
||||
|
||||
import generate_pack
|
||||
import verify
|
||||
from packs import coverage, manifest, platformpack
|
||||
|
||||
for function in (
|
||||
packs_slots.platform_claims,
|
||||
@@ -284,9 +283,11 @@ class TestConflicts(unittest.TestCase):
|
||||
# Every consumer reads the one decision and hands its indexes over:
|
||||
# the ZIP builder, the install manifest and the report. The manifest
|
||||
# deciding nothing gave the installer other bytes than the ZIP.
|
||||
for module, calls in ((generate_pack, 2), (verify, 1)):
|
||||
source = inspect.getsource(module)
|
||||
with self.subTest(module=module.__name__):
|
||||
for tool, modules, calls in (
|
||||
("generate_pack", (platformpack, manifest), 2), ("verify", (coverage,), 1),
|
||||
):
|
||||
source = "".join(inspect.getsource(module) for module in modules)
|
||||
with self.subTest(tool=tool):
|
||||
self.assertNotIn("slots.arbitrate(", source)
|
||||
self.assertNotIn("slots.find_conflicts(", source)
|
||||
self.assertEqual(source.count("slots.pack_overrides("), calls)
|
||||
@@ -499,15 +500,16 @@ class TestBuilderAndVerifierAgree(unittest.TestCase):
|
||||
def test_both_read_the_same_decision_function(self):
|
||||
# The rule lives in one place. A second copy would let the pack and the
|
||||
# report describe different files, which the project forbids outright.
|
||||
builder = Path(__file__).resolve().parents[1] / "scripts" / "generate_pack.py"
|
||||
verifier = Path(__file__).resolve().parents[1] / "scripts" / "verify.py"
|
||||
for source in (builder, verifier):
|
||||
scripts = Path(__file__).resolve().parents[1] / "scripts"
|
||||
builder = (scripts / "packs" / "platformpack.py", scripts / "packs" / "manifest.py")
|
||||
verifier = (scripts / "packs" / "coverage.py",)
|
||||
for source in (*builder, *verifier):
|
||||
text = source.read_text(encoding="utf-8")
|
||||
self.assertIn("slots.pack_overrides(", text, source.name)
|
||||
self.assertNotIn("decision.serves_both", text, source.name)
|
||||
self.assertIn(
|
||||
"decision.serves_both",
|
||||
(builder.parent / "slots.py").read_text(encoding="utf-8"),
|
||||
(scripts / "slots.py").read_text(encoding="utf-8"),
|
||||
)
|
||||
|
||||
def test_neither_reimplements_the_mode_test(self):
|
||||
@@ -516,7 +518,7 @@ class TestBuilderAndVerifierAgree(unittest.TestCase):
|
||||
# override lookup both sides must perform. The old anchor was a string
|
||||
# the test above forbids, so the window was the whole file.
|
||||
mode_test = re.compile(r"""[=!]=\s*["'](?:md5|sha1|existence)["']""")
|
||||
for name in ("generate_pack.py", "verify.py"):
|
||||
for name in ("packs/platformpack.py", "packs/manifest.py", "packs/coverage.py"):
|
||||
source = Path(__file__).resolve().parents[1] / "scripts" / name
|
||||
body = source.read_text(encoding="utf-8")
|
||||
anchors = [m.start() for m in re.finditer(r"slot_overrides\.get\(", body)]
|
||||
@@ -606,7 +608,7 @@ class TestSelfContradictingDestinations(unittest.TestCase):
|
||||
|
||||
variant = Path("bios/M/C/.variants/aes.zip")
|
||||
self.assertEqual(generate_db._canonical_name(variant), "aes.zip")
|
||||
for module in ("slots.py", "generate_db.py"):
|
||||
for module in ("resolve/collisions.py", "generate_db.py"):
|
||||
source = (Path(__file__).resolve().parents[1] / "scripts" / module).read_text()
|
||||
with self.subTest(module=module):
|
||||
self.assertIn("variant_base_name(", source)
|
||||
@@ -781,8 +783,8 @@ class ManifestFollowsTheArbitration(unittest.TestCase):
|
||||
previous = os.getcwd()
|
||||
os.chdir(repo)
|
||||
self.addCleanup(os.chdir, previous)
|
||||
import generate_pack
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from packs import manifest as packs_manifest
|
||||
from model.registry import load_data_dir_registry
|
||||
from model.database import load_database
|
||||
from model.profiles import load_emulator_profiles
|
||||
@@ -799,7 +801,7 @@ class ManifestFollowsTheArbitration(unittest.TestCase):
|
||||
# dsi_bios7/9.bin): an arbitration that settles nothing is the
|
||||
# failure, not a reason to skip.
|
||||
self.assertTrue(overrides, "pack_overrides settles no RetroArch slot")
|
||||
manifest = generate_pack.generate_manifest(
|
||||
manifest = packs_manifest.generate_manifest(
|
||||
"retroarch", str(repo / "platforms"), db, str(repo / "bios"),
|
||||
str(repo / "platforms" / "_registry.yml"),
|
||||
emulators_dir=str(repo / "emulators"), emu_profiles=profiles, offline=True,
|
||||
|
||||
@@ -8,11 +8,12 @@ names, while the split packs, built per system, carried them.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from generate_pack import _extras_for_systems
|
||||
from packs.extras import extras_for_systems as _extras_for_systems
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
@@ -47,7 +48,7 @@ class SystemExtras(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_full_source_does_not_empty_them(self):
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn('elif system_filter and source != "truth":\n core_files = []', source)
|
||||
|
||||
|
||||
|
||||
@@ -583,13 +583,12 @@ class EmulatorVerifyReadsNoArchiveItDoesNotNeed(unittest.TestCase):
|
||||
def test_the_member_index_is_not_built(self):
|
||||
from unittest import mock
|
||||
|
||||
import verify
|
||||
from packs import emulatorcheck
|
||||
|
||||
if not (REPO_ROOT / "database.json").exists():
|
||||
self.skipTest("database.json is not generated")
|
||||
db = load_database(str(REPO_ROOT / "database.json"))
|
||||
with mock.patch.object(verify, "build_zip_contents_index",
|
||||
with mock.patch.object(emulatorcheck, "build_zip_contents_index",
|
||||
side_effect=AssertionError("index built")):
|
||||
result = emulatorcheck.verify_emulator(["handy"], str(REPO_ROOT / "emulators"), db)
|
||||
self.assertTrue(result)
|
||||
|
||||
@@ -8,6 +8,7 @@ and `--verify-packs --target nx` looked for a pack nobody had built.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -130,7 +131,7 @@ class EachPlatformNamesTheTargetItsOwnWay(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_no_naming_site_reads_the_typed_target(self):
|
||||
source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text()
|
||||
source = script_source("generate_pack.py")
|
||||
self.assertNotIn("target_name=args.target,\n one_per_slot", source)
|
||||
self.assertNotIn("args.target = canonical_target_name(", source)
|
||||
|
||||
|
||||
+10
-10
@@ -136,9 +136,8 @@ class ASplitBuildsOnlyTheTargetsSystems(unittest.TestCase):
|
||||
def test_no_part_is_asked_for_a_dropped_system(self):
|
||||
from unittest import mock
|
||||
|
||||
import generate_pack
|
||||
from packs import manifest, platformpack
|
||||
from packs import platformpack as packs_platformpack
|
||||
from packs import platformpack
|
||||
from model.profiles import load_emulator_profiles
|
||||
|
||||
platforms = str(REPO_ROOT / "platforms")
|
||||
@@ -152,8 +151,8 @@ class ASplitBuildsOnlyTheTargetsSystems(unittest.TestCase):
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out, \
|
||||
mock.patch.object(platformpack, "generate_pack", record), \
|
||||
mock.patch.object(generate_pack, "_collect_emulator_extras",
|
||||
return_value=[]):
|
||||
mock.patch.object(platformpack, "_collect_emulator_extras", return_value=[]), \
|
||||
mock.patch.object(manifest, "_collect_emulator_extras", return_value=[]):
|
||||
packs_platformpack.generate_split_packs(
|
||||
"retroarch", platforms, {"files": {}}, "bios", out,
|
||||
emu_profiles=profiles,
|
||||
@@ -207,16 +206,17 @@ class TheSplitDirectoryReadsThePackStem(unittest.TestCase):
|
||||
def test_a_reserved_character_is_made_safe_as_in_the_full_pack(self):
|
||||
from unittest import mock
|
||||
|
||||
import generate_pack
|
||||
from packs import manifest, md5pack, naming
|
||||
from packs import platformpack as packs_platformpack
|
||||
from packs import naming
|
||||
|
||||
config = {"platform": "Foo: Bar", "version": "release/1.22", "systems": {}}
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out, \
|
||||
mock.patch.object(generate_pack, "load_platform_config",
|
||||
return_value=config), \
|
||||
mock.patch.object(generate_pack, "_collect_emulator_extras",
|
||||
return_value=[]):
|
||||
mock.patch.object(packs_platformpack, "load_platform_config", return_value=config), \
|
||||
mock.patch.object(naming, "load_platform_config", return_value=config), \
|
||||
mock.patch.object(manifest, "load_platform_config", return_value=config), \
|
||||
mock.patch.object(md5pack, "load_platform_config", return_value=config), \
|
||||
mock.patch.object(packs_platformpack, "_collect_emulator_extras", return_value=[]), \
|
||||
mock.patch.object(manifest, "_collect_emulator_extras", return_value=[]):
|
||||
packs_platformpack.generate_split_packs(
|
||||
"foo", "platforms", {"files": {}}, "bios", out, emu_profiles={},
|
||||
)
|
||||
|
||||
@@ -262,14 +262,14 @@ class SymlinksAreRefusedBeforeReading(_Fixture):
|
||||
link = self.tmp / "bios" / "Sony" / "PS" / "link.bin"
|
||||
link.symlink_to(self.tmp / "bios" / "Sony" / "PS" / "real.bin")
|
||||
calls = []
|
||||
real = validate_pr.compute_hashes
|
||||
validate_pr.compute_hashes = lambda p, *a, **k: (
|
||||
real = review.compute_hashes
|
||||
review.compute_hashes = lambda p, *a, **k: (
|
||||
calls.append(p) or real(p, *a, **k)
|
||||
)
|
||||
try:
|
||||
review.validate_file("bios/Sony/PS/link.bin", None, EMPTY_HASHES)
|
||||
finally:
|
||||
validate_pr.compute_hashes = real
|
||||
review.compute_hashes = real
|
||||
self.assertEqual(calls, [], "a symlink target must not be read")
|
||||
|
||||
@unittest.skipUnless(os.path.exists("/dev/zero"), "needs /dev/zero")
|
||||
|
||||
@@ -9,6 +9,7 @@ across 14 destinations on six platforms.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import ast
|
||||
import hashlib
|
||||
@@ -83,7 +84,7 @@ class ValidatedChoice(unittest.TestCase):
|
||||
self.assertEqual(disagreement is not None, judged)
|
||||
|
||||
def test_pack_and_manifest_both_read_it(self):
|
||||
tree = ast.parse((REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8"))
|
||||
tree = ast.parse(script_source("generate_pack.py"))
|
||||
callers = {
|
||||
node.name
|
||||
for node in ast.walk(tree)
|
||||
@@ -106,7 +107,7 @@ class ValidatedChoice(unittest.TestCase):
|
||||
)
|
||||
}
|
||||
self.assertLessEqual({"generate_pack", "_manifest_core_entries"}, resolvers)
|
||||
extras = ast.parse((REPO_ROOT / "scripts" / "packextras.py").read_text(encoding="utf-8"))
|
||||
extras = ast.parse((REPO_ROOT / "scripts" / "packs" / "extras.py").read_text(encoding="utf-8"))
|
||||
resolve = next(
|
||||
node for node in ast.walk(extras)
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "resolve"
|
||||
@@ -119,7 +120,7 @@ class ValidatedChoice(unittest.TestCase):
|
||||
def test_core_extras_are_judged_too(self):
|
||||
"""The baseline loop judged a platform's own files while the core-extras loop
|
||||
shipped whatever the name found. Both loops live in generate_pack."""
|
||||
tree = ast.parse((REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8"))
|
||||
tree = ast.parse(script_source("generate_pack.py"))
|
||||
builder = next(
|
||||
node for node in ast.walk(tree)
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "generate_pack"
|
||||
@@ -135,7 +136,7 @@ class ValidatedChoice(unittest.TestCase):
|
||||
and getattr(call.func.value, "id", None) == "extra_resolver"
|
||||
for call in ast.walk(builder)
|
||||
))
|
||||
extras = ast.parse((REPO_ROOT / "scripts" / "packextras.py").read_text(encoding="utf-8"))
|
||||
extras = ast.parse((REPO_ROOT / "scripts" / "packs" / "extras.py").read_text(encoding="utf-8"))
|
||||
resolve = next(
|
||||
node for node in ast.walk(extras)
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "resolve"
|
||||
|
||||
@@ -9,6 +9,7 @@ test fails if either hands the index the whole profile set again.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import re
|
||||
import unittest
|
||||
@@ -20,14 +21,14 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
class ValidationIndexScope(unittest.TestCase):
|
||||
def test_no_index_over_every_profile(self):
|
||||
pattern = re.compile(r"_build_validation_index\(\s*(emu_)?profiles\s*\)")
|
||||
for name in ("verify.py", "generate_pack.py", "packverify.py", "packextras.py"):
|
||||
source = (REPO_ROOT / "scripts" / name).read_text(encoding="utf-8")
|
||||
for name in ("verify.py", "generate_pack.py", "packs/integrity.py", "packs/extras.py"):
|
||||
source = script_source(name)
|
||||
with self.subTest(module=name):
|
||||
self.assertIsNone(pattern.search(source))
|
||||
|
||||
def test_platform_paths_select_by_platform_cores(self):
|
||||
verify = (REPO_ROOT / "scripts" / "verify.py").read_text(encoding="utf-8")
|
||||
builder = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8")
|
||||
verify = script_source("verify.py")
|
||||
builder = script_source("generate_pack.py")
|
||||
self.assertRegex(
|
||||
verify,
|
||||
r"plat_cores = resolve_platform_cores\(config, profiles\)\s+"
|
||||
@@ -43,7 +44,7 @@ class ValidationIndexScope(unittest.TestCase):
|
||||
|
||||
class HleIndexScope(unittest.TestCase):
|
||||
def test_hle_index_reads_the_platform_cores(self):
|
||||
verify = (REPO_ROOT / "scripts" / "verify.py").read_text(encoding="utf-8")
|
||||
verify = script_source("verify.py")
|
||||
start = verify.index(" hle_index = {")
|
||||
block = verify[start:verify.index("}", start)]
|
||||
self.assertIn("for profile in platform_profiles.values()", block)
|
||||
|
||||
@@ -10,6 +10,7 @@ never swapped in. Both sides now read find_validated_variant.
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
@@ -77,12 +78,12 @@ class OneImplementation(unittest.TestCase):
|
||||
"""The report and the builders call the same finder and keep no copy."""
|
||||
|
||||
def test_no_module_carries_its_own_variant_search(self):
|
||||
for name in ("verify.py", "generate_pack.py", "packresolve.py"):
|
||||
source = (REPO_ROOT / "scripts" / name).read_text(encoding="utf-8")
|
||||
for name in ("verify.py", "generate_pack.py", "resolve/packfiles.py"):
|
||||
source = script_source(name)
|
||||
with self.subTest(module=name):
|
||||
self.assertNotRegex(source, r"def _find_best_variant|def _find_candidate_satisfying_both")
|
||||
for name in ("verify.py", "generate_pack.py"):
|
||||
source = (REPO_ROOT / "scripts" / name).read_text(encoding="utf-8")
|
||||
source = script_source(name)
|
||||
with self.subTest(module=name):
|
||||
# Directly or through validated_choice, the one place that
|
||||
# picks the variant a destination ships.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
from tests.sources import script_source
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -57,7 +58,6 @@ class VerifyRefusesWhatAModeDoesNotRead(unittest.TestCase):
|
||||
self.assertIn(flag, result.stderr)
|
||||
|
||||
def test_emulator_mode_reads_the_given_platforms_dir(self):
|
||||
import verify
|
||||
from packs import emulatorcheck
|
||||
|
||||
seen: list[str] = []
|
||||
@@ -67,7 +67,7 @@ class VerifyRefusesWhatAModeDoesNotRead(unittest.TestCase):
|
||||
return {}
|
||||
|
||||
db = {"files": {}, "indexes": {"by_name": {}, "by_md5": {}}}
|
||||
with mock.patch.object(verify, "load_data_dir_registry", registry):
|
||||
with mock.patch.object(emulatorcheck, "load_data_dir_registry", registry):
|
||||
emulatorcheck.verify_emulator(
|
||||
["handy"], str(REPO_ROOT / "emulators"), db, platforms_dir="elsewhere"
|
||||
)
|
||||
@@ -90,7 +90,6 @@ class VerifyAppliesWhatItAccepts(unittest.TestCase):
|
||||
|
||||
class EmulatorPackReadsThePlatformsDir(unittest.TestCase):
|
||||
def test_the_registry_comes_from_the_given_dir(self):
|
||||
import generate_pack
|
||||
from packs import emulatorpack
|
||||
|
||||
seen: list[str] = []
|
||||
@@ -101,7 +100,7 @@ class EmulatorPackReadsThePlatformsDir(unittest.TestCase):
|
||||
|
||||
db = {"files": {}, "indexes": {"by_name": {}, "by_md5": {}}}
|
||||
out = REPO_ROOT / "tmp" / "emupack-registry"
|
||||
with mock.patch.object(generate_pack, "load_data_dir_registry", registry):
|
||||
with mock.patch.object(emulatorpack, "load_data_dir_registry", registry):
|
||||
emulatorpack.generate_emulator_pack(
|
||||
["handy"], str(REPO_ROOT / "emulators"), db, "bios", str(out),
|
||||
zip_contents={}, platforms_dir="elsewhere",
|
||||
@@ -175,7 +174,7 @@ class TheDestinationsFlagNeedsAPack(unittest.TestCase):
|
||||
that mode raised AttributeError."""
|
||||
import ast
|
||||
|
||||
tree = ast.parse((REPO_ROOT / "scripts" / "verify.py").read_text(encoding="utf-8"))
|
||||
tree = ast.parse(script_source("verify.py"))
|
||||
body = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == "_main")
|
||||
stack = body.args.args[0].arg
|
||||
rebound = [
|
||||
|
||||
@@ -69,7 +69,7 @@ class VerifyPackChoice(unittest.TestCase):
|
||||
|
||||
self.variants: list[tuple[str, bool]] = []
|
||||
|
||||
with mock.patch.object(self.gp, "verify_pack_against_platform", record):
|
||||
with mock.patch.object(generate_pack, "verify_pack_against_platform", record):
|
||||
generate_pack._run_verify_packs(args)
|
||||
return checked
|
||||
|
||||
@@ -143,7 +143,7 @@ class VerifyPackChoice(unittest.TestCase):
|
||||
self._touch(pack)
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
failed = (False, 0, 0, ["x: missing"], 1, 0, 1, 1, 0, 0)
|
||||
with mock.patch.object(self.gp, "verify_pack_against_platform",
|
||||
with mock.patch.object(generate_pack, "verify_pack_against_platform",
|
||||
return_value=failed), \
|
||||
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err), \
|
||||
self.assertRaises(SystemExit):
|
||||
@@ -176,7 +176,6 @@ class VerifyPackChoice(unittest.TestCase):
|
||||
class GroupRenameKeepsSystemTag(unittest.TestCase):
|
||||
def test_single_system_pack_does_not_take_the_full_name(self):
|
||||
import generate_pack as gp
|
||||
from packs import finalize
|
||||
from packs import naming
|
||||
from packs import platformpack
|
||||
|
||||
@@ -199,8 +198,9 @@ class GroupRenameKeepsSystemTag(unittest.TestCase):
|
||||
one_per_slot=False, offline=True, bios_dir="bios",
|
||||
output_dir=tmp,
|
||||
)
|
||||
with mock.patch.object(platformpack, "generate_pack", fake_generate), \
|
||||
mock.patch.object(finalize, "verify_and_finalize_packs", return_value=True):
|
||||
with mock.patch.object(gp, "generate_pack", fake_generate), \
|
||||
mock.patch.object(platformpack, "generate_pack", fake_generate), \
|
||||
mock.patch.object(gp, "verify_and_finalize_packs", return_value=True):
|
||||
gp._run_platform_packs(
|
||||
args, [(["retroarch", "lakka"], "retroarch")], {}, {}, {},
|
||||
{}, {}, ["atari-lynx"],
|
||||
|
||||
Reference in new issue
Block a user