"""Verify the public format through an independent Python implementation.""" import importlib.util import math from pathlib import Path import struct import subprocess import sys import tempfile def main(): """Check native/text equality and CSV output using files produced by C++.""" sys.dont_write_bytecode = True writer, reader_path = sys.argv[1:] spec = importlib.util.spec_from_file_location("serif_archive", reader_path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) with tempfile.TemporaryDirectory(prefix="serif-python-reader-") as directory: subprocess.run([writer, directory], check=True) representations = [] for encoding in ("binary", "text"): path = Path(directory) / f"{encoding}.serif" with module.Archive(path) as archive: values = archive.read("values") assert len(values) == 5 assert math.copysign(1.0, values[0]) < 0 assert values[1] == 1.2345678901234567 assert values[2] == float.fromhex("0x0.0000000000001p-1022") assert values[3] == math.inf assert struct.pack("