fix: one size predicate, size_options retired

This commit is contained in:
Abdessamad Derraz committed 2026-10-05 02:51:13 +02:00
1 parent a090e64336
commit 0d7939588e
16 files changed
+115 -61

No files matched your search

+19
View File
@@ -106,6 +106,25 @@ class AgnosticScanStaysInItsTree(unittest.TestCase):
)
return [e for e in extras if e.get("agnostic_scan")]
def test_a_list_of_accepted_sizes_selects_the_scan(self):
"""`size` may list every size the code accepts. The scan compared it
as one integer and failed on a list."""
profiles = self._write_profile(
"emulator: demo\n"
"type: libretro\n"
"display_name: Demo\n"
"bios_mode: agnostic\n"
"systems: [demo-system]\n"
"cores: [demo]\n"
"files:\n"
" - name: boot.bin\n"
" system: demo-system\n"
" size: [512, 1024]\n"
" agnostic: true\n"
)
names = sorted(e["name"] for e in self._scan(profiles))
self.assertIn("boot.bin", names)
def test_it_collects_the_interchangeable_dumps(self):
profiles = self._write_profile(
"emulator: demo\n"
+11
View File
@@ -174,6 +174,17 @@ class TestSizeGateOnTheNameStep(unittest.TestCase):
self.assertIsNotNone(path)
self.assertEqual(status, "hash_mismatch")
def test_a_list_of_accepted_sizes_gates_the_name_step(self):
# SC-55/ROM2.BIN accepts two sizes; a PlayStation 2 ROM2.BIN of a
# third size answered to the name because the list was ignored.
entry = {"name": "ROM", "size": [8, 999], "validation": ["size"]}
path, status = resolve_local_file(entry, self.db)
self.assertEqual(status, "name_exact")
self.assertIn("IIGS", path)
entry = {"name": "ROM", "size": [999, 1000], "validation": ["size"]}
path, status = resolve_local_file(entry, self.db)
self.assertEqual(status, "hash_mismatch")
def test_a_size_without_validation_rejects_nothing(self):
# Documented behaviour: a size is informative until the emulator
# itself checks it.
+39
View File
@@ -198,6 +198,19 @@ class AgnosticFallback(unittest.TestCase):
}
self.assertIsNotNone(common._resolve_agnostic(entry, self.files_db, False))
def test_a_list_of_accepted_sizes_is_honoured(self):
entry = {
"agnostic": True,
"agnostic_path_prefix": str(self.root),
"size": [32, 64],
}
self.assertEqual(
common._resolve_agnostic(entry, self.files_db, False),
(str(self.match), "agnostic_fallback"),
)
entry["size"] = [32, 65]
self.assertIsNone(common._resolve_agnostic(entry, self.files_db, False))
def test_without_a_prefix_nothing_is_scanned(self):
entry = {"agnostic": True, "size": 64}
self.assertIsNone(common._resolve_agnostic(entry, self.files_db, False))
@@ -207,5 +220,31 @@ class AgnosticFallback(unittest.TestCase):
self.assertIsNone(common._resolve_agnostic(entry, self.files_db, False))
class OneSpellingForAcceptedSizes(unittest.TestCase):
"""A set of sizes the code accepts is ``size: [a, b]`` and nothing else.
SC-55/ROM2.BIN declared its two sizes under a field the resolver never
read and resolved by name to a PlayStation 2 ROM of a third size.
"""
def test_no_profile_uses_a_second_field(self):
offenders = [
path.name
for path in sorted((REPO_ROOT / "emulators").glob("*.yml"))
if "size_options" in path.read_text(encoding="utf-8")
]
self.assertEqual(offenders, [])
def test_the_schema_refuses_the_second_field(self):
import json
schema = json.loads(
(REPO_ROOT / "schemas/emulator.schema.json").read_text(encoding="utf-8")
)
file_entry = schema["properties"]["files"]["items"]["properties"]
self.assertNotIn("size_options", file_entry)
self.assertEqual(file_entry["size"]["type"], ["integer", "array", "null"])
if __name__ == "__main__":
unittest.main()