Files
libretro/tests/test_pack_readme.py

60 lines
2.1 KiB
Python

"""The README inside a pack sends files where the platform reads them.
RetroDECK's pack holds bios/ and roms/ at its root, and its guide said to
extract into ~/retrodeck/bios/, giving ~/retrodeck/bios/bios/. MiSTer and
ROCKNIX had no guide and were told "your BIOS directory", a folder MiSTer
does not have, while the registry names the path.
"""
from __future__ import annotations
import re
import sys
import unittest
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from packreadme import _build_readme # noqa: E402
def _extract_lines(text: str) -> list[str]:
return [line for line in text.splitlines() if "Extract all files" in line]
class GuidesPointAtTheReadPath(unittest.TestCase):
def test_retrodeck_is_extracted_at_its_root(self):
text = _build_readme("retrodeck", "RetroDECK", "", 1, 1)
for line in _extract_lines(text):
self.assertNotIn("retrodeck/bios", line)
def test_unguided_platforms_name_the_registry_path(self):
registry = yaml.safe_load((REPO_ROOT / "platforms" / "_registry.yml").read_text())
for name, data in registry["platforms"].items():
paths = [
str(d.get("bios_path", ""))
for d in (data.get("install", {}) or {}).get("detect", [])
]
if not any(paths):
continue
text = _build_readme(name, name, "", 1, 1, bios_paths=paths)
with self.subTest(platform=name):
self.assertFalse(
any("your BIOS directory" in line for line in _extract_lines(text))
)
class GuidesNameShippedInstallers(unittest.TestCase):
def test_every_installer_named_exists(self):
"""RetroBat's guide sent users to an install.bat no release carries."""
source = (REPO_ROOT / "scripts" / "packreadme.py").read_text(encoding="utf-8")
for name in set(re.findall(r"install\.(?:bat|ps1|sh|py)", source)):
with self.subTest(installer=name):
self.assertTrue((REPO_ROOT / name).is_file())
if __name__ == "__main__":
unittest.main()