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

33 lines
1.0 KiB
Python

import yaml
from edgemind import schema
from datetime import datetime
def test_local_problem_from_yaml():
with open("specs/LocalProblem.example.yaml", "r") as f:
data = yaml.safe_load(f)
lp = schema.LocalProblem(**data)
assert lp.id == "local_problem_001"
assert lp.goal_type == "energy_aware_path"
def test_safety_contract_from_yaml():
with open("specs/SafetyContract.example.yaml", "r") as f:
data = yaml.safe_load(f)
sc = schema.SafetyContract(**data)
assert sc.predicate == "battery_level >= 0.10"
def test_plan_delta_and_auditlog():
now = datetime.utcnow()
pd = schema.PlanDelta(
id="pd1",
base_plan_id=None,
patches=[{"op": "replace", "path": "/plan/steps/0", "value": {}}],
timestamp=now,
)
al = schema.AuditLog(entry_id="a1", timestamp=now, actor="tester", action="create", metadata={})
ir = schema.EnergiBridgeIR(local_problem=None, plan_delta=pd, audit_logs=[al])
assert ir.plan_delta.id == "pd1"
assert ir.audit_logs[0].actor == "tester"