chore: merge the installer quality work

This commit is contained in:
Abdessamad Derraz committed 2026-11-17 15:11:43 +01:00
commit 0d0ec442b3
9 files changed
+6155 -4286

No files matched your search

+6073 -4223
View File
File diff suppressed because it is too large. Load diff
+5 -3
View File
@@ -269,10 +269,12 @@ def line_menu() -> str:
+ ([("--no-game-data", None)] if cut[0] else []))
return invocation.command("retroarch", folder)
context = _install.MenuContext(
"retroarch", files, manifest.get("omitted_files") or [], name="RetroArch",
data_trees=manifest.get("data_directories") or [], bios_path=folder,
manifest=manifest)
_install._prompt_custom_selection(
"retroarch", files, manifest.get("omitted_files") or [], None, "RetroArch",
False, manifest.get("data_directories") or [], folder,
_install.records_selection(files), None, manifest, False, command, cut)
context, choosable=_install.records_selection(files), command=command, cut=cut)
return "```\n" + out.getvalue().strip("\n") + "\n```"
+17 -13
View File
@@ -367,12 +367,13 @@ class TestRunOutcome(unittest.TestCase):
omitted=0,
interrupted=False,
)
details = {key: kw.pop(key) for key in list(kw) if key not in defaults}
defaults.update(kw)
buf = io.StringIO()
code = 0
with contextlib.redirect_stdout(buf):
try:
install._report_outcome(**defaults)
install._report_outcome(**defaults, details=install.OutcomeDetails(**details))
except SystemExit as exc:
code = exc.code
return buf.getvalue(), code
@@ -680,11 +681,10 @@ class AFolderThatRefusesWritesIsNamed(unittest.TestCase):
def _summary_for(self, assumed):
buf = io.StringIO()
with contextlib.redirect_stdout(buf), self.assertRaises(SystemExit):
install._report_outcome(
paths=[Path("/userdata/bios")], downloaded=0, up_to_date=0, errors=1,
omitted=0, interrupted=False,
failures=[("neogeo.zip", install.NOT_WRITABLE)], assumed=assumed,
)
install._report_outcome(paths=[Path("/userdata/bios")], downloaded=0, up_to_date=0,
errors=1, omitted=0, interrupted=False,
details=install.OutcomeDetails(failures=[("neogeo.zip", install.NOT_WRITABLE)],
assumed=assumed))
return buf.getvalue()
def test_the_summary_says_sudo_on_the_console_and_dest_elsewhere(self):
@@ -4657,7 +4657,8 @@ class ARefusedStandaloneCopyIsNamed(unittest.TestCase):
out = io.StringIO()
with contextlib.redirect_stdout(out), self.assertRaises(SystemExit):
install._report_outcome([bios], 0, 1, failed, 0, False, failures=failures)
install._report_outcome([bios], 0, 1, failed, 0, False,
details=install.OutcomeDetails(failures=failures))
text = out.getvalue()
self.assertIn(str(target / "scph5501.bin"), text)
self.assertIn(str(target), text.split("BIOS folder")[-1])
@@ -4702,7 +4703,7 @@ class AFullDriveIsSaidAsOne(unittest.TestCase):
out = io.StringIO()
with contextlib.redirect_stdout(out), self.assertRaises(SystemExit) as ended:
install._report_outcome([bios], 7, 0, 1, 0, False,
failures=[("fbneo-cheats", install.DRIVE_FULL)])
details=install.OutcomeDetails(failures=[("fbneo-cheats", install.DRIVE_FULL)]))
text = out.getvalue()
self.assertEqual(ended.exception.code, 1)
self.assertIn("is full: free up space, or install to another drive with --dest", text)
@@ -6227,7 +6228,8 @@ class ANetworkFailureNamesTheNetwork(unittest.TestCase):
("b.bin", install.NetworkReason("Connection reset by peer"))]
out = io.StringIO()
with contextlib.redirect_stdout(out), self.assertRaises(SystemExit) as raised:
install._report_outcome([Path("/bios")], 0, 0, 2, 0, False, failures=failures)
install._report_outcome([Path("/bios")], 0, 0, 2, 0, False,
details=install.OutcomeDetails(failures=failures))
self.assertEqual(raised.exception.code, 2)
text = out.getvalue()
self.assertIn("HTTPS_PROXY", text)
@@ -6246,7 +6248,7 @@ class AnHttpErrorNamesItsAddress(unittest.TestCase):
with unittest.mock.patch.dict(os.environ, env), contextlib.redirect_stdout(out), \
self.assertRaises(SystemExit) as raised:
install._report_outcome([Path("/bios")], 0, 0, len(failures), 0, False,
failures=failures)
details=install.OutcomeDetails(failures=failures))
self.assertEqual(raised.exception.code, 2)
return " ".join(out.getvalue().split())
@@ -6916,14 +6918,14 @@ class SystemEventsFollowTheChoice(unittest.TestCase):
stream = io.StringIO()
install.EVENTS.open(stream)
self.addCleanup(setattr, install.EVENTS, "stream", None)
install._emit_check("retroarch", {}, Path("/b"), files, [], [], 0, 0,
install._emit_check("retroarch", {}, Path("/b"), install.CheckTally(files, [], []),
chosen=["nintendo-gba"])
systems = [json.loads(line)["system"] for line in stream.getvalue().splitlines()
if json.loads(line)["event"] == "system"]
self.assertEqual(systems, ["nintendo-gba"])
stream.seek(0)
stream.truncate()
install._emit_check("retroarch", {}, Path("/b"), files, [], [], 0, 0)
install._emit_check("retroarch", {}, Path("/b"), install.CheckTally(files, [], []))
systems = [json.loads(line)["system"] for line in stream.getvalue().splitlines()
if json.loads(line)["event"] == "system"]
self.assertEqual(systems, ["nintendo-gb", "nintendo-gba"])
@@ -7764,7 +7766,9 @@ class TheListVersionIsComparedWithTheSystems(unittest.TestCase):
buf = io.StringIO()
with contextlib.redirect_stdout(buf), contextlib.suppress(SystemExit):
install._report_outcome([Path("/userdata/bios")], omitted=0,
interrupted=False, notes=["Built for 43.1."],
interrupted=False,
details=install.OutcomeDetails(
notes=["Built for 43.1."]),
**{"downloaded": 0, "up_to_date": 0,
"errors": 0, **kw})
self.assertIn("Built for 43.1.", buf.getvalue())
+2 -1
View File
@@ -472,7 +472,8 @@ class APlatformFileSettledByCoresAndSystems(unittest.TestCase):
def declared_event(files: list[dict]) -> dict:
_todo, fine, wrong = install.check_local(files, tmp)
with mock.patch.object(install.EVENTS, "emit") as emit:
install._emit_check("retroarch", manifest, tmp, files, fine, wrong, 0, 0)
install._emit_check("retroarch", manifest, tmp,
install.CheckTally(files, fine, wrong))
return next(call.kwargs for call in emit.call_args_list
if call.args[0] == "declared")
+11 -11
View File
@@ -342,10 +342,9 @@ class ProgressOutput(unittest.TestCase):
install.OUTPUT.verbose = True
buf = io.StringIO()
with contextlib.redirect_stdout(buf), self.assertRaises(SystemExit):
install._report_outcome(
[Path("/b")], 1, 0, 1, 0, False,
failures=[("x.bin", "HTTP 404")], transferred=2048, seconds=2.0,
)
install._report_outcome([Path("/b")], 1, 0, 1, 0, False,
details=install.OutcomeDetails(failures=[("x.bin", "HTTP 404")],
transferred=2048, seconds=2.0))
out = buf.getvalue()
self.assertIn("failed: x.bin (HTTP 404)", out)
self.assertIn("2.0 KB downloaded in 0:02", out)
@@ -356,10 +355,8 @@ class ProgressOutput(unittest.TestCase):
reason = f"{install.NOT_KEPT} (/sdcard/RetroArch/retrobios-backup belongs to another user)"
buf = io.StringIO()
with contextlib.redirect_stdout(buf), self.assertRaises(SystemExit) as end:
install._report_outcome(
[Path("/b")], 3, 0, 2, 0, False,
failures=[("a.zip", reason), ("b.zip", reason)],
)
install._report_outcome([Path("/b")], 3, 0, 2, 0, False,
details=install.OutcomeDetails(failures=[("a.zip", reason), ("b.zip", reason)]))
out = buf.getvalue()
self.assertEqual(end.exception.code, 1)
self.assertIn("The files in place were left as they were", out)
@@ -400,7 +397,8 @@ class ReviewCases(unittest.TestCase):
def test_declining_is_not_done(self):
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
install._report_outcome([Path("/b")], 0, 3, 0, 0, False, declined=12)
install._report_outcome([Path("/b")], 0, 3, 0, 0, False,
details=install.OutcomeDetails(declined=12))
out = buf.getvalue()
self.assertNotIn("Done.", out)
self.assertIn("12 files not downloaded", out)
@@ -1059,7 +1057,8 @@ class TheEndOfARunPaintsItsStatusWords(unittest.TestCase):
term.colour = colour
out = io.StringIO()
with contextlib.redirect_stdout(out), contextlib.suppress(SystemExit):
install._report_outcome([Path("bios")], *counts, term=term, **given)
install._report_outcome([Path("bios")], *counts, term=term,
details=install.OutcomeDetails(**given))
return out.getvalue()
def test_the_same_words_with_and_without_colour(self):
@@ -1390,7 +1389,8 @@ class TheDryRunWords(unittest.TestCase):
files = [{"dest": "a.bin", "size": 1, "systems": ["x"]}]
with mock.patch.object(install, "_ask", return_value=""), \
contextlib.redirect_stdout(out):
install._prompt_custom_selection("retroarch", files, [], None, "RetroArch",
install._prompt_custom_selection(install.MenuContext("retroarch", files, [],
name="RetroArch"),
dry_run=True)
self.assertNotIn("install everything", out.getvalue())
self.assertIn("nothing is written", out.getvalue())
+5 -3
View File
@@ -1028,9 +1028,11 @@ class LineMenu(GamesTestCase):
out = io.StringIO()
with mock.patch.object(install, "_ask", side_effect=lambda _p: next(replies)), \
contextlib.redirect_stdout(out):
choice = install._prompt_custom_selection(
"retroarch", listed["files"], [], manifest=listed, played=plan, given=given,
command=lambda choice: install._INVOCATION.command("retroarch", "<dest>"))
choice = install._prompt_custom_selection(install.MenuContext("retroarch",
listed["files"], [],
manifest=listed),
played=plan, given=given,
command=lambda choice: install._INVOCATION.command("retroarch", "<dest>"))
return choice, out.getvalue()
def test_the_games_are_the_first_choice(self):
+11 -8
View File
@@ -714,7 +714,7 @@ class TheSummaryNamesTheBulk(unittest.TestCase):
out = io.StringIO()
with contextlib.redirect_stdout(out):
install._report_outcome([Path("/x")], 3, 0, 0, 0, False,
hints=[" arcade pulls most of it."])
details=install.OutcomeDetails(hints=[" arcade pulls most of it."]))
text = out.getvalue()
self.assertIn(" arcade pulls most of it.", text)
self.assertLess(text.index("Done."), text.index("arcade pulls"))
@@ -904,8 +904,8 @@ class OfflineLeavesFilesMissing(Scratch):
with contextlib.redirect_stdout(out), self.assertRaises(SystemExit) as stop:
install._report_outcome([self.dest], counts.get("installed", 0), 0,
counts.get("errors", 0), 0, False,
sources=counts.get("sources", ""),
offline=counts["offline"])
details=install.OutcomeDetails(sources=counts.get("sources", ""),
offline=counts["offline"]))
return stop.exception.code, out.getvalue()
def test_some_installed_is_not_done(self):
@@ -1020,8 +1020,8 @@ class OneOfflineVocabulary(Scratch):
failures = [("a.bin", install.NOT_WRITABLE), ("b.bin", install.NOT_WRITABLE)]
with contextlib.redirect_stdout(io.StringIO()) as out, \
self.assertRaises(SystemExit) as stop:
install._report_outcome([self.dest], 0, 0, 2, 0, False, failures=failures,
offline=20)
install._report_outcome([self.dest], 0, 0, 2, 0, False,
details=install.OutcomeDetails(failures=failures, offline=20))
self.assertEqual(stop.exception.code, 2)
self.assertIn("Nothing installed: 20 files not fetched (--offline), 2 failed.",
out.getvalue())
@@ -1074,7 +1074,8 @@ class OneOfflineVocabulary(Scratch):
with unittest.mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}), \
unittest.mock.patch.object(install, "_ask", lambda _prompt: next(answers)), \
contextlib.redirect_stdout(io.StringIO()) as out:
self.assertIsNone(install._prompt_custom_selection("retroarch", [], []))
context = install.MenuContext("retroarch", [], [])
self.assertIsNone(install._prompt_custom_selection(context))
text = out.getvalue()
self.assertIn("Enter) check the BIOS folder, nothing can be downloaded", text)
self.assertIn("f) copy from a folder or an old card", text)
@@ -1136,7 +1137,8 @@ class OfflineAndPackLeaveOut(Scratch):
unittest.mock.patch.object(install, "_ask", lambda _prompt: next(answers)), \
contextlib.redirect_stdout(io.StringIO()) as out, \
self.assertRaises(SystemExit):
install._prompt_custom_selection("retroarch", files, [], bios_path=self.dest)
install._prompt_custom_selection(install.MenuContext("retroarch", files, [],
bios_path=self.dest))
text = out.getvalue()
self.assertIn("empty holds none of these files.", text)
self.assertNotIn("install what is found", text)
@@ -1149,7 +1151,8 @@ class OfflineAndPackLeaveOut(Scratch):
unittest.mock.patch.object(install, "_ask", lambda _prompt: next(answers)), \
contextlib.redirect_stdout(io.StringIO()) as out, \
self.assertRaises(SystemExit):
install._prompt_custom_selection("retroarch", files, [], bios_path=self.dest)
install._prompt_custom_selection(install.MenuContext("retroarch", files, [],
bios_path=self.dest))
self.assertIn("1 of 4 found in empty.", out.getvalue())
self.assertIn("Enter) install what is found in", out.getvalue())
+3 -3
View File
@@ -425,7 +425,7 @@ class ACoreWithNoFileOfItsOwn(unittest.TestCase):
out = io.StringIO()
with mock.patch("builtins.input", lambda _prompt="": next(answers)), \
contextlib.redirect_stdout(out):
install._prompt_custom_selection("retroarch", self.FILES, [])
install._prompt_custom_selection(install.MenuContext("retroarch", self.FILES, []))
line = self._line(out.getvalue(), "pcsx_rearmed")
self.assertNotIn("0 files", line)
self.assertIn("always kept", line)
@@ -462,7 +462,7 @@ class FilesSharedBySystemsAreCountedApart(unittest.TestCase):
out = io.StringIO()
with mock.patch("builtins.input", lambda _prompt="": next(answers)), \
contextlib.redirect_stdout(out):
install._prompt_custom_selection("retroarch", self.FILES, [])
install._prompt_custom_selection(install.MenuContext("retroarch", self.FILES, []))
self.assertIn("1 file, 4 B, and 2 files, 150 B shared with other systems",
out.getvalue())
@@ -729,7 +729,7 @@ class TheOneLinerNarrows(unittest.TestCase):
menus = (
lambda: install._choose_platform("Platform:"),
lambda: install._pick("Systems:", [("nintendo-gba", files)]),
lambda: install._prompt_custom_selection("retroarch", files, []),
lambda: install._prompt_custom_selection(install.MenuContext("retroarch", files, [])),
)
for menu in menus:
with self.subTest(menu=menu), \
+28 -21
View File
@@ -4390,7 +4390,8 @@ class LineModeOffline(unittest.TestCase):
trees = [{"ref": "t", "files": {"x": {"size": 2048}, "y": {"size": 2048}}}]
with mock.patch.object(install, "_ask", return_value=""), \
contextlib.redirect_stdout(io.StringIO()) as out:
install._prompt_custom_selection("retroarch", files, [], data_trees=trees)
install._prompt_custom_selection(install.MenuContext("retroarch", files, [],
data_trees=trees))
# One total, the kinds under it adding up to it.
self.assertIn("RetroArch: 3 files, 5.0 KB.\n 1 BIOS file (1.0 KB) and 2 data files "
"(4.0 KB).", out.getvalue())
@@ -7182,8 +7183,8 @@ class OneCardReading(unittest.TestCase):
self.assertEqual(install.detected_os("retroarch", dest), "Onion")
with mock.patch.object(install, "_ask", return_value=""), \
contextlib.redirect_stdout(io.StringIO()) as out:
install._prompt_custom_selection("retroarch", [], [], name="Onion",
bios_path=dest)
install._prompt_custom_selection(install.MenuContext("retroarch", [], [], name="Onion",
bios_path=dest))
self.assertIn("Onion: 0 files", out.getvalue())
self.assertIn(f"BIOS folder: {dest}", out.getvalue())
proc = install_run("--platform", "onion", "--dest", str(cards[0]), "--dry-run",
@@ -8334,9 +8335,10 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings,
self.assertEqual(counts.size, sum(e.get("size") or 0 for e in files))
out = io.StringIO()
with contextlib.redirect_stdout(out):
install._print_menu_head(
manifest["platform"], manifest["files"], [], None, "", [], None,
None, None, manifest, False)
install._print_menu_head(install.MenuContext(manifest["platform"],
manifest["files"], [],
manifest=manifest),
current=None, given=None)
head = re.search(r"(\d+) files?, ", out.getvalue())
split = re.search(r"(\d+) BIOS files? \(.*?\) and (\d+) game data files?",
out.getvalue())
@@ -8809,7 +8811,8 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings,
seen = [{**entry, "frontend": "ROCKNIX"} for entry in omitted]
with contextlib.redirect_stdout(io.StringIO()) as out, \
contextlib.suppress(SystemExit):
install._report_outcome([self.here], 1, 0, 0, 3, False, omitted_entries=seen)
install._report_outcome([self.here], 1, 0, 0, 3, False,
details=install.OutcomeDetails(omitted_entries=seen))
self.assertIn(said, out.getvalue())
def test_the_drives_mounted_here_are_offered_in_both(self):
@@ -9076,7 +9079,7 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings,
with mock.patch.object(install, "_ask", return_value="q"), \
contextlib.redirect_stdout(io.StringIO()), \
self.assertRaises(SystemExit) as stop:
install._prompt_custom_selection("retroarch", [], [])
install._prompt_custom_selection(install.MenuContext("retroarch", [], []))
self.assertEqual(stop.exception.code, 2)
self.assertEqual(install.QUIT_CODE, 2)
state = checked_state()
@@ -9171,9 +9174,10 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings,
"files": {"a": {"size": 5}, "b": {"size": 5}}}]
out = io.StringIO()
with contextlib.redirect_stdout(out):
install._print_menu_head("retroarch", manifest["files"], [], None, "",
manifest["data_directories"], None, None, None, manifest,
False)
install._print_menu_head(install.MenuContext("retroarch", manifest["files"], [],
data_trees=manifest["data_directories"],
manifest=manifest),
current=None, given=None)
self.assertIn("1 BIOS file (3 B), 1 game data file (30 B) and 2 data files (10 B).",
out.getvalue())
self.assertIn("Data files: the files an emulator reads from a data folder of its own",
@@ -9345,9 +9349,10 @@ class PacksWordingAndDocs(unittest.TestCase):
with contextlib.redirect_stdout(io.StringIO()) as out, \
mock.patch.object(install, "_ask", side_effect=["c", "1", "q"]), \
contextlib.suppress(SystemExit):
install._prompt_custom_selection(
"retroarch", [{"dest": "a", "size": 1, "systems": ["x"], "cores": None}], [],
command=lambda _choice: "python3 install.py --dest '\x1b[2J'")
install._prompt_custom_selection(install.MenuContext("retroarch",
[{"dest": "a", "size": 1, "systems": ["x"], "cores": None}],
[]),
command=lambda _choice: "python3 install.py --dest '\x1b[2J'")
self.assertNotIn("\x1b", out.getvalue())
def test_the_home_folder_is_said_on_the_plan(self):
@@ -10021,8 +10026,9 @@ class LineModeDecisions(unittest.TestCase):
given = (["nintendo-gba"], [], [])
patcher, _asked = self.ask("")
with patcher, contextlib.redirect_stdout(io.StringIO()) as out:
chosen = install._prompt_custom_selection(
"retroarch", files, [], bios_path=self.root, given=given)
chosen = install._prompt_custom_selection(install.MenuContext("retroarch", files, [],
bios_path=self.root),
given=given)
self.assertEqual(chosen, given)
text = out.getvalue()
self.assertIn("RetroArch: 1 file, 1 B, for 1 of 2 systems (--system).", text)
@@ -10281,8 +10287,9 @@ class ScreenRowsAndFilters(unittest.TestCase):
contextlib.redirect_stdout(io.StringIO()) as out, \
self.assertRaises(SystemExit):
install._report_outcome([self.root], 6, 0, 0, 1, False,
omitted_entries=unplaced, offline=16,
sources="6 files copied from OLD, 16 still missing.")
details=install.OutcomeDetails(omitted_entries=unplaced,
offline=16,
sources="6 files copied from OLD, 16 still missing."))
lines = out.getvalue().splitlines()
remedy = next(i for i, line in enumerate(lines) if "Copy them" in line
or "They are not in" in line)
@@ -14381,8 +14388,8 @@ class ProvenCardsAndCounts(unittest.TestCase):
self.assertEqual(sources, "38 files copied from /media/OLD, 4 downloaded, 2 failed.")
with contextlib.redirect_stdout(out), contextlib.suppress(SystemExit):
install._report_outcome([self.here], 42, 0, 2, 0, False,
failures=[("x.bin", "timed out"), ("y.bin", "timed out")],
sources=sources)
details=install.OutcomeDetails(failures=[("x.bin", "timed out"), ("y.bin", "timed out")],
sources=sources))
text = out.getvalue()
self.assertIn(f"Finished with errors. {sources}", text)
self.assertNotIn("42 files installed", text)
@@ -15050,7 +15057,7 @@ class CoresListAndFolderFailures(unittest.TestCase):
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(out), \
contextlib.suppress(SystemExit):
install._report_outcome([Path("/b")], 3, 0, 1, 0, False,
failures=[("gba_bios.bin", "timed out")])
details=install.OutcomeDetails(failures=[("gba_bios.bin", "timed out")]))
self.assertNotIn("gba_bios.bin", out.getvalue())
self.assertIn("Run the same command again to retry only those.", out.getvalue())