-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathtest_enum.py
91 lines (73 loc) · 2.06 KB
/
test_enum.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# enum_test.py
from enum import Enum, enum
class Direction(Enum):
CW = "CW"
CCW = "CCW"
class State(Direction):
Stop = 1
Run = 2
Ready = 3
Disabled = False
Enabled = True
state = Enum()
print(state)
state = Direction()
print(state)
state = State()
print(state)
state = State({"X": 1.0, "Y": 2.0})
print(state)
state.Idle = 10
state.Triggered = 20
state.Lockout = 30
print(state)
print("Direction(Direction.CCW):", Direction(Direction.CCW))
print("Direction('CW'):", Direction("CW"))
print("state(10):", state(10))
print("state('CW'):", state("CW"))
print("type(state('CW')):", type(state("CW")))
print("state.key_from_value(20):", state.key_from_value(20))
print("len(state):", len(state))
print("state.Idle:", state.Idle)
print("type(state.Idle):", type(state.Idle))
current_state = state.Idle
print("current_state:", current_state)
if current_state == state.Idle:
print(" Idle state")
if current_state != state.Triggered:
print(" Not a triggered state")
current_state = state.Idle
print("current_state:", current_state)
print("state.key_from_value(current_state):", state.key_from_value(current_state))
state2 = eval(str(state))
print(state2)
print("state == state2:", state == state2)
del state.Triggered
print(state)
print("state == state2:", state == state2)
print("state.keys():", state.keys())
print("state.values():", state.values())
print("state.items():", state.items())
try:
del state.stop
except Exception as e:
print("Exception:", e)
assert current_state == state.Idle
assert current_state != state.Disabled
assert state.Idle != state.Disabled
print(
"State(State.Ready):",
State(State.Ready),
"type(State.Ready):",
type(State(State.Ready)),
"type(State.Ready):",
type(State.Ready),
)
assert int(str(State(State.Ready))) == State.Ready
assert int(str(State(State.Ready))) != State.Disabled
print("will raise exception")
try:
del state.Triggered
except Exception as e:
print("Exception:", e)
print("OK")