Initial commit: add .gitignore and README
This commit is contained in:
71
tests/test_schemas.py
Normal file
71
tests/test_schemas.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""Schema tests: Plan.from_dict, Plan.to_dict, and related deserialization."""
|
||||
|
||||
from fusionagi.schemas.plan import Plan, PlanStep
|
||||
|
||||
|
||||
def test_plan_from_dict_valid() -> None:
|
||||
d = {
|
||||
"steps": [
|
||||
{"id": "s1", "description": "Step 1", "dependencies": []},
|
||||
{"id": "s2", "description": "Step 2", "dependencies": ["s1"]},
|
||||
],
|
||||
"fallback_paths": [],
|
||||
"metadata": {},
|
||||
}
|
||||
plan = Plan.from_dict(d)
|
||||
assert len(plan.steps) == 2
|
||||
assert plan.steps[0].id == "s1"
|
||||
assert plan.steps[1].id == "s2"
|
||||
assert plan.steps[1].dependencies == ["s1"]
|
||||
assert plan.fallback_paths == []
|
||||
assert plan.metadata == {}
|
||||
|
||||
|
||||
def test_plan_from_dict_extra_keys() -> None:
|
||||
d = {
|
||||
"steps": [{"id": "s1", "description": "Step 1", "dependencies": []}],
|
||||
"fallback_paths": [],
|
||||
"metadata": {},
|
||||
"extra_key": "ignored",
|
||||
}
|
||||
plan = Plan.from_dict(d)
|
||||
assert len(plan.steps) == 1
|
||||
assert plan.steps[0].id == "s1"
|
||||
|
||||
|
||||
def test_plan_from_dict_empty_steps() -> None:
|
||||
d = {"steps": [], "fallback_paths": [], "metadata": {}}
|
||||
plan = Plan.from_dict(d)
|
||||
assert plan.steps == []
|
||||
assert plan.step_ids() == []
|
||||
|
||||
|
||||
def test_plan_from_dict_invalid_input() -> None:
|
||||
"""Plan.from_dict with non-dict raises TypeError."""
|
||||
try:
|
||||
Plan.from_dict(None) # type: ignore[arg-type]
|
||||
assert False, "expected TypeError"
|
||||
except TypeError as e:
|
||||
assert "expects dict" in str(e)
|
||||
try:
|
||||
Plan.from_dict("not a dict") # type: ignore[arg-type]
|
||||
assert False, "expected TypeError"
|
||||
except TypeError as e:
|
||||
assert "expects dict" in str(e)
|
||||
|
||||
|
||||
def test_plan_from_dict_to_dict_roundtrip() -> None:
|
||||
plan = Plan(
|
||||
steps=[
|
||||
PlanStep(id="a", description="A", dependencies=[]),
|
||||
PlanStep(id="b", description="B", dependencies=["a"]),
|
||||
],
|
||||
fallback_paths=[["a"]],
|
||||
metadata={"k": "v"},
|
||||
)
|
||||
d = plan.to_dict()
|
||||
restored = Plan.from_dict(d)
|
||||
assert len(restored.steps) == 2
|
||||
assert restored.steps[0].id == plan.steps[0].id
|
||||
assert restored.fallback_paths == plan.fallback_paths
|
||||
assert restored.metadata == plan.metadata
|
||||
Reference in New Issue
Block a user