-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathtest_conditions_algebra.py
More file actions
65 lines (43 loc) · 1.63 KB
/
test_conditions_algebra.py
File metadata and controls
65 lines (43 loc) · 1.63 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
import pytest
from statemachine.exceptions import InvalidDefinition
from statemachine import State
from statemachine import StateMachine
class AnyConditionSM(StateMachine):
start = State(initial=True)
end = State(final=True)
submit = start.to(end, cond="used_money or used_credit")
used_money: bool = False
used_credit: bool = False
def test_conditions_algebra_any_false():
sm = AnyConditionSM()
with pytest.raises(sm.TransitionNotAllowed):
sm.submit()
assert sm.current_state == sm.start
def test_conditions_algebra_any_left_true():
sm = AnyConditionSM()
sm.used_money = True
sm.submit()
assert sm.current_state == sm.end
def test_conditions_algebra_any_right_true():
sm = AnyConditionSM()
sm.used_credit = True
sm.submit()
assert sm.current_state == sm.end
def test_should_raise_invalid_definition_if_cond_is_not_valid_sintax():
class AnyConditionSM(StateMachine):
start = State(initial=True)
end = State(final=True)
submit = start.to(end, cond="used_money xxx")
used_money: bool = False
used_credit: bool = False
with pytest.raises(InvalidDefinition, match="Failed to parse boolean expression"):
AnyConditionSM()
def test_should_raise_invalid_definition_if_cond_is_not_found():
class AnyConditionSM(StateMachine):
start = State(initial=True)
end = State(final=True)
submit = start.to(end, cond="used_money and xxx")
used_money: bool = False
used_credit: bool = False
with pytest.raises(InvalidDefinition, match="Did not found name 'xxx'"):
AnyConditionSM()