-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f48b3fe
commit 1b46350
Showing
11 changed files
with
632 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
import commands2 | ||
from util import * # type: ignore | ||
|
||
if TYPE_CHECKING: | ||
from .util import * | ||
|
||
from ntcore import NetworkTableInstance | ||
from wpilib import SmartDashboard | ||
|
||
import pytest | ||
|
||
|
||
def test_trueAndNotScheduledSchedules( | ||
scheduler: commands2.CommandScheduler, nt_instance: NetworkTableInstance | ||
): | ||
schedule = OOInteger(0) | ||
cancel = OOInteger(0) | ||
|
||
command = commands2.cmd.startEnd(schedule.incrementAndGet, cancel.incrementAndGet) | ||
publish = nt_instance.getBooleanTopic("/SmartDashboard/command/running").publish() | ||
SmartDashboard.putData("command", command) | ||
SmartDashboard.updateValues() | ||
# | ||
commands2.CommandScheduler.getInstance().run() | ||
SmartDashboard.updateValues() | ||
assert not command.isScheduled() | ||
assert schedule == 0 | ||
assert cancel == 0 | ||
|
||
publish.set(True) | ||
SmartDashboard.updateValues() | ||
commands2.CommandScheduler.getInstance().run() | ||
assert command.isScheduled() | ||
assert schedule == 1 | ||
assert cancel == 0 | ||
|
||
|
||
def test_trueAndScheduleNoOp( | ||
scheduler: commands2.CommandScheduler, nt_instance: NetworkTableInstance | ||
): | ||
schedule = OOInteger(0) | ||
cancel = OOInteger(0) | ||
|
||
command = commands2.cmd.startEnd(schedule.incrementAndGet, cancel.incrementAndGet) | ||
publish = nt_instance.getBooleanTopic("/SmartDashboard/command/running").publish() | ||
SmartDashboard.putData("command", command) | ||
SmartDashboard.updateValues() | ||
# | ||
command.schedule() | ||
commands2.CommandScheduler.getInstance().run() | ||
SmartDashboard.updateValues() | ||
assert command.isScheduled() | ||
assert schedule == 1 | ||
assert cancel == 0 | ||
|
||
publish.set(True) | ||
SmartDashboard.updateValues() | ||
commands2.CommandScheduler.getInstance().run() | ||
assert command.isScheduled() | ||
assert schedule == 1 | ||
assert cancel == 0 | ||
|
||
|
||
def test_falseAndNotScheduledNoOp( | ||
scheduler: commands2.CommandScheduler, nt_instance: NetworkTableInstance | ||
): | ||
schedule = OOInteger(0) | ||
cancel = OOInteger(0) | ||
|
||
command = commands2.cmd.startEnd(schedule.incrementAndGet, cancel.incrementAndGet) | ||
publish = nt_instance.getBooleanTopic("/SmartDashboard/command/running").publish() | ||
SmartDashboard.putData("command", command) | ||
SmartDashboard.updateValues() | ||
# | ||
commands2.CommandScheduler.getInstance().run() | ||
SmartDashboard.updateValues() | ||
assert not command.isScheduled() | ||
assert schedule == 0 | ||
assert cancel == 0 | ||
|
||
publish.set(False) | ||
SmartDashboard.updateValues() | ||
commands2.CommandScheduler.getInstance().run() | ||
assert not command.isScheduled() | ||
assert schedule == 0 | ||
assert cancel == 0 | ||
|
||
|
||
def test_falseAndScheduleCancel( | ||
scheduler: commands2.CommandScheduler, nt_instance: NetworkTableInstance | ||
): | ||
schedule = OOInteger(0) | ||
cancel = OOInteger(0) | ||
|
||
command = commands2.cmd.startEnd(schedule.incrementAndGet, cancel.incrementAndGet) | ||
publish = nt_instance.getBooleanTopic("/SmartDashboard/command/running").publish() | ||
SmartDashboard.putData("command", command) | ||
SmartDashboard.updateValues() | ||
# | ||
command.schedule() | ||
commands2.CommandScheduler.getInstance().run() | ||
SmartDashboard.updateValues() | ||
assert command.isScheduled() | ||
assert schedule == 1 | ||
assert cancel == 0 | ||
|
||
publish.set(False) | ||
SmartDashboard.updateValues() | ||
commands2.CommandScheduler.getInstance().run() | ||
assert not command.isScheduled() | ||
assert schedule == 1 | ||
assert cancel == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
import commands2 | ||
from util import * # type: ignore | ||
|
||
if TYPE_CHECKING: | ||
from .util import * | ||
|
||
import pytest | ||
|
||
|
||
# parameterized on true and false | ||
@pytest.mark.parametrize( | ||
"interrupted", | ||
[ | ||
True, | ||
False, | ||
], | ||
) | ||
def test_deferredFunctions(interrupted): | ||
inner_command = commands2.Command() | ||
start_spying_on(inner_command) | ||
command = commands2.DeferredCommand(lambda: inner_command) | ||
|
||
command.initialize() | ||
verify(inner_command).initialize() | ||
|
||
command.execute() | ||
verify(inner_command).execute() | ||
|
||
assert not command.isFinished() | ||
verify(inner_command).isFinished() | ||
|
||
inner_command.isFinished = lambda: True | ||
assert command.isFinished() | ||
verify(inner_command, times(2)).isFinished() | ||
|
||
command.end(interrupted) | ||
verify(inner_command).end(interrupted) | ||
|
||
|
||
def test_deferredSupplierOnlyCalledDuringInit(scheduler: commands2.CommandScheduler): | ||
class Supplier: | ||
def get(self): | ||
return commands2.cmd.none() | ||
|
||
supplier = Supplier() | ||
start_spying_on(supplier) | ||
|
||
command = commands2.DeferredCommand(supplier) | ||
verify(supplier, never()).get() | ||
|
||
scheduler.schedule(command) | ||
verify(supplier, times(1)).get() | ||
scheduler.run() | ||
|
||
scheduler.schedule(command) | ||
verify(supplier, times(2)).get() | ||
|
||
|
||
def test_deferredRequirements(): | ||
subsystem = commands2.Subsystem() | ||
command = commands2.DeferredCommand(commands2.cmd.none(), subsystem) | ||
|
||
assert subsystem in command.getRequirements() | ||
|
||
|
||
def test_deferredNullCommand(): | ||
command = commands2.DeferredCommand(lambda: None) | ||
|
||
command.initialize() | ||
command.execute() | ||
command.isFinished() | ||
command.end(False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.