From 00649d0377e597fb6f292a95a94a0a0915f0a2c5 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 24 Oct 2026 00:52:36 +0200 Subject: [PATCH] chore: tests for the round 5 entry pages --- tests/test_site_r5_entry.py | 235 ++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 tests/test_site_r5_entry.py diff --git a/tests/test_site_r5_entry.py b/tests/test_site_r5_entry.py new file mode 100644 index 00000000..c59f4783 --- /dev/null +++ b/tests/test_site_r5_entry.py @@ -0,0 +1,235 @@ +"""Entry pages, get/ and guides (round 5, package 4). + +The get/ page of a setup with no ZIP printed one command for three +systems, with no --dest, so it failed on the computer most readers open +it on. "All good when you see 0 wrong hash" was also what an empty folder +prints. Setups with no ZIP lost every route that works without a network. +The get/ pages were titled "Download KNULLI", /get/ answered 404, and two +Linux handheld rows sent the reader to a menu. +""" + +from __future__ import annotations + +import re +import sys +import unittest +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(REPO_ROOT / "scripts")) +sys.path.insert(0, str(REPO_ROOT)) + +import generate_site # noqa: E402 +import release_record # noqa: E402 +import siteguides # noqa: E402 +from common import load_platform_config, load_platform_registry # noqa: E402 +from tests import sitepages # noqa: E402 + +REGISTRY = load_platform_registry(str(REPO_ROOT / "platforms")) +SETUPS = [name for name in siteguides.GUIDES if name in REGISTRY] +COMMAND = re.compile(r"^(?:curl -fsSL |&\(\[scriptblock\]|irm ).*$", re.M) +OFFLINE_ANCHOR = "#without-a-network-offline-install" +CARD_FAQ = "/retrobios/wiki/faq/#fill-an-sd-card-from-a-computer" + + +def _page(name: str) -> str: + sitepages.require() + return re.sub(r"]*>", "", sitepages.page(name).read_text(encoding="utf-8")) + + +def _guide_part(text: str) -> str: + match = re.search(r"^## Reference\b", text, re.M) + return text[: match.start()] if match else text + + +def _with_zip(name: str) -> bool: + pack = release_record.pack_for(name, release_record.load_advertised()) + return bool(pack and pack.get("assets")) + + +def _display(name: str) -> str: + return load_platform_config(name, str(REPO_ROOT / "platforms")).get("platform", name) + + +def _tab_labels(text: str) -> set[str]: + return set(re.findall(r' Directory > System/BIOS**", text) + self.assertIn("into RetroBat's `bios` folder", _page("get/retrobat.md")) + self.assertNotIn("into `system/`", text) + + +class HandheldRowsSayWhere(unittest.TestCase): + def test_retrooz_names_its_folder_with_a_pinned_source(self): + system = next(s for s in siteguides.HANDHELD_GUIDE.systems if s.name == "RetroOZ") + self.assertIn("`/roms/bios`", system.folder) + self.assertRegex(system.folder_source, r"/wiki/Home/[0-9a-f]{40}$") + row = next(line for line in _page("platforms/linux-handhelds.md").splitlines() + if line.startswith("| RetroOZ |")) + self.assertNotIn(generate_site.RETROARCH_FOLDER_SETTING, row) + + +class GetIndex(unittest.TestCase): + def test_every_setup_is_linked_under_its_group(self): + text = _page("get/index.md") + for name in SETUPS: + with self.subTest(setup=name): + self.assertIn(f"(/retrobios/get/{name}/)", text) + for label, _description in siteguides.DEVICE_GROUPS.values(): + self.assertIn(f"## {label}", text) + + +class HomeAndWhichPack(unittest.TestCase): + def test_the_home_step_does_not_promise_a_zip(self): + text = _page("index.md") + self.assertIn("**Run one command.** Some setups have a ZIP.", text) + self.assertNotIn("or download a ZIP file", text) + + def test_which_pack_answers_ios(self): + text = _page("which-pack.md") + meta = re.search(r'data-pagefind-meta="terms:([^"]+)"', text) + self.assertIsNotNone(meta) + for word in ("ios", "iphone", "ipad", "delta", "provenance"): + self.assertIn(word, meta[1].split()) + + +if __name__ == "__main__": + unittest.main()