"""Synthetic tests for tools/anim_rigs.py. python -I tests/test_anim_rigs.py Every byte here is built by the test: a fake RPF9 data area with two rig dictionaries and one clip dictionary (the builders of tests/test_anim_clips.py), and a small rig-set JSON in the shape `anim_index.py --rigs` writes. No game file or game asset name is used. """ import json import os import struct import subprocess import sys import tempfile import unittest ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOL = os.path.join(ROOT, "tools", "anim_rigs.py") sys.path.insert(0, os.path.join(ROOT, "tools")) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import anim_rigs # noqa: E402 from anim_index import joaat32 # noqa: E402 from test_anim_clips import Page, two_sequence_dictionary, write_rpf # noqa: E402 KIND_A, KIND_B = joaat32("kind_a"), joaat32("kind_b") def rig_block(page, tables, version=2): """`RIG` + version, u32 length, 8 filler bytes, then each table {kind, 0xC + 8n, n, word} + n items.""" body = bytearray(b"\x11" * 8) for kind, items in tables: body += struct.pack("<4I", kind, 0xC + 8 * len(items), len(items), 0x0300) body += b"".join(struct.pack(" None: source = "src@one" first, second = RIGS[source].items() shared = {"anim/rig/x/shared": [(KIND_A, [10])]} write_rpf(self.rpf, [ rig_dictionary(source, dict([first]) | shared), rig_dictionary(source, dict([second]) | shared), rig_dictionary("src@two", RIGS["src@two"]), ]) dicts, _ = anim_rigs.scan(self.rpf) self.assertEqual([d["name"] for d in dicts], [source, source, "src@two"]) for dictionaries in (dicts, dicts[::-1]): joined = anim_rigs.join_rbf0(dictionaries, RIGSETS) self.assertEqual(joined["resolved"], 3) self.assertEqual(joined["keys_named_by_an_entry"], 3) self.assertEqual(joined["key_missing"], 1) self.assertEqual(joined["keys"], 5) def test_bad_block_is_reported_not_raised(self): page = bytearray(rig_dictionary("src@bad", {"anim/rig/b": [(KIND_A, [1])]})) at = page.rfind(b"RIG\x02") page[at:at + 3] = b"XYZ" rpf = os.path.join(self.tmp.name, "bad.rpf") write_rpf(rpf, [bytes(page)]) dicts, summary = anim_rigs.scan(rpf) self.assertEqual(summary["counts"]["rig_dictionaries_unparsed"], 1) self.assertIn("no RIG block", dicts[0]["error"]) def test_truncated_rig_header_is_reported_not_raised(self): p = Page() pm = p.alloc(bytes(16)) p.b[pm + 8], p.b[pm + 9] = 1, 0 p.ptr(8, pm) p.string(0x38, "src@trunc") struct.pack_into("