2026-06-15 04:48:51 +02:00
|
|
|
"""Generate tests/testthat/golden_specs.R: the per-indicator spec list (canonical
|
|
|
|
|
name, archetype, ctor params, output width) consumed by test-golden-all.R, which
|
|
|
|
|
replays all 514 indicators against the Rust reference fixtures g_<Canonical>.csv.
|
|
|
|
|
|
|
|
|
|
Run from repo root: python bindings/r/gen_golden_test.py
|
|
|
|
|
"""
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
|
|
|
MAN = json.load(open(os.path.join(ROOT, "testdata", "golden", "golden_manifest.json")))
|
2026-06-15 17:19:24 +02:00
|
|
|
# Canonical core Indicator::name() per indicator, shared across every binding.
|
|
|
|
|
NAMES = json.load(open(os.path.join(ROOT, "testdata", "golden", "names.json")))
|
2026-06-15 04:48:51 +02:00
|
|
|
|
|
|
|
|
lines = [
|
|
|
|
|
"# Code generated by gen_golden_test.py. DO NOT EDIT.",
|
2026-06-15 17:19:24 +02:00
|
|
|
"# Per-indicator golden spec: canonical name, archetype, ctor params, output width, core name.",
|
2026-06-15 04:48:51 +02:00
|
|
|
"GOLDEN_SPECS <- list(",
|
|
|
|
|
]
|
|
|
|
|
for e in MAN:
|
|
|
|
|
n = e.get("n", e.get("width", 0))
|
|
|
|
|
params = ",".join(repr(float(p)) for p in e["params"])
|
2026-06-15 17:19:24 +02:00
|
|
|
nm = NAMES[e["canonical"]].replace("\\", "\\\\").replace('"', '\\"')
|
|
|
|
|
lines.append(
|
|
|
|
|
f' list(canon="{e["canonical"]}", arch="{e["arch"]}", params=c({params}), width={n}L, name="{nm}"),'
|
|
|
|
|
)
|
2026-06-15 04:48:51 +02:00
|
|
|
lines[-1] = lines[-1].rstrip(",")
|
|
|
|
|
lines.append(")")
|
|
|
|
|
|
|
|
|
|
dest = os.path.join(ROOT, "bindings", "r", "tests", "testthat", "golden_specs.R")
|
|
|
|
|
open(dest, "w", encoding="utf-8").write("\n".join(lines) + "\n")
|
|
|
|
|
print("wrote golden_specs.R with", len(MAN), "specs")
|