idea15-edgemind-verifiable-.../tests/test_generate_schemas.py

31 lines
965 B
Python

from pathlib import Path
import json
import specs.ir as ir
def test_generate_schemas(tmp_path: Path):
out = tmp_path / "schemas"
out.mkdir()
# mimic the generator logic: iterate ir.__all__ and ensure JSON serializable
for name in getattr(ir, "__all__", []):
cls = getattr(ir, name, None)
assert cls is not None, f"Missing model class for {name}"
# get schema (compat v1/v2)
if hasattr(cls, "model_json_schema"):
try:
schema = cls.model_json_schema()
except TypeError:
schema = cls.schema()
else:
schema = cls.schema()
# ensure JSON serializable
json_str = json.dumps(schema)
assert "title" in json.loads(json_str) or "properties" in json.loads(json_str)
# write out to disk and ensure file exists
p = out / f"{name}.json"
p.write_text(json_str, encoding="utf8")
assert p.exists()