diff --git a/scripts/model/guides.py b/scripts/model/guides.py index 57227d4a8..062d206b8 100644 --- a/scripts/model/guides.py +++ b/scripts/model/guides.py @@ -9,7 +9,7 @@ from pathlib import Path from model.registry import load_platform_registry from core.paths import REPO_ROOT -from model.safeparse import require_yaml +from model.sources import source_yaml SH_NAME = "i" @@ -343,11 +343,10 @@ def load_guides(path: Path = GUIDES_FILE, registry: dict | None = None) -> dict: describes. A mistake raises GuideError naming the key, so the site is never built from half a guide. """ - yaml = require_yaml() if registry is None: registry = load_platform_registry(PLATFORMS_DIR, required=True) with open(path, encoding="utf-8") as handle: - data = yaml.safe_load(handle) or {} + data = source_yaml(handle) or {} if not isinstance(data, dict): raise GuideError(f"{path.name}: expected a mapping") _unknown(data, _TOP_KEYS, path.name) diff --git a/tests/test_site_content_data.py b/tests/test_site_content_data.py index 234036c15..fb545ad9b 100644 --- a/tests/test_site_content_data.py +++ b/tests/test_site_content_data.py @@ -22,6 +22,7 @@ import yaml from sitegen import decorate from sitegen import nav as sitegen_nav from model import guides +from core.cli import SourceUnreadable from model.guides import GUIDES, GuideError, load_guides REPO_ROOT = Path(__file__).resolve().parent.parent @@ -76,6 +77,12 @@ class GuidesLiveInYaml(unittest.TestCase): with self.assertRaisesRegex(GuideError, r"guides\.lakka\.run: no terminal named telnet"): self._load(yaml.safe_dump(data)) + def test_a_repeated_guide_is_refused_with_its_line(self): + """safe_load kept the second retroarch guide and dropped the first.""" + text = _guides_text().replace("guides:\n", "guides:\n lakka: {}\n", 1) + with self.assertRaisesRegex(SourceUnreadable, r"_guides\.yml:\d+: duplicate key 'lakka'"): + self._load(text) + def test_a_folder_row_without_path_is_the_extract_folder(self): """The folder the pack unzips into is written once, in the registry.""" registry = _registry()