|
8 | 8 |
|
9 | 9 | from util import *
|
10 | 10 |
|
11 |
| -if not IS_OLD_COMMANDS: |
12 | 11 |
|
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 |
31 | 27 | )
|
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 |
42 | 30 |
|
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 |
48 | 37 |
|
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): |
51 | 42 | self.composeSingle(command)
|
52 |
| - with pytest.raises(commands2.IllegalCommandUse): |
53 |
| - self.composeSingle(command) |
54 | 43 |
|
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): |
57 | 48 | self.composeSingle(command)
|
58 |
| - with pytest.raises(commands2.IllegalCommandUse): |
59 |
| - scheduler.schedule(command) |
60 | 49 |
|
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): |
63 | 54 | 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 |
89 | 77 | ),
|
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 |
102 | 80 | ),
|
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 |
115 | 83 | ),
|
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 |
128 | 90 | ),
|
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 |
144 | 93 | ),
|
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 |
151 | 96 | ),
|
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 |
158 | 103 | ),
|
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 |
165 | 106 | ),
|
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 |
0 commit comments