38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from gridverse.core_contracts import LocalProblem, SharedVariables, PlanDelta, ConstraintSet, DeviceInfo
|
|
|
|
|
|
def test_local_problem_roundtrip():
|
|
lp = LocalProblem(site_id="site-1", description="test", variables={"key": "value"})
|
|
d = lp.to_dict()
|
|
assert d["site_id"] == "site-1"
|
|
lp2 = LocalProblem.from_dict(d)
|
|
assert lp2.site_id == lp.site_id
|
|
|
|
|
|
def test_shared_variables_roundtrip():
|
|
sv = SharedVariables(signals={"p": 1.0}, version=2)
|
|
d = sv.to_dict()
|
|
sv2 = SharedVariables.from_dict(d)
|
|
assert sv2.signals == sv.signals and sv2.version == sv.version
|
|
|
|
|
|
def test_plan_delta_roundtrip():
|
|
pd = PlanDelta(delta_id="d1", changes={"a": 1}, timestamp=1.23)
|
|
d = pd.to_dict()
|
|
pd2 = PlanDelta.from_dict(d)
|
|
assert pd2.delta_id == pd.delta_id and pd2.timestamp == pd.timestamp
|
|
|
|
|
|
def test_constraint_set_roundtrip():
|
|
cs = ConstraintSet(constraints={"mesh": True})
|
|
d = cs.to_dict()
|
|
cs2 = ConstraintSet.from_dict(d)
|
|
assert cs2.constraints["mesh"] is True
|
|
|
|
|
|
def test_device_info_roundtrip():
|
|
di = DeviceInfo(device_id="dev-1", device_type="inverter", capabilities={"cap": 10})
|
|
d = di.to_dict()
|
|
di2 = DeviceInfo.from_dict(d)
|
|
assert di2.device_id == di.device_id and di2.device_type == di.device_type
|