-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_planner.py
More file actions
123 lines (99 loc) · 3.38 KB
/
Copy pathtest_planner.py
File metadata and controls
123 lines (99 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
Tests for planner.py PlanManager
Run: python test_planner.py
"""
import tempfile
from pathlib import Path
from planner import PlanManager
def _new_manager() -> PlanManager:
return PlanManager(plan_dir=Path(tempfile.mkdtemp()))
def test_write_assigns_sequential_ids():
pm = _new_manager()
pm.write(
steps=[{"content": "a"}, {"content": "b", "status": "in_progress"}],
goal="demo goal",
title="demo",
)
plan = pm.get_plan()
assert [s["id"] for s in plan["steps"]] == [1, 2]
assert plan["steps"][0]["status"] == "pending"
assert plan["steps"][1]["status"] == "in_progress"
assert plan["goal"] == "demo goal"
assert plan["title"] == "demo"
assert pm.path.exists()
print("[PASS] test_write_assigns_sequential_ids")
def test_write_overwrites_existing():
pm = _new_manager()
pm.write(steps=[{"content": "a"}, {"content": "b"}, {"content": "c"}])
pm.write(steps=[{"content": "only"}])
plan = pm.get_plan()
assert len(plan["steps"]) == 1
assert plan["steps"][0]["content"] == "only"
assert plan["steps"][0]["id"] == 1
print("[PASS] test_write_overwrites_existing")
def test_write_normalizes_invalid_status():
pm = _new_manager()
pm.write(steps=[{"content": "a", "status": "bogus"}])
assert pm.get_plan()["steps"][0]["status"] == "pending"
print("[PASS] test_write_normalizes_invalid_status")
def test_update_step():
pm = _new_manager()
pm.write(steps=[{"content": "a"}, {"content": "b"}])
pm.update_step(1, status="completed")
pm.update_step(2, content="b2")
plan = pm.get_plan()
assert plan["steps"][0]["status"] == "completed"
assert plan["steps"][1]["content"] == "b2"
err = pm.update_step(1, status="bogus")
assert "invalid status" in err
missing = pm.update_step(99, status="completed")
assert "not found" in missing
print("[PASS] test_update_step")
def test_mark_all_and_pause():
pm = _new_manager()
pm.write(
steps=[
{"content": "a", "status": "in_progress"},
{"content": "b", "status": "pending"},
]
)
pm.pause()
assert all(s["status"] == "pending" for s in pm.get_plan()["steps"])
pm.update_step(1, status="in_progress")
pm.mark_all("completed")
assert all(s["status"] == "completed" for s in pm.get_plan()["steps"])
print("[PASS] test_mark_all_and_pause")
def test_set_goal_and_render():
pm = _new_manager()
assert pm.render() == "No plan yet."
pm.set_goal("the goal", title="t")
pm.write(steps=[{"content": "step one", "status": "completed"}])
rendered = pm.render()
assert "Goal: the goal" in rendered
assert "[x] #1 step one" in rendered
print("[PASS] test_set_goal_and_render")
def test_clear():
pm = _new_manager()
pm.write(steps=[{"content": "a"}], goal="g")
pm.clear()
plan = pm.get_plan()
assert plan["steps"] == []
assert plan["goal"] == ""
print("[PASS] test_clear")
def main():
print("=" * 60)
print("Testing planner.py PlanManager")
print("=" * 60)
test_write_assigns_sequential_ids()
test_write_overwrites_existing()
test_write_normalizes_invalid_status()
test_update_step()
test_mark_all_and_pause()
test_set_goal_and_render()
test_clear()
print()
print("=" * 60)
print("All planner.py tests passed!")
print("=" * 60)
if __name__ == "__main__":
main()