mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: move profile selection into profiling
select_profiles and version_selection go to profiling.selection, the flag refusals to profiling.flagchecks. main calls selection, quota and the profile loader through their modules, so tests patch them there. generate_truth's parse_args becomes build_parser.
This commit is contained in:
1 parent
8afccc3d0f
commit
b520e48798
8 files changed
+241
-219
No files matched your search
@@ -30,7 +30,7 @@ yaml = require_yaml()
|
||||
DEFAULT_OUTPUT_DIR = TRUTH_DIR
|
||||
|
||||
|
||||
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(
|
||||
allow_abbrev=False,
|
||||
description="Generate ground-truth YAML from emulator profiles",
|
||||
@@ -50,11 +50,11 @@ def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
||||
help="hardware target filter",
|
||||
)
|
||||
add_repo_inputs(parser, "platforms", "emulators", "db")
|
||||
return parser.parse_args(argv)
|
||||
return parser
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> None:
|
||||
args = parse_args(argv)
|
||||
args = build_parser().parse_args(argv)
|
||||
require_directory(args.platforms_dir, "--platforms-dir")
|
||||
|
||||
registry = load_platform_registry(args.platforms_dir, required=True)
|
||||
|
||||
+10
-193
@@ -16,16 +16,16 @@ import sys
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from core import upstream
|
||||
from model.systems import norm_system_id, system_index
|
||||
from model.profiles import ProfileSelectionError, is_emulator, load_emulator_profiles, resolve_profile_name
|
||||
from core.cli import add_repo_inputs, suggest_names
|
||||
from model import profiles as emulator_profiles
|
||||
from core.cli import add_repo_inputs
|
||||
from profiling import quota, selection
|
||||
from profiling.bump import DEFAULT_CACHE
|
||||
from profiling.quota import check_quota
|
||||
from profiling.flagchecks import refuse_flag_combinations
|
||||
from profiling.realignpass import run_realign
|
||||
from profiling.run import emit_reports, read_selected
|
||||
from profiling.sourcepaths import refresh_source_paths
|
||||
from profiling.versioncheck import run_versions
|
||||
from profiling.worktree import branch_profiles, project_base, refuse_dirty_tree
|
||||
from profiling.worktree import refuse_dirty_tree
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
@@ -179,203 +179,20 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
return parser
|
||||
|
||||
|
||||
def select_profiles(profiles: dict, args: argparse.Namespace) -> dict:
|
||||
"""Profiles matching the selection flags."""
|
||||
if args.changed or args.added:
|
||||
base = args.base or project_base()
|
||||
names = branch_profiles(args.emulators_dir, base, args.added)
|
||||
selected = {name: profiles[name] for name in names if name in profiles}
|
||||
if not selected:
|
||||
verb = "adds" if args.added else "adds or edits"
|
||||
print(f"the branch {verb} no profile against {base}", file=sys.stderr)
|
||||
return selected
|
||||
if args.emulator:
|
||||
requested = [args.emulator] if isinstance(args.emulator, str) else args.emulator
|
||||
try:
|
||||
names = [
|
||||
resolve_profile_name(name, profiles, "python scripts/verify.py --list-emulators")
|
||||
for name in requested
|
||||
]
|
||||
except ProfileSelectionError as exc:
|
||||
raise SystemExit(f"ERROR: {exc}") from None
|
||||
return {name: profiles[name] for name in dict.fromkeys(names)}
|
||||
|
||||
# --system matches as verify.py --list-systems lists and --system selects:
|
||||
# by normalized id, so `saturn` reaches the profiles declaring sega-saturn.
|
||||
wanted_system = norm_system_id(args.system) if args.system else None
|
||||
selected = {}
|
||||
for name, profile in sorted(profiles.items()):
|
||||
if not is_emulator(profile):
|
||||
continue
|
||||
if wanted_system and wanted_system not in {
|
||||
norm_system_id(str(s)) for s in profile.get("systems") or []
|
||||
}:
|
||||
continue
|
||||
if args.type_ and profile.get("type") != args.type_:
|
||||
continue
|
||||
if args.stale_before:
|
||||
profiled = str(profile.get("profiled_date") or "")
|
||||
if not profiled or profiled >= args.stale_before:
|
||||
continue
|
||||
selected[name] = profile
|
||||
if args.limit and len(selected) >= args.limit:
|
||||
break
|
||||
if not selected:
|
||||
# A misspelt filter selected nothing and the run said nothing: it
|
||||
# read as "no profile of that system needs a re-read".
|
||||
filters = ", ".join(
|
||||
f"{flag} {value}" for flag, value in (
|
||||
("--system", args.system), ("--type", args.type_),
|
||||
("--stale-before", args.stale_before),
|
||||
) if value
|
||||
)
|
||||
hint = ""
|
||||
if args.system:
|
||||
# Suggested from the spellings the named listing prints.
|
||||
systems = sorted(spelling for spelling, _ in system_index(profiles).values())
|
||||
hint = " " + suggest_names([args.system], systems, "python scripts/verify.py --list-systems")
|
||||
elif args.type_:
|
||||
kinds = sorted({str(p.get("type")) for p in profiles.values() if p.get("type")})
|
||||
hint = f" Types: {', '.join(kinds)}."
|
||||
raise SystemExit(f"ERROR: no profile matches {filters or 'the selection'}.{hint}")
|
||||
return selected
|
||||
|
||||
|
||||
def _refuse_flag_combinations(args: argparse.Namespace) -> None:
|
||||
"""Exit on a flag the chosen mode would not apply, before any request."""
|
||||
if args.verify_version or args.set_version:
|
||||
ignored = [
|
||||
flag for flag, on in (
|
||||
("--verify-version", args.verify_version and args.set_version),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
("--strict", args.strict),
|
||||
("--check-version", args.check_version),
|
||||
("--detect-new-files", args.detect_new_files),
|
||||
("--watch-hashes", args.watch_hashes),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
("--backfill-commits", args.backfill_commits),
|
||||
("--rebase-refs", args.rebase_refs),
|
||||
("--attribute-refs", args.attribute_refs),
|
||||
("--bump-commit", args.bump_commit),
|
||||
("--realign-prose", args.realign_prose),
|
||||
("--accept-changed", args.accept_changed),
|
||||
("--dry-run", args.dry_run and not args.set_version),
|
||||
) if on
|
||||
]
|
||||
if ignored:
|
||||
mode = "--set-version" if args.set_version else "--verify-version"
|
||||
print(f"{mode} does not apply {', '.join(ignored)}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
if args.fresh and args.offline:
|
||||
print("--fresh asks the forges again, which --offline forbids.", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
if args.accept_changed and not args.emulator:
|
||||
print(
|
||||
"--accept-changed applies to one profile at a time: its diff has "
|
||||
"to be read before its CHANGED refs can be recaled.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.attribute_refs and (
|
||||
args.rebase_refs or args.bump_commit or args.backfill_commits
|
||||
or args.realign_prose
|
||||
):
|
||||
print(
|
||||
"--attribute-refs runs alone: it rewrites the refs the report was "
|
||||
"built from.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.realign_prose and (
|
||||
args.rebase_refs or args.bump_commit or args.backfill_commits
|
||||
):
|
||||
print(
|
||||
"--realign-prose runs alone: the report has to be rebuilt on the "
|
||||
"realigned text before any other write.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.realign_prose:
|
||||
ignored = [
|
||||
flag for flag, on in (
|
||||
("--json", args.as_json),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
("--changed-only", args.changed_only),
|
||||
("--strict", args.strict),
|
||||
("--check-version", args.check_version),
|
||||
("--detect-new-files", args.detect_new_files),
|
||||
("--watch-hashes", args.watch_hashes),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
("--accept-changed", args.accept_changed),
|
||||
) if on
|
||||
]
|
||||
if ignored:
|
||||
# A mode applies a flag or refuses it, never swallows it.
|
||||
print(
|
||||
f"--realign-prose does not apply {', '.join(ignored)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
machine = [
|
||||
flag for flag, on in (
|
||||
("--json", args.as_json),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
) if on
|
||||
]
|
||||
# The version check lives on the report, so the outputs built from the
|
||||
# report (text, --json, --markdown) carry it. A URL list and a ranking
|
||||
# do not. Detection lives on the report too, and --json carries it for
|
||||
# check_freshness. The markdown table has no column for it.
|
||||
lists_only = args.fetch_plan or args.triage
|
||||
off_json = lists_only or args.markdown
|
||||
extras = [
|
||||
flag for flag, on in (
|
||||
("--check-version", args.check_version and lists_only),
|
||||
("--detect-new-files", args.detect_new_files and off_json),
|
||||
("--watch-hashes", args.watch_hashes and off_json),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
) if on
|
||||
]
|
||||
if machine and extras:
|
||||
# The extra sections only exist in the text report. The other outputs
|
||||
# returned before reaching them and printed as if never asked.
|
||||
print(
|
||||
f"{', '.join(machine)} does not carry {', '.join(extras)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def _version_selection(args: argparse.Namespace, profiles: dict) -> dict:
|
||||
"""--all reaches the alias and test profiles too: each states a version."""
|
||||
if args.all and not (args.system or args.type_ or args.stale_before or args.limit):
|
||||
return dict(sorted(profiles.items()))
|
||||
return select_profiles(profiles, args)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Build one report per selected profile, then apply writes and output."""
|
||||
args = build_parser().parse_args()
|
||||
_refuse_flag_combinations(args)
|
||||
refuse_flag_combinations(args)
|
||||
if args.fresh:
|
||||
# Tips cached before an upstream commit hid it for six hours: EKA2L1,
|
||||
# trzy/Supermodel and VICE read as behind their real HEAD.
|
||||
upstream.MOVING_TTL = 0
|
||||
profiles = load_emulator_profiles(args.emulators_dir, skip_aliases=False)
|
||||
profiles = emulator_profiles.load_emulator_profiles(args.emulators_dir, skip_aliases=False)
|
||||
if args.verify_version or args.set_version:
|
||||
run_versions(args, profiles, _version_selection(args, profiles))
|
||||
run_versions(args, profiles, selection.version_selection(args, profiles))
|
||||
return
|
||||
selected = select_profiles(profiles, args)
|
||||
check_quota(len(selected), args.offline)
|
||||
selected = selection.select_profiles(profiles, args)
|
||||
quota.check_quota(len(selected), args.offline)
|
||||
|
||||
writes = (
|
||||
args.backfill_commits or args.rebase_refs or args.bump_commit
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
"""The flag combinations a profile pass refuses before any request."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
def refuse_flag_combinations(args: argparse.Namespace) -> None:
|
||||
"""Exit on a flag the chosen mode would not apply, before any request."""
|
||||
if args.verify_version or args.set_version:
|
||||
ignored = [
|
||||
flag for flag, on in (
|
||||
("--verify-version", args.verify_version and args.set_version),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
("--strict", args.strict),
|
||||
("--check-version", args.check_version),
|
||||
("--detect-new-files", args.detect_new_files),
|
||||
("--watch-hashes", args.watch_hashes),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
("--backfill-commits", args.backfill_commits),
|
||||
("--rebase-refs", args.rebase_refs),
|
||||
("--attribute-refs", args.attribute_refs),
|
||||
("--bump-commit", args.bump_commit),
|
||||
("--realign-prose", args.realign_prose),
|
||||
("--accept-changed", args.accept_changed),
|
||||
("--dry-run", args.dry_run and not args.set_version),
|
||||
) if on
|
||||
]
|
||||
if ignored:
|
||||
mode = "--set-version" if args.set_version else "--verify-version"
|
||||
print(f"{mode} does not apply {', '.join(ignored)}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
if args.fresh and args.offline:
|
||||
print("--fresh asks the forges again, which --offline forbids.", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
if args.accept_changed and not args.emulator:
|
||||
print(
|
||||
"--accept-changed applies to one profile at a time: its diff has "
|
||||
"to be read before its CHANGED refs can be recaled.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.attribute_refs and (
|
||||
args.rebase_refs or args.bump_commit or args.backfill_commits
|
||||
or args.realign_prose
|
||||
):
|
||||
print(
|
||||
"--attribute-refs runs alone: it rewrites the refs the report was "
|
||||
"built from.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.realign_prose and (
|
||||
args.rebase_refs or args.bump_commit or args.backfill_commits
|
||||
):
|
||||
print(
|
||||
"--realign-prose runs alone: the report has to be rebuilt on the "
|
||||
"realigned text before any other write.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.realign_prose:
|
||||
ignored = [
|
||||
flag for flag, on in (
|
||||
("--json", args.as_json),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
("--changed-only", args.changed_only),
|
||||
("--strict", args.strict),
|
||||
("--check-version", args.check_version),
|
||||
("--detect-new-files", args.detect_new_files),
|
||||
("--watch-hashes", args.watch_hashes),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
("--accept-changed", args.accept_changed),
|
||||
) if on
|
||||
]
|
||||
if ignored:
|
||||
# A mode applies a flag or refuses it, never swallows it.
|
||||
print(
|
||||
f"--realign-prose does not apply {', '.join(ignored)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
machine = [
|
||||
flag for flag, on in (
|
||||
("--json", args.as_json),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
) if on
|
||||
]
|
||||
# The version check lives on the report, so the outputs built from the
|
||||
# report (text, --json, --markdown) carry it. A URL list and a ranking
|
||||
# do not. Detection lives on the report too, and --json carries it for
|
||||
# check_freshness. The markdown table has no column for it.
|
||||
lists_only = args.fetch_plan or args.triage
|
||||
off_json = lists_only or args.markdown
|
||||
extras = [
|
||||
flag for flag, on in (
|
||||
("--check-version", args.check_version and lists_only),
|
||||
("--detect-new-files", args.detect_new_files and off_json),
|
||||
("--watch-hashes", args.watch_hashes and off_json),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
) if on
|
||||
]
|
||||
if machine and extras:
|
||||
# The extra sections only exist in the text report. The other outputs
|
||||
# returned before reaching them and printed as if never asked.
|
||||
print(
|
||||
f"{', '.join(machine)} does not carry {', '.join(extras)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
@@ -0,0 +1,80 @@
|
||||
"""The profiles a profile pass selects from its command line."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from core.cli import suggest_names
|
||||
from model.profiles import ProfileSelectionError, is_emulator, resolve_profile_name
|
||||
from model.systems import norm_system_id, system_index
|
||||
from profiling.worktree import branch_profiles, project_base
|
||||
|
||||
|
||||
def select_profiles(profiles: dict, args: argparse.Namespace) -> dict:
|
||||
"""Profiles matching the selection flags."""
|
||||
if args.changed or args.added:
|
||||
base = args.base or project_base()
|
||||
names = branch_profiles(args.emulators_dir, base, args.added)
|
||||
selected = {name: profiles[name] for name in names if name in profiles}
|
||||
if not selected:
|
||||
verb = "adds" if args.added else "adds or edits"
|
||||
print(f"the branch {verb} no profile against {base}", file=sys.stderr)
|
||||
return selected
|
||||
if args.emulator:
|
||||
requested = [args.emulator] if isinstance(args.emulator, str) else args.emulator
|
||||
try:
|
||||
names = [
|
||||
resolve_profile_name(name, profiles, "python scripts/verify.py --list-emulators")
|
||||
for name in requested
|
||||
]
|
||||
except ProfileSelectionError as exc:
|
||||
raise SystemExit(f"ERROR: {exc}") from None
|
||||
return {name: profiles[name] for name in dict.fromkeys(names)}
|
||||
|
||||
# --system matches as verify.py --list-systems lists and --system selects:
|
||||
# by normalized id, so `saturn` reaches the profiles declaring sega-saturn.
|
||||
wanted_system = norm_system_id(args.system) if args.system else None
|
||||
selected = {}
|
||||
for name, profile in sorted(profiles.items()):
|
||||
if not is_emulator(profile):
|
||||
continue
|
||||
if wanted_system and wanted_system not in {
|
||||
norm_system_id(str(s)) for s in profile.get("systems") or []
|
||||
}:
|
||||
continue
|
||||
if args.type_ and profile.get("type") != args.type_:
|
||||
continue
|
||||
if args.stale_before:
|
||||
profiled = str(profile.get("profiled_date") or "")
|
||||
if not profiled or profiled >= args.stale_before:
|
||||
continue
|
||||
selected[name] = profile
|
||||
if args.limit and len(selected) >= args.limit:
|
||||
break
|
||||
if not selected:
|
||||
# A misspelt filter selected nothing and the run said nothing: it
|
||||
# read as "no profile of that system needs a re-read".
|
||||
filters = ", ".join(
|
||||
f"{flag} {value}" for flag, value in (
|
||||
("--system", args.system), ("--type", args.type_),
|
||||
("--stale-before", args.stale_before),
|
||||
) if value
|
||||
)
|
||||
hint = ""
|
||||
if args.system:
|
||||
# Suggested from the spellings the named listing prints.
|
||||
systems = sorted(spelling for spelling, _ in system_index(profiles).values())
|
||||
hint = " " + suggest_names([args.system], systems, "python scripts/verify.py --list-systems")
|
||||
elif args.type_:
|
||||
kinds = sorted({str(p.get("type")) for p in profiles.values() if p.get("type")})
|
||||
hint = f" Types: {', '.join(kinds)}."
|
||||
raise SystemExit(f"ERROR: no profile matches {filters or 'the selection'}.{hint}")
|
||||
return selected
|
||||
|
||||
|
||||
def version_selection(args: argparse.Namespace, profiles: dict) -> dict:
|
||||
"""--all reaches the alias and test profiles too: each states a version."""
|
||||
if args.all and not (args.system or args.type_ or args.stale_before or args.limit):
|
||||
return dict(sorted(profiles.items()))
|
||||
return select_profiles(profiles, args)
|
||||
+2
-1
@@ -154,8 +154,9 @@ COMMANDS = {
|
||||
"profiling/yamledit.py", "profiling/proseedit.py", "profiling/rebase.py",
|
||||
"profiling/bump.py", "profiling/realign.py", "profiling/run.py", "profiling/worktree.py",
|
||||
"profiling/quota.py", "profiling/sourcepaths.py", "profiling/realignpass.py",
|
||||
"profiling/versioncheck.py",
|
||||
"profiling/versioncheck.py", "profiling/selection.py", "profiling/flagchecks.py",
|
||||
),
|
||||
"generate_truth.py": ("resolve/truth.py",),
|
||||
"diff_truth.py": ("exporter/truthdiff.py", "exporter/diffreport.py"),
|
||||
"fetch_site_images.py": ("sitegen/imagefetch.py", "sitegen/imagenormalize.py"),
|
||||
"make_site_icons.py": ("sitegen/brand.py", "sitegen/chromium.py"),
|
||||
|
||||
@@ -636,6 +636,7 @@ class ProfileSummaryTests(unittest.TestCase):
|
||||
"""--json with the detection flags was refused, so --profiles read an
|
||||
empty stdout and reported "unreadable report" on every run."""
|
||||
import profile_sync
|
||||
from profiling.flagchecks import refuse_flag_combinations
|
||||
|
||||
captured = []
|
||||
|
||||
@@ -647,7 +648,7 @@ class ProfileSummaryTests(unittest.TestCase):
|
||||
check_profiles(True, offline=True)
|
||||
(cmd,) = captured
|
||||
args = profile_sync.build_parser().parse_args(cmd[2:])
|
||||
profile_sync._refuse_flag_combinations(args)
|
||||
refuse_flag_combinations(args)
|
||||
self.assertTrue(args.as_json)
|
||||
|
||||
def test_a_non_list_report_is_an_error_not_a_crash(self):
|
||||
|
||||
+22
-19
@@ -34,6 +34,9 @@ from profiling import sourcepaths as profiling_sourcepaths
|
||||
from profiling import worktree as profiling_worktree
|
||||
from profiling import triage
|
||||
from profiling import versions
|
||||
from profiling import quota as profiling_quota
|
||||
from profiling import selection as profiling_selection
|
||||
from model import profiles as model_profiles
|
||||
from model import sourceref
|
||||
from profiling.reports import (
|
||||
EntryReport,
|
||||
@@ -53,7 +56,8 @@ from profiling.yamledit import (
|
||||
insert_after_line,
|
||||
replace_field_line,
|
||||
)
|
||||
from profile_sync import build_parser, select_profiles
|
||||
from profile_sync import build_parser
|
||||
from profiling.selection import select_profiles
|
||||
from profiling.resolver import build_report
|
||||
from profiling.bump import bump_commit
|
||||
from profiling.citations import collect_citations, collect_tokens
|
||||
@@ -5127,10 +5131,10 @@ class TestRateLimitEndsOneProfile(unittest.TestCase):
|
||||
saved = sys.argv
|
||||
try:
|
||||
sys.argv = ["profile_sync.py", "--all", "--json"]
|
||||
with mock.patch.object(profile_sync, "load_emulator_profiles", return_value={}), \
|
||||
mock.patch.object(profile_sync, "select_profiles",
|
||||
with mock.patch.object(model_profiles, "load_emulator_profiles", return_value={}), \
|
||||
mock.patch.object(profiling_selection, "select_profiles",
|
||||
return_value={"cemu": {}, "after": {}}), \
|
||||
mock.patch.object(profile_sync, "check_quota"), \
|
||||
mock.patch.object(profiling_quota, "check_quota"), \
|
||||
mock.patch.object(profiling_run, "build_report", side_effect=build), \
|
||||
contextlib.redirect_stdout(out), \
|
||||
contextlib.redirect_stderr(err), \
|
||||
@@ -5178,7 +5182,6 @@ class AWriteRefreshesTheSourcePaths(unittest.TestCase):
|
||||
# before writing them: the record kept the pins it had replaced.
|
||||
from unittest import mock
|
||||
|
||||
from model import profiles as model_profiles
|
||||
from model.profiles import emulator_profiles_cache
|
||||
from sitegen import sources
|
||||
|
||||
@@ -5261,10 +5264,10 @@ class TestOutputModesApplyTheirFlags(unittest.TestCase):
|
||||
saved = sys.argv
|
||||
try:
|
||||
sys.argv = ["profile_sync.py", "--all", *argv]
|
||||
with mock.patch.object(profile_sync, "load_emulator_profiles", return_value={}), \
|
||||
mock.patch.object(profile_sync, "select_profiles",
|
||||
with mock.patch.object(model_profiles, "load_emulator_profiles", return_value={}), \
|
||||
mock.patch.object(profiling_selection, "select_profiles",
|
||||
return_value={"clean": {}, "drift": {}}), \
|
||||
mock.patch.object(profile_sync, "check_quota"), \
|
||||
mock.patch.object(profiling_quota, "check_quota"), \
|
||||
mock.patch.object(profiling_run, "build_report",
|
||||
side_effect=lambda name, *a, **k: reports[name]), \
|
||||
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
@@ -5369,10 +5372,10 @@ class TestOutputModesApplyTheirFlags(unittest.TestCase):
|
||||
saved = sys.argv
|
||||
try:
|
||||
sys.argv = ["profile_sync.py", "--all", "--changed-only", "--json"]
|
||||
with mock.patch.object(profile_sync, "load_emulator_profiles", return_value={}), \
|
||||
mock.patch.object(profile_sync, "select_profiles",
|
||||
with mock.patch.object(model_profiles, "load_emulator_profiles", return_value={}), \
|
||||
mock.patch.object(profiling_selection, "select_profiles",
|
||||
return_value={"clean": {}, "drift": {}}), \
|
||||
mock.patch.object(profile_sync, "check_quota"), \
|
||||
mock.patch.object(profiling_quota, "check_quota"), \
|
||||
mock.patch.object(profiling_run, "build_report", side_effect=build), \
|
||||
contextlib.redirect_stdout(out), \
|
||||
contextlib.redirect_stderr(io.StringIO()), \
|
||||
@@ -5800,16 +5803,16 @@ class TestSelectionNamesWhatMatchedNothing(unittest.TestCase):
|
||||
|
||||
def test_a_misspelt_system_stops_and_suggests(self):
|
||||
with self.assertRaises(SystemExit) as caught:
|
||||
profile_sync.select_profiles(self.PROFILES, self._args(system="atari-lynxx"))
|
||||
select_profiles(self.PROFILES, self._args(system="atari-lynxx"))
|
||||
self.assertIn("atari-lynx", str(caught.exception.code))
|
||||
|
||||
def test_a_misspelt_emulator_suggests(self):
|
||||
with self.assertRaises(SystemExit) as caught:
|
||||
profile_sync.select_profiles(self.PROFILES, self._args(emulator="handyy"))
|
||||
select_profiles(self.PROFILES, self._args(emulator="handyy"))
|
||||
self.assertIn("Close matches: handy", str(caught.exception.code))
|
||||
|
||||
def test_a_matching_filter_selects(self):
|
||||
selected = profile_sync.select_profiles(self.PROFILES, self._args(system="atari-lynx"))
|
||||
selected = select_profiles(self.PROFILES, self._args(system="atari-lynx"))
|
||||
self.assertEqual(sorted(selected), ["handy", "mednafen_lynx"])
|
||||
|
||||
def test_system_matches_as_the_listing_does(self):
|
||||
@@ -5820,7 +5823,7 @@ class TestSelectionNamesWhatMatchedNothing(unittest.TestCase):
|
||||
"b": {"type": "libretro", "systems": ["saturn"]},
|
||||
}
|
||||
for spelling in ("saturn", "sega-saturn"):
|
||||
selected = profile_sync.select_profiles(profiles, self._args(system=spelling))
|
||||
selected = select_profiles(profiles, self._args(system=spelling))
|
||||
self.assertEqual(sorted(selected), ["a", "b"])
|
||||
|
||||
def test_the_hint_counts_what_the_listing_prints(self):
|
||||
@@ -5830,7 +5833,7 @@ class TestSelectionNamesWhatMatchedNothing(unittest.TestCase):
|
||||
"c": {"type": "libretro", "systems": ["atari-lynx"]},
|
||||
}
|
||||
with self.assertRaises(SystemExit) as caught:
|
||||
profile_sync.select_profiles(profiles, self._args(system="nothing"))
|
||||
select_profiles(profiles, self._args(system="nothing"))
|
||||
self.assertIn("Known: atari-lynx, sega-saturn.", str(caught.exception.code))
|
||||
|
||||
|
||||
@@ -6168,7 +6171,7 @@ class AnOnlinePassSaysWhereItIs(unittest.TestCase):
|
||||
try:
|
||||
sys.argv = ["profile_sync.py", "--all", "--triage", *argv]
|
||||
with mock.patch.object(profiling_run, "_build_full_report", side_effect=build), \
|
||||
mock.patch.object(profile_sync, "check_quota"), \
|
||||
mock.patch.object(profiling_quota, "check_quota"), \
|
||||
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err), \
|
||||
self.assertRaises(SystemExit) as caught:
|
||||
profile_sync.main()
|
||||
@@ -6318,7 +6321,7 @@ class TestBranchProfiles(unittest.TestCase):
|
||||
args = profile_sync.build_parser().parse_args(["--changed", "--base", "main"])
|
||||
profiles = {"kept": {}, "edited": {}, "new": {}, "draft": {}}
|
||||
self.assertEqual(
|
||||
list(profile_sync.select_profiles(profiles, args)),
|
||||
list(select_profiles(profiles, args)),
|
||||
["draft", "edited", "new"],
|
||||
)
|
||||
|
||||
@@ -6336,7 +6339,7 @@ class TestBranchProfiles(unittest.TestCase):
|
||||
args = profile_sync.build_parser().parse_args(["--changed"])
|
||||
profiles = {"kept": {}, "edited": {}, "new": {}, "draft": {}}
|
||||
self.assertEqual(
|
||||
list(profile_sync.select_profiles(profiles, args)),
|
||||
list(select_profiles(profiles, args)),
|
||||
["draft", "edited", "new"],
|
||||
)
|
||||
|
||||
|
||||
@@ -63,10 +63,10 @@ class ABuildbotNameSelectsItsProfile(unittest.TestCase):
|
||||
"""Both refused pcfx, which verify --emulator accepts."""
|
||||
import argparse
|
||||
|
||||
import profile_sync
|
||||
from profiling.selection import select_profiles
|
||||
|
||||
args = argparse.Namespace(changed=False, added=False, emulator=["pcfx"])
|
||||
self.assertEqual(list(profile_sync.select_profiles(self.PROFILES, args)), ["beetle_pcfx"])
|
||||
self.assertEqual(list(select_profiles(self.PROFILES, args)), ["beetle_pcfx"])
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "scripts/fileless_audit.py", "pcfxx", "--offline"],
|
||||
cwd=REPO_ROOT, capture_output=True, text=True, timeout=600, check=False,
|
||||
|
||||
Reference in new issue
Block a user