mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-30 13:28:51 -06:00
refactor: move verify, slots, crossref into packs
The three commands keep their parser, main and printing. Scans, scopes, report text, the JSON forms, the strict gate and the destinations file live in new packs modules, one subject each.
This commit is contained in:
1 parent
1e95a73a4d
commit
6ba52a9682
21 files changed
+897
-774
No files matched your search
+9
-3
@@ -24,10 +24,16 @@ COMMANDS = {
|
||||
),
|
||||
"verify.py": (
|
||||
"packs/verdicts.py", "packs/gaps.py", "packs/coverage.py", "packs/emulatorcheck.py",
|
||||
"packs/report.py",
|
||||
"packs/report.py", "packs/verifyplatforms.py", "packs/verifysummary.py",
|
||||
"packs/verifyoutput.py", "packs/strictgate.py",
|
||||
),
|
||||
"cross_reference.py": (
|
||||
"packs/crossref.py", "packs/crossrefscope.py", "packs/crossrefrun.py",
|
||||
"packs/crossreflaunchers.py", "packs/crossreftext.py",
|
||||
),
|
||||
"slots.py": (
|
||||
"packs/slots.py", "resolve/collisions.py", "packs/slotscan.py", "packs/slotreport.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",),
|
||||
|
||||
@@ -572,7 +572,7 @@ class VerboseAppliesToJson(unittest.TestCase):
|
||||
|
||||
def test_every_json_branch_reads_the_flag(self):
|
||||
source = script_source("verify.py")
|
||||
self.assertEqual(source.count("_json_details("), 4)
|
||||
self.assertEqual(source.count("json_details("), 4)
|
||||
self.assertNotIn('if d["status"] != Status.OK\n ]', source)
|
||||
|
||||
|
||||
@@ -5391,7 +5391,7 @@ class VerifyAllSummaryNamesWhatIsWrong(unittest.TestCase):
|
||||
say which platform carried it."""
|
||||
|
||||
def test_counts_carry_platforms_and_core_misses(self):
|
||||
import verify
|
||||
from packs import verifysummary
|
||||
from packs import verdicts
|
||||
|
||||
clean = {"severity_counts": {}, "undeclared_files": []}
|
||||
@@ -5403,7 +5403,7 @@ class VerifyAllSummaryNamesWhatIsWrong(unittest.TestCase):
|
||||
"category": "bios", "in_pack": True,
|
||||
}],
|
||||
}
|
||||
summary = verify._overall_summary(
|
||||
summary = verifysummary.overall_summary(
|
||||
[(clean, ["RetroArch"]), (warned, ["RetroDECK"]), (core_miss, ["ROCKNIX"])]
|
||||
)
|
||||
self.assertIn("1 warning (RetroDECK 1)", summary)
|
||||
@@ -5413,7 +5413,7 @@ class VerifyAllSummaryNamesWhatIsWrong(unittest.TestCase):
|
||||
def test_a_file_missing_on_several_platforms_is_counted_once(self):
|
||||
"""sfiii2a.zip missing on 15 platforms read '24 core file(s)' for 10
|
||||
distinct files, the name printed 15 times on one line."""
|
||||
import verify
|
||||
from packs import verifysummary
|
||||
|
||||
def missing(*names: str) -> dict:
|
||||
return {"severity_counts": {}, "undeclared_files": [
|
||||
@@ -5421,7 +5421,7 @@ class VerifyAllSummaryNamesWhatIsWrong(unittest.TestCase):
|
||||
"category": "bios", "in_pack": True} for name in names
|
||||
]}
|
||||
|
||||
summary = verify._overall_summary([
|
||||
summary = verifysummary.overall_summary([
|
||||
(missing("sfiii2a.zip"), ["Batocera"]),
|
||||
(missing("sfiii2a.zip", "ROM"), ["RetroPie"]),
|
||||
(missing("sfiii2a.zip"), ["RomM"]),
|
||||
@@ -5462,13 +5462,13 @@ class BundledFilesAreNotToSource(unittest.TestCase):
|
||||
listed among the files to source, with 19 more like it."""
|
||||
|
||||
def test_verify_does_not_count_it_missing(self):
|
||||
import verify
|
||||
from packs import verifysummary
|
||||
from packs import report as packs_report
|
||||
|
||||
entry = {"name": "n64.psh", "required": True, "in_repo": False,
|
||||
"category": "bios", "in_pack": True, "bundled": True}
|
||||
self.assertEqual(packs_report.core_required_missing([entry]), [])
|
||||
summary = verify._overall_summary(
|
||||
summary = verifysummary.overall_summary(
|
||||
[({"severity_counts": {}, "undeclared_files": [entry]}, ["ROCKNIX"])]
|
||||
)
|
||||
self.assertNotIn("n64.psh", summary)
|
||||
@@ -6391,13 +6391,13 @@ class StrictFailsOnMissingOnly(unittest.TestCase):
|
||||
but a rejected file is UNTESTED, a warning, and --strict never saw it."""
|
||||
|
||||
def test_the_contract(self):
|
||||
from scripts import verify as verify_mod
|
||||
from scripts.packs.strictgate import platform_strict_failure
|
||||
from scripts.packs.verdicts import Severity
|
||||
|
||||
verify_mod._exit_if_strict(True, [{"severity_counts": {Severity.WARNING: 2}}])
|
||||
with self.assertRaises(SystemExit), contextlib.redirect_stderr(io.StringIO()):
|
||||
verify_mod._exit_if_strict(True, [{"severity_counts": {Severity.CRITICAL: 1}}])
|
||||
self.assertNotIn("or rejected", verify_mod._exit_if_strict.__doc__)
|
||||
self.assertIsNone(platform_strict_failure([{"severity_counts": {Severity.WARNING: 2}}]))
|
||||
self.assertIsNotNone(
|
||||
platform_strict_failure([{"severity_counts": {Severity.CRITICAL: 1}}]))
|
||||
self.assertNotIn("or rejected", platform_strict_failure.__doc__)
|
||||
|
||||
|
||||
class TheRepairCommandWritesTheFileNamed(unittest.TestCase):
|
||||
@@ -6465,7 +6465,7 @@ class AHashScanningCoreContradictsNoPlatform(unittest.TestCase):
|
||||
def test_no_conflict_names_ares(self):
|
||||
import json
|
||||
|
||||
from scripts import slots
|
||||
from scripts.packs import slotscan
|
||||
from scripts.model.registry import list_registered_platforms
|
||||
from scripts.model.profiles import load_emulator_profiles
|
||||
|
||||
@@ -6477,7 +6477,7 @@ class AHashScanningCoreContradictsNoPlatform(unittest.TestCase):
|
||||
claimed = [
|
||||
(platform, conflict.destination)
|
||||
for platform in list_registered_platforms(str(root / "platforms"))
|
||||
for conflict in slots.scan_platform(platform, profiles, db, str(root / "platforms"))
|
||||
for conflict in slotscan.scan_platform(platform, profiles, db, str(root / "platforms"))
|
||||
if any(claim.emulator == "ares" for claim in conflict.profile_claims)
|
||||
]
|
||||
self.assertEqual(claimed, [])
|
||||
|
||||
@@ -17,7 +17,7 @@ import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from packs.crossref import build_supplemental_index, cross_reference, entry_source
|
||||
from cross_reference import print_report
|
||||
from packs.crossreftext import print_report
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
+3
-4
@@ -6896,15 +6896,14 @@ class OneOfASearchList(unittest.TestCase):
|
||||
"""second.bin used to read required: false beside a required
|
||||
first.bin: the set is required and held, so nothing is critical
|
||||
for it, and the strict exit names only the set nobody holds."""
|
||||
from verify import _exit_if_strict_emulator
|
||||
from packs.strictgate import emulator_strict_failure
|
||||
|
||||
result = self._verify()
|
||||
critical = [d["name"] for d in result["details"]
|
||||
if d["status"] == "missing" and d["required"]]
|
||||
self.assertEqual(critical, ["none_a.bin"])
|
||||
with self.assertRaises(SystemExit), contextlib.redirect_stderr(io.StringIO()) as err:
|
||||
_exit_if_strict_emulator(True, result)
|
||||
self.assertIn("1 required file(s) missing: none_a.bin", err.getvalue())
|
||||
self.assertIn("1 required file(s) missing: none_a.bin",
|
||||
emulator_strict_failure(result) or "")
|
||||
|
||||
def test_pack_and_verify_agree(self):
|
||||
from packs.emulatorpack import generate_emulator_pack
|
||||
|
||||
@@ -27,12 +27,13 @@ from unittest import mock
|
||||
|
||||
import yaml
|
||||
|
||||
import verify
|
||||
from packs import coverage
|
||||
from packs import report as packs_report
|
||||
from model.profiles import emulator_profiles_cache, load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
from cross_reference import LAUNCHER_READS_KEY, LAUNCHER_UNPROVEN_KEY, print_launcher_reads
|
||||
from packs.crossreflaunchers import LAUNCHER_READS_KEY, LAUNCHER_UNPROVEN_KEY
|
||||
from packs.crossreftext import print_launcher_reads
|
||||
from packs.strictgate import platform_strict_failure
|
||||
from packs.crossref import launcher_file_names, launcher_reads_not_held
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -298,16 +299,10 @@ class LauncherGapTest(unittest.TestCase):
|
||||
{"absent.bin", "mixed.rom", "labelled.rom", "user.sf2"})
|
||||
self.assertEqual(with_rows, without)
|
||||
|
||||
def exit_code(result: dict) -> int:
|
||||
try:
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
verify._exit_if_strict(True, [result])
|
||||
except SystemExit as exc:
|
||||
return int(exc.code or 0)
|
||||
return 0
|
||||
|
||||
self.assertEqual(exit_code({**with_rows, "launcher_reads_not_held": rows}),
|
||||
exit_code(without))
|
||||
self.assertEqual(
|
||||
platform_strict_failure([{**with_rows, "launcher_reads_not_held": rows}]),
|
||||
platform_strict_failure([without]),
|
||||
)
|
||||
|
||||
def test_verify_prints_a_count_and_lists_on_verbose(self) -> None:
|
||||
result = coverage.verify_platform(
|
||||
|
||||
+11
-10
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import tests
|
||||
|
||||
import inspect
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
@@ -12,11 +13,11 @@ import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import slots
|
||||
from packs import slotreport
|
||||
from packs import slots as packs_slots
|
||||
from resolve import collisions as resolve_collisions
|
||||
from packs.slots import Claim, Conflict, arbitrate
|
||||
from slots import format_decision
|
||||
from packs.slotreport import format_decision
|
||||
from tests.sources import script_source
|
||||
|
||||
|
||||
@@ -346,7 +347,7 @@ class TestConflicts(unittest.TestCase):
|
||||
conflicts = packs_slots.find_conflicts(
|
||||
self._config("m" * 32), self._profile("GC/JAP/IPL.bin"), REGIONS_DB
|
||||
)
|
||||
line = slots.format_conflict(conflicts[0])
|
||||
line = slotreport.format_conflict(conflicts[0])
|
||||
self.assertIn("USA/IPL.bin", line)
|
||||
self.assertIn("JAP/IPL.bin", line)
|
||||
self.assertIn("dolphin", line)
|
||||
@@ -443,12 +444,12 @@ class TestArbitration(unittest.TestCase):
|
||||
self.assertEqual(served, decision.winner.local_path)
|
||||
|
||||
def test_the_reported_line_gives_the_ground_for_the_decision(self):
|
||||
kept = slots.format_decision(packs_slots.arbitrate(self._conflict(), "md5"))
|
||||
kept = slotreport.format_decision(packs_slots.arbitrate(self._conflict(), "md5"))
|
||||
self.assertIn("verifies content", kept)
|
||||
# A fact about each layer, no verdict on the platform's list.
|
||||
self.assertIn("the file dolphin reads", kept)
|
||||
self.assertNotIn("wrong", slots.__loader__.get_source("slots").lower())
|
||||
served = slots.format_decision(packs_slots.arbitrate(self._conflict(), "existence"))
|
||||
self.assertNotIn("wrong", inspect.getsource(slotreport).lower())
|
||||
served = slotreport.format_decision(packs_slots.arbitrate(self._conflict(), "existence"))
|
||||
self.assertIn("both are satisfied", served)
|
||||
|
||||
def test_each_emulator_is_given_the_file_it_reads(self):
|
||||
@@ -461,7 +462,7 @@ class TestArbitration(unittest.TestCase):
|
||||
packs_slots.Claim("profile", "neocdz.zip", "neocdz.zip", emulator="geolith",
|
||||
local_path="b/neocdz.zip.712816a3", status="md5_exact"),
|
||||
]
|
||||
kept = slots.format_decision(packs_slots.arbitrate(conflict, "md5"))
|
||||
kept = slotreport.format_decision(packs_slots.arbitrate(conflict, "md5"))
|
||||
self.assertIn("a/neocdz.zip.ba20a7be, the file fbneo reads", kept)
|
||||
self.assertIn("b/neocdz.zip.712816a3, the file geolith reads", kept)
|
||||
self.assertEqual(conflict.files_read(), [
|
||||
@@ -510,7 +511,7 @@ class TestBuilderAndVerifierAgree(unittest.TestCase):
|
||||
self.assertNotIn("decision.serves_both", text, source.name)
|
||||
self.assertIn(
|
||||
"decision.serves_both",
|
||||
(scripts / "slots.py").read_text(encoding="utf-8"),
|
||||
(scripts / "packs" / "slotreport.py").read_text(encoding="utf-8"),
|
||||
)
|
||||
|
||||
def test_neither_reimplements_the_mode_test(self):
|
||||
@@ -554,7 +555,7 @@ class TestSelfContradictingDestinations(unittest.TestCase):
|
||||
"md5": "n" * 32}]},
|
||||
}}
|
||||
collision = resolve_collisions.find_collisions(config, REGIONS_DB)[0]
|
||||
line = slots.format_collision(collision)
|
||||
line = slotreport.format_collision(collision)
|
||||
left, packed = collision.resolved
|
||||
# The builder walks the systems sorted: alpha's declaration ships.
|
||||
self.assertIn(f"{packed} (alpha) packed", line)
|
||||
@@ -633,7 +634,7 @@ class TestSelfContradictingDestinations(unittest.TestCase):
|
||||
{"name": "IPL.bin", "destination": "disk.rom", "md5": "m" * 32},
|
||||
{"name": "IPL.bin", "destination": "disk.rom", "md5": "n" * 32},
|
||||
)
|
||||
line = slots.format_collision(resolve_collisions.find_collisions(config, REGIONS_DB)[0])
|
||||
line = slotreport.format_collision(resolve_collisions.find_collisions(config, REGIONS_DB)[0])
|
||||
self.assertIn("USA/IPL.bin", line)
|
||||
self.assertIn("JAP/IPL.bin", line)
|
||||
|
||||
|
||||
@@ -222,9 +222,7 @@ class CrossReferenceReadsTheTargetAcrossPlatforms(unittest.TestCase):
|
||||
each narrowed to the cores it builds for it."""
|
||||
|
||||
def test_the_scope_is_the_union_of_each_platforms_target_cores(self):
|
||||
import argparse
|
||||
|
||||
import cross_reference
|
||||
from packs.crossrefscope import tree_scope
|
||||
from model.platforms import load_platform_config
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.registry import list_registered_platforms
|
||||
@@ -232,9 +230,8 @@ class CrossReferenceReadsTheTargetAcrossPlatforms(unittest.TestCase):
|
||||
|
||||
platforms_dir = str(REPO_ROOT / "platforms")
|
||||
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
args = argparse.Namespace(platform=None, target="switch", platforms_dir=platforms_dir)
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
tree = cross_reference._tree_scope(args, profiles)
|
||||
tree = tree_scope(None, "switch", platforms_dir, profiles)
|
||||
cache, kept = build_target_cores_cache(
|
||||
list_registered_platforms(platforms_dir), "switch", platforms_dir, is_all=True,
|
||||
)
|
||||
|
||||
@@ -24,10 +24,10 @@ import diff_truth
|
||||
import pipeline
|
||||
from orchestrate import guards, labels, prepare, runner
|
||||
from resolve import truth
|
||||
import verify
|
||||
from packs import coverage
|
||||
from packs import report as packs_report
|
||||
from packs import verdicts
|
||||
from packs import verifysummary
|
||||
from tests.sources import script_source
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -527,7 +527,7 @@ class TheVerifySummaryCountsDiscrepancies(unittest.TestCase):
|
||||
"discrepancy": "unmet"},
|
||||
{"system": "arcade", "name": "x.zip", "status": verdicts.Status.MISSING},
|
||||
]
|
||||
summary = verify._overall_summary([
|
||||
summary = verifysummary.overall_summary([
|
||||
({"severity_counts": {}, "details": details}, ["RetroArch"]),
|
||||
({"severity_counts": {}, "details": []}, ["Batocera"]),
|
||||
])
|
||||
@@ -552,7 +552,7 @@ class EveryPlatformInTheSummaryCarriesItsCount(unittest.TestCase):
|
||||
def test_a_count_of_one_is_written(self):
|
||||
one = {"severity_counts": {verdicts.Severity.WARNING: 1}, "details": []}
|
||||
two = {"severity_counts": {verdicts.Severity.WARNING: 2}, "details": []}
|
||||
summary = verify._overall_summary([(two, ["Lakka"]), (one, ["ROCKNIX"])])
|
||||
summary = verifysummary.overall_summary([(two, ["Lakka"]), (one, ["ROCKNIX"])])
|
||||
self.assertIn("3 warning (Lakka 2, ROCKNIX 1)", summary)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user