"""A hardware target names its artifacts by the name it is filed under. `switch`, `nx` and `nintendo-switch` are one RetroArch target. The tag came from the name as typed, so one target gave three pack and manifest names, and `--verify-packs --target nx` looked for a pack nobody had built. """ from __future__ import annotations import subprocess import sys import tempfile import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import canonical_target_name # noqa: E402 class AliasesResolveToOneName(unittest.TestCase): def test_retroarch_switch_aliases(self): platforms = str(REPO_ROOT / "platforms") for typed in ("switch", "nx", "nintendo-switch"): with self.subTest(typed=typed): self.assertEqual( canonical_target_name(["retroarch"], typed, platforms), "nintendo-switch", ) def test_an_unknown_name_is_left_for_the_target_check(self): self.assertEqual( canonical_target_name(["retroarch"], "bogus", str(REPO_ROOT / "platforms")), "bogus", ) class TheBuilderNamesByTheCanonicalTarget(unittest.TestCase): def test_an_alias_writes_the_canonical_manifest(self): if not (REPO_ROOT / "database.json").exists(): self.skipTest("database.json is not built") (REPO_ROOT / "tmp").mkdir(exist_ok=True) with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out: proc = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--platform", "retroarch", "--target", "nx", "--manifest", "--offline", "--output-dir", out], cwd=REPO_ROOT, capture_output=True, text=True, timeout=600, check=False, ) self.assertEqual(proc.returncode, 0, proc.stderr) self.assertEqual( sorted(p.name for p in Path(out).glob("*.json")), ["retroarch_nintendoswitch.json"], ) class TheListingCountsWhatTheFilterUses(unittest.TestCase): """--list-targets showed Batocera x86_64 with 198 cores; --target x86_64 filters on 187 once _overrides.yml removes machine variants and launchers.""" def test_every_listed_count_is_the_filtered_set(self): from common import list_available_targets, load_target_config # noqa: PLC0415 platforms = str(REPO_ROOT / "platforms") checked = 0 for target_file in sorted((REPO_ROOT / "platforms" / "targets").glob("[!_]*.yml")): platform = target_file.stem for row in list_available_targets(platform, platforms): with self.subTest(platform=platform, target=row["name"]): self.assertEqual( row["core_count"], len(load_target_config(platform, row["name"], platforms)), ) checked += 1 self.assertGreater(checked, 0) if __name__ == "__main__": unittest.main()