Files
libretro/tests/test_data_dir_refs.py
T
Abdessamad Derraz 057fd2d0f6 fix: isolate every test module however it runs
tests/__init__.py keeps a run offline, its scratch under tmp/ and its
installer cache its own, but only discover -s tests -t . imported it.
discover tests ran with RETROBIOS_OFFLINE unset, scratch on the /tmp
tmpfs and the user's real installer cache, the setting in which e2e
fixtures had written into the shared .cache/large. Every test module now
imports the package first, and a test fails on a module that does not.
test_verify_listing.py took its line with the previous commit.
2026-11-06 15:14:05 +01:00

61 lines
2.3 KiB
Python

"""Every data_directories ref names a registered data directory.
yaps2 referenced yaps2-resources, absent from _data_dirs.yml: the pack and
verify only said "not cached" and refresh_data_dirs had nothing to fetch.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import sys
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
class DataDirRefsAreRegistered(unittest.TestCase):
def test_no_unknown_ref(self):
try:
import validate_schemas
except ImportError as exc:
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
self.assertEqual(validate_schemas._unknown_data_dir_refs(), [])
class EachSourceIsParsedOnce(unittest.TestCase):
"""The schema pass, the data directory refs and the layout check each
parsed every profile again: 2,038 parses for about 690 files."""
def test_three_checks_one_parse(self):
import tempfile
from unittest import mock
try:
import validate_schemas
except ImportError as exc:
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
root = Path(tmp)
(root / "emulators").mkdir()
(root / "platforms").mkdir()
(root / "platforms" / "_data_dirs.yml").write_text("data_directories: {}\n")
(root / "emulators" / "core.yml").write_text(
"emulator: Core\nfiles:\n- name: a.bin\n path: .variants/a.bin\n")
loaded = []
real = validate_schemas.yaml_load
with mock.patch.object(validate_schemas, "ROOT", root), \
mock.patch.object(validate_schemas, "yaml_load",
side_effect=lambda h: loaded.append(h.name) or real(h)):
validate_schemas._validate_yaml_directory(root / "emulators", "emulator.schema.json")
validate_schemas._unknown_data_dir_refs()
layout = validate_schemas._repository_layout_in_profiles()
self.assertEqual(sorted(Path(n).name for n in loaded), ["_data_dirs.yml", "core.yml"])
self.assertEqual(len(layout), 1)
if __name__ == "__main__":
unittest.main()