-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest_command_decorators.py
149 lines (85 loc) · 3.18 KB
/
test_command_decorators.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from util import ConditionHolder, ManualSimTime
import commands2
def test_with_timeout(scheduler: commands2.CommandScheduler):
with ManualSimTime() as tm:
cmd = commands2.WaitCommand(10)
timeout = cmd.withTimeout(2)
scheduler.schedule(timeout)
scheduler.run()
assert not scheduler.isScheduled(cmd)
assert scheduler.isScheduled(timeout)
tm.step(3)
scheduler.run()
assert not scheduler.isScheduled(timeout)
def test_with_interrupt(scheduler: commands2.CommandScheduler):
cond = ConditionHolder()
cmd = commands2.WaitCommand(10)
timeout = cmd.withInterrupt(cond.getCondition)
scheduler.schedule(timeout)
scheduler.run()
assert not scheduler.isScheduled(cmd)
assert scheduler.isScheduled(timeout)
cond.setTrue()
scheduler.run()
assert not scheduler.isScheduled(cmd)
def test_before_starting(scheduler: commands2.CommandScheduler):
cond = ConditionHolder()
cmd = commands2.InstantCommand().beforeStarting(cond.setTrue)
scheduler.schedule(cmd)
assert cond.getCondition()
scheduler.run()
scheduler.run()
assert not scheduler.isScheduled(cmd)
def test_and_then_fn(scheduler: commands2.CommandScheduler):
cond = ConditionHolder()
cmd = commands2.InstantCommand().andThen(cond.setTrue)
scheduler.schedule(cmd)
assert not cond.getCondition()
scheduler.run()
scheduler.run()
assert not scheduler.isScheduled(cmd)
assert cond.getCondition()
def test_and_then_commands(scheduler: commands2.CommandScheduler):
cond = ConditionHolder()
cmd1 = commands2.InstantCommand()
cmd2 = commands2.InstantCommand(cond.setTrue)
scheduler.schedule(cmd1.andThen(cmd2))
assert not cond.getCondition()
scheduler.run()
assert cond.getCondition()
def test_deadline_with(scheduler: commands2.CommandScheduler):
cond = ConditionHolder()
dictator = commands2.WaitUntilCommand(cond.getCondition)
endsBefore = commands2.InstantCommand()
endsAfter = commands2.WaitUntilCommand(lambda: False)
group = dictator.deadlineWith(endsBefore, endsAfter)
scheduler.schedule(group)
scheduler.run()
assert scheduler.isScheduled(group)
cond.setTrue()
scheduler.run()
assert not scheduler.isScheduled(group)
def test_along_with(scheduler: commands2.CommandScheduler):
cond = ConditionHolder(False)
cmd1 = commands2.WaitUntilCommand(cond.getCondition)
cmd2 = commands2.InstantCommand()
group = cmd1.alongWith(cmd2)
scheduler.schedule(group)
scheduler.run()
assert scheduler.isScheduled(group)
cond.setTrue()
scheduler.run()
assert not scheduler.isScheduled(group)
def test_race_with(scheduler: commands2.CommandScheduler):
cmd1 = commands2.WaitUntilCommand(lambda: False)
cmd2 = commands2.InstantCommand()
group = cmd1.raceWith(cmd2)
scheduler.schedule(group)
scheduler.run()
assert not scheduler.isScheduled(group)
def test_perpetually(scheduler: commands2.CommandScheduler):
cmd = commands2.InstantCommand().perpetually()
scheduler.schedule(cmd)
scheduler.run()
scheduler.run()
assert scheduler.isScheduled(cmd)