forked from robotpy/robotpy-commands-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_command_schedule.py
90 lines (62 loc) · 2.27 KB
/
test_command_schedule.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
from typing import TYPE_CHECKING
import commands2
from util import * # type: ignore
if TYPE_CHECKING:
from .util import *
import pytest
def test_instantSchedule(scheduler: commands2.CommandScheduler):
command = commands2.Command()
command.isFinished = lambda: True
start_spying_on(command)
scheduler.schedule(command)
assert scheduler.isScheduled(command)
verify(command).initialize()
scheduler.run()
verify(command).execute()
verify(command).end(False)
assert not scheduler.isScheduled(command)
def test_singleIterationSchedule(scheduler: commands2.CommandScheduler):
command = commands2.Command()
start_spying_on(command)
scheduler.schedule(command)
assert scheduler.isScheduled(command)
scheduler.run()
command.isFinished = lambda: True
scheduler.run()
verify(command).initialize()
verify(command, times(2)).execute()
verify(command).end(False)
assert not scheduler.isScheduled(command)
def test_multiSchedule(scheduler: commands2.CommandScheduler):
command1 = commands2.Command()
command2 = commands2.Command()
command3 = commands2.Command()
scheduler.schedule(command1, command2, command3)
assert scheduler.isScheduled(command1, command2, command3)
scheduler.run()
assert scheduler.isScheduled(command1, command2, command3)
command1.isFinished = lambda: True
scheduler.run()
assert scheduler.isScheduled(command2, command3)
assert not scheduler.isScheduled(command1)
command2.isFinished = lambda: True
scheduler.run()
assert scheduler.isScheduled(command3)
assert not scheduler.isScheduled(command1, command2)
command3.isFinished = lambda: True
scheduler.run()
assert not scheduler.isScheduled(command1, command2, command3)
def test_schedulerCancel(scheduler: commands2.CommandScheduler):
command = commands2.Command()
start_spying_on(command)
scheduler.schedule(command)
scheduler.run()
scheduler.cancel(command)
scheduler.run()
verify(command).execute()
verify(command).end(True)
verify(command, never()).end(False)
assert not scheduler.isScheduled(command)
def test_notScheduledCancel(scheduler: commands2.CommandScheduler):
command = commands2.Command()
scheduler.cancel(command)