Skip to content

Commit b690857

Browse files
committed
Remove old commands test compat
1 parent 21291fa commit b690857

7 files changed

+139
-202
lines changed

Diff for: tests/compositiontestbase.py

+139-151
Original file line numberDiff line numberDiff line change
@@ -8,171 +8,159 @@
88

99
from util import *
1010

11-
if not IS_OLD_COMMANDS:
1211

13-
class SingleCompositionTestBase:
14-
def composeSingle(self, member: commands2.Command):
15-
raise NotImplementedError
16-
17-
@pytest.mark.parametrize(
18-
"interruptionBehavior",
19-
[
20-
commands2.InterruptionBehavior.kCancelSelf,
21-
commands2.InterruptionBehavior.kCancelIncoming,
22-
],
23-
)
24-
def test_interruptible(
25-
self, interruptionBehavior: commands2.InterruptionBehavior
26-
):
27-
command = self.composeSingle(
28-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
29-
interruptionBehavior
30-
)
12+
class SingleCompositionTestBase:
13+
def composeSingle(self, member: commands2.Command):
14+
raise NotImplementedError
15+
16+
@pytest.mark.parametrize(
17+
"interruptionBehavior",
18+
[
19+
commands2.InterruptionBehavior.kCancelSelf,
20+
commands2.InterruptionBehavior.kCancelIncoming,
21+
],
22+
)
23+
def test_interruptible(self, interruptionBehavior: commands2.InterruptionBehavior):
24+
command = self.composeSingle(
25+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
26+
interruptionBehavior
3127
)
32-
assert command.getInterruptionBehavior() == interruptionBehavior
33-
34-
@pytest.mark.parametrize("runsWhenDisabled", [True, False])
35-
def test_runWhenDisabled(self, runsWhenDisabled: bool):
36-
command = self.composeSingle(
37-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(
38-
runsWhenDisabled
39-
)
40-
)
41-
assert command.runsWhenDisabled() == runsWhenDisabled
28+
)
29+
assert command.getInterruptionBehavior() == interruptionBehavior
4230

43-
def test_command_in_other_composition(self):
44-
command = commands2.InstantCommand()
45-
wrapped = commands2.WrapperCommand(command)
46-
with pytest.raises(commands2.IllegalCommandUse):
47-
self.composeSingle(command)
31+
@pytest.mark.parametrize("runsWhenDisabled", [True, False])
32+
def test_runWhenDisabled(self, runsWhenDisabled: bool):
33+
command = self.composeSingle(
34+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(runsWhenDisabled)
35+
)
36+
assert command.runsWhenDisabled() == runsWhenDisabled
4837

49-
def test_command_in_multiple_compositions(self):
50-
command = commands2.InstantCommand()
38+
def test_command_in_other_composition(self):
39+
command = commands2.InstantCommand()
40+
wrapped = commands2.WrapperCommand(command)
41+
with pytest.raises(commands2.IllegalCommandUse):
5142
self.composeSingle(command)
52-
with pytest.raises(commands2.IllegalCommandUse):
53-
self.composeSingle(command)
5443

55-
def test_compose_then_schedule(self, scheduler: commands2.CommandScheduler):
56-
command = commands2.InstantCommand()
44+
def test_command_in_multiple_compositions(self):
45+
command = commands2.InstantCommand()
46+
self.composeSingle(command)
47+
with pytest.raises(commands2.IllegalCommandUse):
5748
self.composeSingle(command)
58-
with pytest.raises(commands2.IllegalCommandUse):
59-
scheduler.schedule(command)
6049

