Files
sglang/rust/sglang-processor/tests/scripts/fixture_json.py
T
2026-10-09 19:17:52 +08:00

24 lines
790 B
Python

"""The JSON layout of the parity fixtures."""
import json
def dump(fixture):
return compact(fixture, 0) + "\n"
def compact(value, indent):
"""JSON indented by two, with each value that fits in 100 columns on one line."""
flat = json.dumps(value, ensure_ascii=False)
if not isinstance(value, (dict, list)) or not value or indent + len(flat) <= 100:
return flat
pad = " " * (indent + 2)
if isinstance(value, dict):
items = [
f"{pad}{json.dumps(k, ensure_ascii=False)}: {compact(v, indent + 2)}"
for k, v in value.items()
]
return "{\n" + ",\n".join(items) + "\n" + " " * indent + "}"
items = [pad + compact(v, indent + 2) for v in value]
return "[\n" + ",\n".join(items) + "\n" + " " * indent + "]"