"""Synthetic-tree tests for tools/rbf0_tree.py. python -I tests/test_rbf0_tree.py Every byte here is built by the test. No game file, game asset path or game name is used. """ import contextlib import csv import io import json import os import struct import subprocess import sys import tempfile import unittest from unittest.mock import patch from xml.etree import ElementTree as ET ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(ROOT, "tools")) import rbf0_tree # noqa: E402 import rbf0_index # noqa: E402 WIDE = b"RBF0" + rbf0_tree.PROLOGUE CLOSE = b"\xff\xff" def _name(name): return struct.pack(" Item(attrs=2) -> Child(text), then a value after the child.""" b = bytearray(WIDE) b += _open(0, b"TestRoot") b += _open(1, b"Item", attrs=2) b += _value(2, 0x10, struct.pack(" None: source = os.path.join(self.root, "text.bin") expected = "first\rsecond\r\n" with open(source, "wb") as f: f.write(WIDE + _open(0, b"TestRoot") + _text(expected.encode("utf-8")) + CLOSE) out = os.path.join(self.root, "tree.json") xml_dir = os.path.join(self.root, "xml") self.assertEqual(rbf0_tree.main([source, out, "--xml", xml_dir, "--quiet"]), 0) tree = ET.parse(os.path.join(xml_dir, "00000000.xml")) self.assertEqual(tree.findtext(".//text"), expected) def test_json_and_xml(self): blob = bytearray(WIDE) blob += _open(0, b"TestRoot", attrs=1) blob += _value(1, 0x60, struct.pack("