forked from elizaOS/agentloop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
68 lines (55 loc) · 2.05 KB
/
test.py
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
import threading
import time
from agentloop import start, step, stop
def step_one(options_dict, loop_data):
if options_dict is None:
options_dict = {"step_one": 0, "step_two": 0}
# increment step_one
options_dict["step_one"] += 1
print("step_one: ", options_dict["step_one"])
return options_dict
def step_two(options_dict, loop_data):
# increment step_two
options_dict["step_two"] += 1
print("step_two: ", options_dict["step_two"])
return options_dict
def inner_loop(context):
loop_data = start(steps=[step_one, step_two], stepped=False)
for _ in range(3):
step(loop_data)
# sleep 1 s
time.sleep(0.1)
stop(loop_data) # Stop the loop
return context
def test_inner_loop():
print("Starting test_start")
loop_data = start(steps=[step_one, inner_loop, step_two], stepped=False)
for _ in range(3):
step(loop_data)
# sleep 1 s
time.sleep(0.1)
assert isinstance(loop_data["thread"], threading.Thread)
assert isinstance(loop_data["step_event"], threading.Event)
assert loop_data["thread"].is_alive() is True
stop(loop_data) # Stop the loop
assert loop_data["thread"].is_alive() is False
def test_start():
print("Starting test_start")
loop_data = start(steps=[step_one, step_two], stepped=False)
assert isinstance(loop_data["thread"], threading.Thread)
assert isinstance(loop_data["step_event"], threading.Event)
assert loop_data["thread"].is_alive() is True
stop(loop_data) # Stop the loop
assert loop_data["thread"].is_alive() is False
def test_start_stepped():
print("Starting test_start_stepped")
loop_data = start(steps=[step_one, step_two], stepped=True)
assert isinstance(loop_data["thread"], threading.Thread)
assert isinstance(loop_data["step_event"], threading.Event)
assert loop_data["thread"].is_alive() is True
for _ in range(5):
step(loop_data)
# sleep 1 s
time.sleep(0.1)
stop(loop_data) # Stop the loop
assert loop_data["thread"].is_alive() is False