diff --git a/scripts/exporter/baseline.py b/scripts/exporter/baseline.py index 6fd86c11..18f8aad5 100644 --- a/scripts/exporter/baseline.py +++ b/scripts/exporter/baseline.py @@ -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: diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index 2cc6da75..c59b6959 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -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})