mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-10 21:43:23 -05:00
fix: count mister corrections only where it writes
This commit is contained in:
1 parent
44cf638e06
commit
ced7588d17
2 files changed
+26
-1
No files matched your search
@@ -13,7 +13,7 @@ import zipfile
|
||||
from collections import OrderedDict
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from .baseline import NativeSystem, Report
|
||||
from .baseline import NativeFile, NativeSystem, Report
|
||||
|
||||
SOURCE_URL = (
|
||||
"https://raw.githubusercontent.com/ajgowans/BiosDB_MiSTer/db/bios_db.json.zip"
|
||||
@@ -57,6 +57,13 @@ class Exporter(BaseExporter):
|
||||
with zipfile.ZipFile(io.BytesIO(raw)) as archive:
|
||||
return {_DB_NAME: archive.read(_DB_NAME).decode("utf-8")}
|
||||
|
||||
def states(self, fe: NativeFile, field_name: str) -> bool:
|
||||
"""A correction whose path the database does not hold is not written."""
|
||||
written = getattr(self, "_written", None)
|
||||
if written is not None and id(fe) not in written:
|
||||
return False
|
||||
return super().states(fe, field_name)
|
||||
|
||||
def _by_path(self, systems: dict[str, NativeSystem]) -> dict[str, object]:
|
||||
indexed: dict[str, object] = {}
|
||||
for system in systems.values():
|
||||
@@ -80,11 +87,13 @@ class Exporter(BaseExporter):
|
||||
)
|
||||
database = json.loads(original, object_pairs_hook=OrderedDict)
|
||||
indexed = self._by_path(systems)
|
||||
self._written = set()
|
||||
|
||||
for path, entry in database.get("files", {}).items():
|
||||
fe = indexed.get(path)
|
||||
if fe is None:
|
||||
continue
|
||||
self._written.add(id(fe))
|
||||
md5 = fe.hash("md5")
|
||||
if md5:
|
||||
entry["hash"] = md5
|
||||
|
||||
@@ -181,6 +181,22 @@ class BizHawkCountsWhatItWrites(unittest.TestCase):
|
||||
self.assertFalse(exporter.states(first, "sha1"))
|
||||
|
||||
|
||||
class MisterCountsWhatItWrites(unittest.TestCase):
|
||||
def test_a_path_the_database_lacks_is_not_counted(self):
|
||||
from exporter.misterfpga_exporter import Exporter as Mister
|
||||
|
||||
held = NativeFile("boot.rom", "NES/boot.rom", "nes", platform={"md5": A},
|
||||
truth={"md5": B}, corrections=["md5"])
|
||||
absent = NativeFile("boot.rom", "SNES/boot.rom", "snes", platform={"md5": A},
|
||||
truth={"md5": C}, corrections=["md5"])
|
||||
systems = {"nes": NativeSystem("nes", files=[held]), "snes": NativeSystem("snes", files=[absent])}
|
||||
database = {"db_id": "x", "files": {"games/NES/boot.rom": {"hash": A, "url": "u"}}}
|
||||
exporter = Mister()
|
||||
exporter.render(systems, None, {"bios_db.json": json.dumps(database)})
|
||||
self.assertTrue(exporter.states(held, "md5"))
|
||||
self.assertFalse(exporter.states(absent, "md5"))
|
||||
|
||||
|
||||
class ModelKeepsOneFileOneEntry(unittest.TestCase):
|
||||
def test_size_describes_the_hash_written(self):
|
||||
fe = NativeFile("boot.bin", "dc/boot.bin", "dc",
|
||||
|
||||
Reference in new issue
Block a user