-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathtest_state_machine.py
51 lines (38 loc) · 1.29 KB
/
test_state_machine.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
import conftest
from MissionPlanning.StateMachine.state_machine import StateMachine
def test_transition():
sm = StateMachine("state_machine")
sm.add_transition(src_state="idle", event="start", dst_state="running")
sm.set_current_state("idle")
sm.process("start")
assert sm.get_current_state().name == "running"
def test_guard():
class Model:
def can_start(self):
return False
sm = StateMachine("state_machine", Model())
sm.add_transition(
src_state="idle", event="start", dst_state="running", guard="can_start"
)
sm.set_current_state("idle")
sm.process("start")
assert sm.get_current_state().name == "idle"
def test_action():
class Model:
def on_start(self):
self.start_called = True
model = Model()
sm = StateMachine("state_machine", model)
sm.add_transition(
src_state="idle", event="start", dst_state="running", action="on_start"
)
sm.set_current_state("idle")
sm.process("start")
assert model.start_called
def test_plantuml():
sm = StateMachine("state_machine")
sm.add_transition(src_state="idle", event="start", dst_state="running")
sm.set_current_state("idle")
assert sm.generate_plantuml()
if __name__ == "__main__":
conftest.run_this_test(__file__)