mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-10 13:33:24 -05:00
fix: state no size for several accepted sizes
This commit is contained in:
1 parent
f3d01aeeeb
commit
500535b7a6
2 files changed
+17
-1
No files matched your search
@@ -42,6 +42,15 @@ def _field_sets(entry: dict | None) -> dict[str, set[str]]:
|
||||
return {f: set(_hash_values(entry or {}, f)) for f in HASH_FIELDS}
|
||||
|
||||
|
||||
def _single_size(value: object) -> int | None:
|
||||
"""One size, or None: a list names several accepted revisions, which a
|
||||
single size field cannot state (int() on it stopped the whole export)."""
|
||||
if isinstance(value, list):
|
||||
distinct = {int(v) for v in value}
|
||||
return distinct.pop() if len(distinct) == 1 else None
|
||||
return int(value)
|
||||
|
||||
|
||||
@dataclass
|
||||
class NativeFile:
|
||||
"""One file as the platform will read it, after correction."""
|
||||
@@ -147,7 +156,7 @@ class NativeFile:
|
||||
order = (self.platform, self.truth) if source == "platform" else (self.truth, self.platform)
|
||||
for entry in order:
|
||||
if entry and entry.get("size"):
|
||||
return int(entry["size"])
|
||||
return _single_size(entry["size"])
|
||||
return None
|
||||
|
||||
def native(self, key: str, default: object = "") -> object:
|
||||
|
||||
@@ -196,6 +196,13 @@ class MisterCountsWhatItWrites(unittest.TestCase):
|
||||
|
||||
|
||||
class ModelKeepsOneFileOneEntry(unittest.TestCase):
|
||||
def test_a_list_of_sizes_is_not_one_size(self):
|
||||
"""A profile may accept several revisions; int() on the list crashed."""
|
||||
several = NativeFile("a.bin", "a.bin", "s", truth={"size": [1024, 2048], "crc32": "aaaaaaaa"})
|
||||
single = NativeFile("b.bin", "b.bin", "s", truth={"size": [1024], "crc32": "aaaaaaaa"})
|
||||
self.assertIsNone(several.size())
|
||||
self.assertEqual(single.size(), 1024)
|
||||
|
||||
def test_size_describes_the_hash_written(self):
|
||||
fe = NativeFile("boot.bin", "dc/boot.bin", "dc",
|
||||
platform={"size": 2097152, "md5": A}, truth={"size": 480})
|
||||
|
||||
Reference in new issue
Block a user