forked from robotpy/robotpy-commands-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_default_command.py
73 lines (46 loc) · 1.94 KB
/
test_default_command.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
from typing import TYPE_CHECKING
import commands2
from util import * # type: ignore
if TYPE_CHECKING:
from .util import *
import pytest
def test_defaultCommandSchedule(scheduler: commands2.CommandScheduler):
hasDefaultCommand = commands2.Subsystem()
defaultCommand = commands2.Command()
defaultCommand.addRequirements(hasDefaultCommand)
scheduler.setDefaultCommand(hasDefaultCommand, defaultCommand)
scheduler.run()
assert scheduler.isScheduled(defaultCommand)
def test_defaultCommandInterruptResume(scheduler: commands2.CommandScheduler):
hasDefaultCommand = commands2.Subsystem()
defaultCommand = commands2.Command()
defaultCommand.addRequirements(hasDefaultCommand)
interrupter = commands2.Command()
interrupter.addRequirements(hasDefaultCommand)
scheduler.setDefaultCommand(hasDefaultCommand, defaultCommand)
scheduler.run()
scheduler.schedule(interrupter)
assert not scheduler.isScheduled(defaultCommand)
assert scheduler.isScheduled(interrupter)
scheduler.cancel(interrupter)
scheduler.run()
assert scheduler.isScheduled(defaultCommand)
assert not scheduler.isScheduled(interrupter)
def test_defaultCommandDisableResume(scheduler: commands2.CommandScheduler):
hasDefaultCommand = commands2.Subsystem()
defaultCommand = commands2.Command()
defaultCommand.addRequirements(hasDefaultCommand)
defaultCommand.runsWhenDisabled = lambda: False
start_spying_on(defaultCommand)
scheduler.setDefaultCommand(hasDefaultCommand, defaultCommand)
scheduler.run()
assert scheduler.isScheduled(defaultCommand)
DriverStationSim.setEnabled(False)
DriverStationSim.notifyNewData()
scheduler.run()
assert not scheduler.isScheduled(defaultCommand)
DriverStationSim.setEnabled(True)
DriverStationSim.notifyNewData()
scheduler.run()
assert scheduler.isScheduled(defaultCommand)
assert defaultCommand.end.called_with(True)