"""Synthetic-data tests for tools/instance_lists.py. python -I tests/test_instance_lists.py Every byte here is built by the test: a minimal 0x7a resource with the four list structs, one prop list with two instances and one grass list with three. No game file, value or name is used. """ import json import os import struct import subprocess import sys import tempfile import unittest import zlib ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOL = os.path.join(ROOT, "tools", "instance_lists.py") sys.path.insert(0, os.path.join(ROOT, "tools")) import instance_lists as il # noqa: E402 M = il.M def members(spec): """Member table: 16 bytes each (name hash, offset, type byte, padding).""" return b"".join(struct.pack(" tuple[bytes, bytes]: """Virtual buffer (header, schema, lists) and physical buffer (instances) of one 0x7a resource.""" V = bytearray(0x1000) V[0x10:0x15] = b"0DRPz" names = list(SCHEMA) struct.pack_into(" None: virtual, physical = resource(rotation_first=True) summary: dict = {} self.assertTrue(il.measure(virtual, physical, summary)) self.assertEqual(summary["grass"]["rotation_idx_max"], 72) self.assertEqual(summary["grass"], self.T["grass"]) def test_empty_list_is_counted(self): V = bytearray(self.V) struct.pack_into("= 48, but < 0x20 + 48 (80), so InstMat at +0x20 is truncated inst = b"\0" * 56 blocks = [(il.PROP_INST, len(inst), 0x60000000)] R = {} il.prop_list(bytes(pl), inst, blocks, structs, bytes(pl), 0, R) self.assertEqual(R.get("instances_truncated"), 1) class ArchiveTests(unittest.TestCase): def test_end_to_end(self): V, P = resource() with tempfile.TemporaryDirectory() as tmp: path = os.path.join(tmp, "fake.rpf") first = zlib.compress(V) first += b"\0" * (-len(first) % 16) with open(path, "wb") as fh: fh.write(b"RPF9" + struct.pack("", r.stderr) self.assertNotIn("Traceback", r.stderr) self.assertEqual(r.stdout, "") if __name__ == "__main__": unittest.main()