fix: name a DAT the importer skips for size

This commit is contained in:
Abdessamad Derraz committed 2026-10-18 14:56:51 +02:00
1 parent 3799d4a1a4
commit be0443a935
2 files changed
+34 -1

No files matched your search

+10 -1
View File
@@ -305,10 +305,19 @@ def _iter_dat_contents(pack: Path) -> Iterator[tuple[str, bytes]]:
if pack.suffix.lower() == ".zip":
with zipfile.ZipFile(pack) as archive:
for info in sorted(archive.infolist(), key=lambda i: i.filename):
if info.is_dir() or info.file_size > MAX_MEMBER_SIZE:
if info.is_dir():
continue
if Path(info.filename).suffix.lower() not in (".dat", ".xml"):
continue
if info.file_size > MAX_MEMBER_SIZE:
# Said out loud: a DAT left out silently ended the run
# on "Unchanged" with a version missing.
print(
f" Skipping {info.filename}: {info.file_size} bytes "
f"exceeds {MAX_MEMBER_SIZE}",
file=sys.stderr,
)
continue
yield info.filename, archive.read(info)
return
yield pack.name, pack.read_bytes()
+24
View File
@@ -641,5 +641,29 @@ class WriteRunsTheReportItWrites(unittest.TestCase):
self.assertEqual((alone.identify, alone.missing), (True, False))
class AnOversizedDatIsNamed(unittest.TestCase):
"""The romset importer skipped a DAT over its size cap without a word,
and the run ended on "Unchanged" with a version missing."""
def test_the_skip_is_reported(self):
import contextlib
import io
import zipfile
from unittest import mock
from scripts.scraper import romset_dat_importer as importer
with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory:
pack = Path(directory) / "pack.zip"
with zipfile.ZipFile(pack, "w") as archive:
archive.writestr("big.dat", b"x" * 64)
err = io.StringIO()
with mock.patch.object(importer, "MAX_MEMBER_SIZE", 16), \
contextlib.redirect_stderr(err):
self.assertEqual(list(importer._iter_dat_contents(pack)), [])
self.assertIn("Skipping big.dat", err.getvalue())
if __name__ == "__main__":
unittest.main()