"""Synthetic tests for tools/rbf0_encode.py. python -I tests/test_rbf0_encode.py Every byte here is built by the test. No game file, game asset path or game name is used. """ import io import json import math import os import struct import subprocess import sys import tempfile import unittest from contextlib import redirect_stderr, redirect_stdout ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(ROOT, "tools")) import rbf0_encode # noqa: E402 import rbf0_tree # noqa: E402 PROLOGUE = rbf0_tree.PROLOGUE class Stream: """Builds an RBF0 record stream; a descriptor gets its name on first use, as the format requires.""" def __init__(self, wide=True): self.wide = wide self.out = bytearray(b"RBF0" + (PROLOGUE if wide else b"")) self.names = [] def _rec(self, name, kind): if name in self.names: self.out += bytes((self.names.index(name), kind)) else: self.names.append(name) raw = name.encode() self.out += bytes((len(self.names) - 1, kind)) + struct.pack("