forked from robotpy/robotpy-commands-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_robotdisabledcommand.py
157 lines (112 loc) · 5.03 KB
/
test_robotdisabledcommand.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
150
151
152
153
154
155
156
157
from typing import TYPE_CHECKING
import commands2
from util import * # type: ignore
if TYPE_CHECKING:
from .util import *
if IS_OLD_COMMANDS:
import commands2.cmd
import pytest
from wpilib import RobotState
def test_robotDisabledCommandCancel(scheduler: commands2.CommandScheduler):
command = commands2.Command()
scheduler.schedule(command)
assert scheduler.isScheduled(command)
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
scheduler.run()
assert not scheduler.isScheduled(command)
DriverStationSim.setEnabled(True)
DriverStationSim.notifyNewData()
def test_runWhenDisabled(scheduler: commands2.CommandScheduler):
command = commands2.Command()
command.runsWhenDisabled = lambda: True
scheduler.schedule(command)
assert scheduler.isScheduled(command)
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
scheduler.run()
assert scheduler.isScheduled(command)
def test_sequentialGroupRunWhenDisabled(scheduler: commands2.CommandScheduler):
command1 = commands2.Command()
command1.runsWhenDisabled = lambda: True
command2 = commands2.Command()
command2.runsWhenDisabled = lambda: True
command3 = commands2.Command()
command3.runsWhenDisabled = lambda: True
command4 = commands2.Command()
command4.runsWhenDisabled = lambda: False
runWhenDisabled = commands2.SequentialCommandGroup(command1, command2)
dontRunWhenDisabled = commands2.SequentialCommandGroup(command3, command4)
scheduler.schedule(runWhenDisabled)
scheduler.schedule(dontRunWhenDisabled)
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
scheduler.run()
assert scheduler.isScheduled(runWhenDisabled)
assert not scheduler.isScheduled(dontRunWhenDisabled)
def test_parallelGroupRunWhenDisabled(scheduler: commands2.CommandScheduler):
command1 = commands2.Command()
command1.runsWhenDisabled = lambda: True
command2 = commands2.Command()
command2.runsWhenDisabled = lambda: True
command3 = commands2.Command()
command3.runsWhenDisabled = lambda: True
command4 = commands2.Command()
command4.runsWhenDisabled = lambda: False
runWhenDisabled = commands2.ParallelCommandGroup(command1, command2)
dontRunWhenDisabled = commands2.ParallelCommandGroup(command3, command4)
scheduler.schedule(runWhenDisabled)
scheduler.schedule(dontRunWhenDisabled)
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
scheduler.run()
assert scheduler.isScheduled(runWhenDisabled)
assert not scheduler.isScheduled(dontRunWhenDisabled)
def test_conditionalRunWhenDisabled(scheduler: commands2.CommandScheduler):
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
command1 = commands2.Command()
command1.runsWhenDisabled = lambda: True
command2 = commands2.Command()
command2.runsWhenDisabled = lambda: True
command3 = commands2.Command()
command3.runsWhenDisabled = lambda: True
command4 = commands2.Command()
command4.runsWhenDisabled = lambda: False
runWhenDisabled = commands2.ConditionalCommand(command1, command2, lambda: True)
dontRunWhenDisabled = commands2.ConditionalCommand(command3, command4, lambda: True)
scheduler.schedule(runWhenDisabled, dontRunWhenDisabled)
assert scheduler.isScheduled(runWhenDisabled)
assert not scheduler.isScheduled(dontRunWhenDisabled)
def test_selectRunWhenDisabled(scheduler: commands2.CommandScheduler):
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
command1 = commands2.Command()
command1.runsWhenDisabled = lambda: True
command2 = commands2.Command()
command2.runsWhenDisabled = lambda: True
command3 = commands2.Command()
command3.runsWhenDisabled = lambda: True
command4 = commands2.Command()
command4.runsWhenDisabled = lambda: False
runWhenDisabled = commands2.SelectCommand({1: command1, 2: command2}, lambda: 1)
dontRunWhenDisabled = commands2.SelectCommand({1: command3, 2: command4}, lambda: 1)
scheduler.schedule(runWhenDisabled, dontRunWhenDisabled)
assert scheduler.isScheduled(runWhenDisabled)
assert not scheduler.isScheduled(dontRunWhenDisabled)
def test_parallelConditionalRunWhenDisabledTest(scheduler: commands2.CommandScheduler):
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
command1 = commands2.Command()
command1.runsWhenDisabled = lambda: True
command2 = commands2.Command()
command2.runsWhenDisabled = lambda: True
command3 = commands2.Command()
command3.runsWhenDisabled = lambda: True
command4 = commands2.Command()
command4.runsWhenDisabled = lambda: False
runWhenDisabled = commands2.ConditionalCommand(command1, command2, lambda: True)
dontRunWhenDisabled = commands2.ConditionalCommand(command3, command4, lambda: True)
parallel = commands2.cmd.parallel(runWhenDisabled, dontRunWhenDisabled)
scheduler.schedule(parallel)
assert not scheduler.isScheduled(runWhenDisabled)