"""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()) class TheSiteSaysWhatTheInstallerShows(unittest.TestCase): """which-pack showed a line menu (Enter, i, c, q) the one-liner never opens, typed by hand, its keys out of date. The site, the README and the wiki now take the screen's words and the line menu from install.py.""" MENU_LINES = ("Enter) install everything", "i) only what the installed cores read", "c) choose systems, cores and regions") def test_which_pack_describes_the_screen_in_the_installers_words(self): installer = generate_site._installer() text = _page("which-pack.md") for line in generate_site.first_screen_words(): self.assertIn(line, text) self.assertIn(f"**{installer.TUI_INSTALL_ROW}**", text) self.assertIn(f"**{installer.TUI_SYSTEMS_ROW}**", text) for line in self.MENU_LINES: self.assertNotIn(line, text) self.assertNotIn("press **c**", text) def test_the_plan_rows_are_the_words_the_pages_use(self): installer = generate_site._installer() state = installer.TuiState(os_type="linux", home=Path("/home/me")) state.stack = ["plan"] state.check = {"files": 2, "present": 0, "missing": 2, "wrong_hash": 0, "need": 2, "bytes_needed": 10} state.systems = [{"system": name, "missing": 1, "wrong_hash": 0, "present": 0, "files": 1, "bytes_needed": 5} for name in ("a", "b")] state.manifest = {"files": [{"dest": "a.bin", "systems": ["a"]}, {"dest": "b.bin", "systems": ["b"]}]} state.ticked = {"a", "b"} state.checked_flags = installer.tui_flags(state) labels = [row.label for row in installer.tui_rows(state)] self.assertEqual(labels[0], installer.TUI_INSTALL_ROW) self.assertIn(installer.TUI_SYSTEMS_ROW, labels) def test_the_readme_and_the_wiki_take_the_same_words(self): installer = generate_site._installer() readme = (REPO_ROOT / "README.md").read_text(encoding="utf-8") self.assertIn(f"fewer under **{installer.TUI_SYSTEMS_ROW}**", readme) self.assertNotIn("offers to install everything or to choose systems", readme) source = (REPO_ROOT / "scripts" / "generate_readme.py").read_text(encoding="utf-8") self.assertIn("_installer_words().TUI_SYSTEMS_ROW", source) import generate_installer_doc # noqa: PLC0415 page = (REPO_ROOT / "wiki" / "installer.md").read_text(encoding="utf-8") self.assertIn(generate_installer_doc.line_menu(), page) menu = page.split("", 1)[1] outside = page.replace(menu.split("", 1)[0], "") for line in self.MENU_LINES: self.assertNotIn(line, outside) if __name__ == "__main__": unittest.main()