61-
def test_schedule_then_compose(self, scheduler: commands2.CommandScheduler):
62-
command = commands2.RunCommand(lambda: None)
50+
def test_compose_then_schedule(self, scheduler: commands2.CommandScheduler):
51+
command = commands2.InstantCommand()
52+
self.composeSingle(command)
53+
with pytest.raises(commands2.IllegalCommandUse):
6354
scheduler.schedule(command)
64-
with pytest.raises(commands2.IllegalCommandUse):
65-
self.composeSingle(command)
66-
67-
class MultiCompositionTestBase(SingleCompositionTestBase):
68-
def compose(self, *members: commands2.Command):
69-
raise NotImplementedError
70-
71-
def composeSingle(self, member: commands2.Command):
72-
return self.compose(member)
73-
74-
@pytest.mark.parametrize(
75-
"expected,command1,command2,command3",
76-
[
77-
pytest.param(
78-
commands2.InterruptionBehavior.kCancelSelf,
79-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
80-
commands2.InterruptionBehavior.kCancelSelf
81-
),
82-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
83-
commands2.InterruptionBehavior.kCancelSelf
84-
),
85-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
86-
commands2.InterruptionBehavior.kCancelSelf
87-
),
88-
id="AllCancelSelf",
55+
56+
def test_schedule_then_compose(self, scheduler: commands2.CommandScheduler):
57+
command = commands2.RunCommand(lambda: None)
58+
scheduler.schedule(command)
59+
with pytest.raises(commands2.IllegalCommandUse):
60+
self.composeSingle(command)
61+
62+
63+
class MultiCompositionTestBase(SingleCompositionTestBase):
64+
def compose(self, *members: commands2.Command):
65+
raise NotImplementedError
66+
67+
def composeSingle(self, member: commands2.Command):
68+
return self.compose(member)
69+
70+
@pytest.mark.parametrize(
71+
"expected,command1,command2,command3",
72+
[
73+
pytest.param(
74+
commands2.InterruptionBehavior.kCancelSelf,
75+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
76+
commands2.InterruptionBehavior.kCancelSelf
8977
),
90-
pytest.param(
91-
commands2.InterruptionBehavior.kCancelIncoming,
92-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
93-
commands2.InterruptionBehavior.kCancelIncoming
94-
),
95-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
96-
commands2.InterruptionBehavior.kCancelIncoming
97-
),
98-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
99-
commands2.InterruptionBehavior.kCancelIncoming
100-
),
101-
id="AllCancelIncoming",
78+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
79+
commands2.InterruptionBehavior.kCancelSelf
10280
),
103-
pytest.param(
104-
commands2.InterruptionBehavior.kCancelSelf,
105-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
106-
commands2.InterruptionBehavior.kCancelSelf
107-
),
108-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
109-
commands2.InterruptionBehavior.kCancelSelf
110-
),
111-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
112-
commands2.InterruptionBehavior.kCancelIncoming
113-
),
114-
id="TwoCancelSelfOneIncoming",
81+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
82+
commands2.InterruptionBehavior.kCancelSelf
11583
),
116-
pytest.param(
117-
commands2.InterruptionBehavior.kCancelSelf,
118-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
119-
commands2.InterruptionBehavior.kCancelIncoming
120-
),
121-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
122-
commands2.InterruptionBehavior.kCancelIncoming
123-
),
124-
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
125-
commands2.InterruptionBehavior.kCancelSelf
126-
),
127-
id="TwoCancelIncomingOneSelf",
84+
id="AllCancelSelf",
85+
),
86+
pytest.param(
87+
commands2.InterruptionBehavior.kCancelIncoming,
88+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
89+
commands2.InterruptionBehavior.kCancelIncoming
12890
),
129-
],
130-
)
131-
def test_interruptible(self, expected, command1, command2, command3):
132-
command = self.compose(command1, command2, command3)
133-
assert command.getInterruptionBehavior() == expected
134-
135-
@pytest.mark.parametrize(
136-
"expected,command1,command2,command3",
137-
[
138-
pytest.param(
139-
False,
140-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
141-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
142-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
143-
id="AllFalse",
91+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
92+
commands2.InterruptionBehavior.kCancelIncoming
14493
),
145-
pytest.param(
146-
True,
147-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
148-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
149-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
150-
id="AllTrue",
94+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
95+
commands2.InterruptionBehavior.kCancelIncoming
15196
),
152-
pytest.param(
153-
False,
154-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
155-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
156-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
157-
id="TwoTrueOneFalse",
97+
id="AllCancelIncoming",
98+
),
99+
pytest.param(
100+
commands2.InterruptionBehavior.kCancelSelf,
101+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
102+
commands2.InterruptionBehavior.kCancelSelf
158103
),
159-
pytest.param(
160-
False,
161-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
162-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
163-
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
164-
id="TwoFalseOneTrue",
104+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
105+
commands2.InterruptionBehavior.kCancelSelf
165106
),
166-
],
167-
)
168-
def test_runWhenDisabled(self, expected, command1, command2, command3):
169-
command = self.compose(command1, command2, command3)
170-
assert command.runsWhenDisabled() == expected
171-
172-
else:
173-
174-
class SingleCompositionTestBase:
175-
...
176-
177-
class MultiCompositionTestBase:
178-
...
107+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
108+
commands2.InterruptionBehavior.kCancelIncoming
109+
),
110+
id="TwoCancelSelfOneIncoming",
111+
),
112+
pytest.param(
113+
commands2.InterruptionBehavior.kCancelSelf,
114+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
115+
commands2.InterruptionBehavior.kCancelIncoming
116+
),
117+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
118+
commands2.InterruptionBehavior.kCancelIncoming
119+
),
120+
commands2.WaitUntilCommand(lambda: False).withInterruptBehavior(
121+
commands2.InterruptionBehavior.kCancelSelf
122+
),
123+
id="TwoCancelIncomingOneSelf",
124+
),
125+
],
126+
)
127+
def test_interruptible(self, expected, command1, command2, command3):
128+
command = self.compose(command1, command2, command3)
129+
assert command.getInterruptionBehavior() == expected
130+
131+
@pytest.mark.parametrize(
132+
"expected,command1,command2,command3",
133+
[
134+
pytest.param(
135+
False,
136+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
137+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
138+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
139+
id="AllFalse",
140+
),
141+
pytest.param(
142+
True,
143+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
144+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
145+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
146+
id="AllTrue",
147+
),
148+
pytest.param(
149+
False,
150+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
151+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
152+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
153+
id="TwoTrueOneFalse",
154+
),
155+
pytest.param(
156+
False,
157+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
158+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(False),
159+
commands2.WaitUntilCommand(lambda: False).ignoringDisable(True),
160+
id="TwoFalseOneTrue",
161+
),
162+
],
163+
)
164+
def test_runWhenDisabled(self, expected, command1, command2, command3):
165+
command = self.compose(command1, command2, command3)
166+
assert command.runsWhenDisabled() == expected

