Files
libretro/tests/test_content_declarations.py
T
Abdessamad Derraz 83cfa6fd0f refactor: split common.py into three packages
core: cli (run_cli, input errors, name hints), github (token), paths.
model: sources, database, composition, registry, platforms,
declarations, targets, systems, profiles, cliargs. resolve: content,
ownership, datadirs, archives, localfile, directories, layout,
contentlayout, standalone, grouping, cores.

Definitions move verbatim; common.py and its re-exports are gone and
every importer, patch target and code-in-string names the new home. A
test that stubbed common.load_platform_config stubs each module that
reads the loader by its own name.
2026-11-18 11:09:13 +01:00

63 lines
2.3 KiB
Python

"""A platform declaration that a content-found core entry accepts by hash.
atari800 identifies its ROMs by CRC32 in the folder it scans. RetroDECK
lists Atari BASIC Rev A as ROM_BASIC_A, a name atari800 never opens, and
the profile answered it with a false alias. Settled by content instead, the
declared file meets the entry and the label is not shipped a second time.
"""
from __future__ import annotations
import tests
import unittest
from model.declarations import platform_declared_contents
from resolve.validation import declaration_settles
SHA1 = "70cdf57469a208528f78a14275837352e90e20f1"
DB = {
"files": {SHA1: {"path": "bios/Atari/ROM_BASIC_A", "name": "ROM_BASIC_A", "sha1": SHA1,
"md5": "a4dc52536d526ecc51ea857b9fa2b90f", "crc32": "4bec4de2",
"size": 8192}},
"indexes": {"by_md5": {"a4dc52536d526ecc51ea857b9fa2b90f": SHA1}},
}
CONFIG = {
"base_destination": "",
"systems": {"atari800": {"files": [
{"name": "ROM_BASIC_A", "destination": "bios/ROM_BASIC_A",
"md5": "a4dc52536d526ecc51ea857b9fa2b90f"},
]}},
}
ENTRY = {"name": "atari-basic-rev-a.rom", "found_by": "content", "crc32": "4bec4de2"}
class ContentDeclarationTest(unittest.TestCase):
def setUp(self) -> None:
self.contents = platform_declared_contents(CONFIG, DB)
def test_the_declared_file_is_indexed_by_each_hash(self) -> None:
self.assertEqual(self.contents["crc32:4bec4de2"], {""})
self.assertEqual(self.contents[f"sha1:{SHA1}"], {""})
def test_a_content_found_entry_is_met_by_its_hash(self) -> None:
self.assertTrue(declaration_settles(
ENTRY, ENTRY["name"], {}, ENTRY["name"], declared_contents=self.contents,
))
def test_an_entry_opened_by_name_is_not(self) -> None:
entry = {key: value for key, value in ENTRY.items() if key != "found_by"}
self.assertFalse(declaration_settles(
entry, entry["name"], {}, entry["name"], declared_contents=self.contents,
))
def test_another_folder_is_not_the_one_scanned(self) -> None:
self.assertFalse(declaration_settles(
ENTRY, ENTRY["name"], {}, "atari800/" + ENTRY["name"],
declared_contents=self.contents,
))
if __name__ == "__main__":
unittest.main()