"""Game-free actual Nup constructor/copy_to regression; requires zstandard. python -I -B nx2/test_nup_codec.py """ import argparse from contextlib import redirect_stdout import importlib.util import io from pathlib import Path import struct import tempfile from unittest.mock import patch import zstandard RUN_ALL_MODULES = ["zstandard"] p = argparse.ArgumentParser(description=__doc__) p.add_argument('--source', type=Path, default=Path(__file__).resolve().parents[1]) a = p.parse_args() spec = importlib.util.spec_from_file_location('tested_nup', a.source/'nx2/nup.py') nup = importlib.util.module_from_spec(spec) spec.loader.exec_module(nup) def package(name, logical, stored, codec, extent=None): """One title, one root directory, one file; no private content or other modules.""" name = name.encode() file_at = 0x80 + 0x30 + 0x40 + 24 strings_at = file_at + 80 + 4 data_at = (strings_at + len(name) + 15) & ~15 # The tail deliberately contains the rest of a truncated declared extent. blob = bytearray(data_at + len(stored) + len(logical) + 64) blob[:4] = b'NUP\x01' struct.pack_into('