"""Synthetic tests for tools/psin_names.py (no game data: every name and hash is invented).""" import json import os import struct import subprocess import sys import tempfile import unittest from unittest import mock ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOL = os.path.join(ROOT, "tools", "psin_names.py") sys.path.insert(0, os.path.join(ROOT, "tools")) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import psin_names as N # noqa: E402 from test_psin_data import make_container, ptr # noqa: E402 from test_psin_index import joaat # noqa: E402 def mm64(name): return N.murmur3_x64_128(name.encode())[0] ROOT_T = joaat("PropSet") MODEL, KEY, MODELS, OTHER = joaat("model"), joaat("key"), joaat("models"), joaat("other") MEMBERS = [ (0x100, 0, 0x4A, 0, 0, 0), # 0: element descriptor, u32 hash (MODEL, 0x00, 0x4A, 0, 0, 0), # u32 name hash (OTHER, 0x04, 0x4D, 0, 0, 0), # u32 hash that is not a listed name (KEY, 0x08, 0x4F, 0, 0, 0), # u64 name key (MODELS, 0x10, 0x5C, 0, 0, 0), # {u32 count, u32 capacity, ptr} -> u32 hash[] ] SCHEMA = [(ROOT_T, 0x3, 0x20, 1, MEMBERS)] NAMES = ["prop_crate_01", "prop_barrel_02", "Prop_Lamp_03"] def sample(model="prop_crate_01", key="prop_crate_01", models=("prop_barrel_02", "prop_lamp_03"), other=0x12345678): root = bytearray(0x20) struct.pack_into("