feat: suggest systems by short name

--system gba, psx or ps1 was refused with no suggestion on RetroArch.
Short names now suggest the ids they stand for, never taken in their
place, and two aliases of one system name it once. --platform muos and
the other systems --list-platforms names stand for the file list they
get, and the run says which.
This commit is contained in:
Abdessamad Derraz committed 2026-10-23 13:55:09 +02:00
1 parent 41839b7784
commit e041fac351
6 files changed
+104 -10

No files matched your search

+15
View File
@@ -3759,6 +3759,21 @@ class ATypoGetsTheClosestName(unittest.TestCase):
self.assertEqual(install.normalize_platform("RetroArch "), "retroarch")
self.assertEqual(install.normalize_platform("RetroDECK"), "retrodeck")
def test_a_system_name_stands_for_the_list_it_gets(self):
"""--list-platforms printed `muOS: retroarch`, and --platform muos
answered "Unknown platform"."""
for typed, plat in (("muos", "retroarch"), ("muOS", "retroarch"),
("ArkOS", "retroarch"), ("PAN4ELEC", "amberelec"),
("JELOS", "retroarch")):
out = io.StringIO()
with self.subTest(typed=typed), contextlib.redirect_stdout(out):
self.assertEqual(install.normalize_platform(typed), plat)
self.assertIn(f"--platform {plat}", out.getvalue())
def test_a_system_that_gets_no_list_is_still_refused(self):
with contextlib.redirect_stderr(io.StringIO()), self.assertRaises(SystemExit):
install.normalize_platform("TrimUI")
def test_a_platform_typo_is_answered_with_one_name(self):
err = io.StringIO()
with contextlib.redirect_stderr(err), self.assertRaises(SystemExit) as raised:
+19
View File
@@ -13,6 +13,7 @@ import functools
import hashlib
import http.server
import importlib.util
import io
import json
import os
import random
@@ -311,6 +312,24 @@ class CommandLineChoices(unittest.TestCase):
self.assertIn("sega-saturn", str(ctx.exception))
self.assertIn("nintendo-gba", str(ctx.exception))
def test_a_short_name_is_suggested_never_taken(self):
"""`--system gba`, `psx` and `ps1` were refused on RetroArch with no
suggestion, though nintendo-gba holds the very letters."""
known = [f"system-{i}" for i in range(40)] + [
"nintendo-gb", "nintendo-gba", "nintendo-gbc", "sony-playstation",
"sony-playstation-2", "sega-mega-drive"]
for typed, meant in (("gba", "nintendo-gba"), ("psx", "sony-playstation"),
("ps1", "sony-playstation"), ("PS2", "sony-playstation-2"),
("genesis", "sega-mega-drive"), ("gb", "nintendo-gb")):
with self.subTest(typed=typed), self.assertRaises(ValueError) as ctx:
install.resolve_choices([typed], known, "system")
self.assertIn(f"Did you mean: {meant}", str(ctx.exception))
def test_a_short_name_for_a_system_the_list_lacks_is_not_suggested(self):
with self.assertRaises(ValueError) as ctx:
install.resolve_choices(["psx"], [f"system-{i}" for i in range(40)], "system")
self.assertNotIn("sony-playstation", str(ctx.exception))
def test_an_empty_list_is_refused(self):
with self.assertRaises(ValueError):
install.resolve_regions([" , "])