Co-authored-by: Kan Wu <kan.wu@radixark.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Shangming Cai <csmthu@gmail.com>
24 lines
790 B
Python
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 + "]"
|