Diff for: tests/test_command_decorators.py

-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def test_until(scheduler: commands2.CommandScheduler):
3333
assert not command.isScheduled()
3434

3535

36-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
3736
def test_only_while(scheduler: commands2.CommandScheduler):
3837
condition = OOBoolean(True)
3938
command = commands2.WaitCommand(10).onlyWhile(condition)
@@ -45,7 +44,6 @@ def test_only_while(scheduler: commands2.CommandScheduler):
4544
assert not command.isScheduled()
4645

4746

48-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
4947
def test_ignoringDisable(scheduler: commands2.CommandScheduler):
5048
command = commands2.RunCommand(lambda: None).ignoringDisable(True)
5149
DriverStationSim.setEnabled(False)
@@ -127,7 +125,6 @@ def test_raceWith(scheduler: commands2.CommandScheduler):
127125
assert not group.isScheduled()
128126

129127

130-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
131128
def test_unless(scheduler: commands2.CommandScheduler):
132129
unlessCondition = OOBoolean(True)
133130
hasRunCondition = OOBoolean(False)
@@ -145,7 +142,6 @@ def test_unless(scheduler: commands2.CommandScheduler):
145142
assert hasRunCondition == True
146143

147144

148-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
149145
def test_onlyIf(scheduler: commands2.CommandScheduler):
150146
onlyIfCondition = OOBoolean(False)
151147
hasRunCondition = OOBoolean(False)
@@ -163,7 +159,6 @@ def test_onlyIf(scheduler: commands2.CommandScheduler):
163159
assert hasRunCondition == True
164160

165161

166-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
167162
def test_finallyDo(scheduler: commands2.CommandScheduler):
168163
first = OOInteger(0)
169164
second = OOInteger(0)
@@ -183,7 +178,6 @@ def test_finallyDo(scheduler: commands2.CommandScheduler):
183178
assert second == 2
184179

185180

186-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
187181
def test_handleInterrupt(scheduler: commands2.CommandScheduler):
188182
first = OOInteger(0)
189183
second = OOInteger(0)
@@ -204,7 +198,6 @@ def test_handleInterrupt(scheduler: commands2.CommandScheduler):
204198
assert second == 2
205199

206200

207-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
208201
def test_withName(scheduler: commands2.CommandScheduler):
209202
command = commands2.InstantCommand()
210203
name = "Named"

Diff for: tests/test_command_requirements.py

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def test_requirementInterrupt(scheduler: commands2.CommandScheduler):
3434
assert interrupter.isScheduled()
3535

3636

37-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
3837
def test_requirementUninterruptible(scheduler: commands2.CommandScheduler):
3938
requirement = commands2.Subsystem()
4039
notInterrupted = commands2.RunCommand(

Diff for: tests/test_commandgroup_error.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def test_commandInGroupExternallyScheduled(scheduler: commands2.CommandScheduler
2828
scheduler.schedule(command1)
2929

3030

31-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
3231
def test_redecoratedCommandError(scheduler: commands2.CommandScheduler):
3332
command = commands2.InstantCommand()
3433
command.withTimeout(10).until(lambda: False)

Diff for: tests/test_proxycommand.py

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pytest
1010

1111

12-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
1312
def test_proxyCommandSchedule(scheduler: commands2.CommandScheduler):
1413
command1 = commands2.Command()
1514
start_spying_on(command1)
@@ -21,7 +20,6 @@ def test_proxyCommandSchedule(scheduler: commands2.CommandScheduler):
2120
verify(command1).schedule()
2221

2322

24-
@pytest.mark.skipif(IS_OLD_COMMANDS, reason="not in old commands")
2523
def test_proxyCommandEnd(scheduler: commands2.CommandScheduler):
2624
cond = OOBoolean()
2725

0 commit comments

Comments
 (0)