Files
libretro/tests/test_region_required_only.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

64 lines
2.5 KiB
Python

"""--region decides among the files --required-only keeps.
The regional choice ran over optional candidates too. In Batocera's Vic20
group the optional Japanese kernel won for --region jp, the required PAL
and NTSC kernels were dropped as beaten, and --required-only then removed
the optional winner: the slot shipped empty.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import ast
import sys
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from packextras import platform_region_groups # noqa: E402
class RequiredOnlyBeforeRegion(unittest.TestCase):
def test_optional_files_leave_the_groups(self):
systems = {"vic20": {"files": [
{"name": "kernel-ntsc.bin", "destination": "Vic20/kernel-ntsc.bin", "required": True},
{"name": "kernel-japanese.bin", "destination": "Vic20/kernel-japanese.bin",
"required": False},
]}}
groups, _ = platform_region_groups(
{}, systems, "emulators", None, "", {}, include_extras=False, required_only=True,
)
self.assertEqual(groups["vic20"], [("Vic20/kernel-ntsc.bin", "kernel-ntsc.bin")])
def test_every_caller_passes_it(self):
tree = ast.parse((REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8"))
calls = [
node for node in ast.walk(tree)
if isinstance(node, ast.Call)
and getattr(node.func, "id", None) == "platform_region_groups"
]
self.assertGreaterEqual(len(calls), 2)
for call in calls:
self.assertIn("required_only", {kw.arg for kw in call.keywords})
class EmulatorModeToo(unittest.TestCase):
"""--emulator mednafen_pce_fast --region us --required-only shipped 0 files:
the optional US cards won the group, then --required-only removed them."""
def test_the_required_card_survives(self):
from packextras import emulator_region_drops # noqa: PLC0415
profile = {"systems": ["nec-pc-engine"], "files": [
{"name": "syscard3.pce", "required": True, "region": ["japan"]},
{"name": "syscard3u.pce", "required": False, "region": ["north-america"]},
]}
drops = emulator_region_drops([("pce", profile)], False, ["north-america"], True)
self.assertNotIn("syscard3.pce", drops)
if __name__ == "__main__":
unittest.main()