Skip to content

Commit cb5af47

Browse files
committed
get it testable
1 parent a2da722 commit cb5af47

File tree

5 files changed

+110
-45
lines changed

5 files changed

+110
-45
lines changed

commands2/button/networkbutton.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from networktables import NetworkTable, NetworkTables, NetworkTableEntry
1+
from ntcore import NetworkTable, NetworkTableEntry
22

33
from typing import Union, overload
44

tests/test_button_coroutine_functions.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ def setPressed(self, value: bool):
2020
def test_when_pressed_coroutine(scheduler: commands2.CommandScheduler):
2121
button = MyButton()
2222

23-
class state: pass
23+
class state:
24+
pass
25+
2426
state.executed = False
27+
2528
def cmd1():
2629
state.executed = True
2730
return
@@ -43,8 +46,11 @@ def cmd1():
4346
def test_when_released_coroutine(scheduler: commands2.CommandScheduler):
4447
button = MyButton()
4548

46-
class state: pass
49+
class state:
50+
pass
51+
4752
state.executed = False
53+
4854
def cmd1():
4955
state.executed = True
5056
return
@@ -62,11 +68,15 @@ def cmd1():
6268

6369
assert state.executed
6470

71+
6572
def test_while_held_coroutine(scheduler: commands2.CommandScheduler):
6673
button = MyButton()
6774

68-
class state: pass
75+
class state:
76+
pass
77+
6978
state.executed = 0
79+
7080
def cmd1():
7181
state.executed += 1
7282
return
@@ -82,17 +92,21 @@ def cmd1():
8292
scheduler.run()
8393
scheduler.run()
8494
assert state.executed == 2
85-
95+
8696
button.setPressed(False)
8797
scheduler.run()
8898

8999
assert state.executed == 2
90100

101+
91102
def test_when_held_coroutine(scheduler: commands2.CommandScheduler):
92103
button = MyButton()
93104

94-
class state: pass
105+
class state:
106+
pass
107+
95108
state.executed = 0
109+
96110
def cmd1():
97111
while True:
98112
state.executed += 1
@@ -108,23 +122,27 @@ def cmd1():
108122
scheduler.run()
109123
scheduler.run()
110124
assert state.executed == 2
111-
125+
112126
button.setPressed(False)
113127

114128
assert state.executed == 2
115129

130+
116131
def test_toggle_when_pressed_coroutine(scheduler: commands2.CommandScheduler):
117132
button = MyButton()
118133

119-
class state: pass
134+
class state:
135+
pass
136+
120137
state.executed = 0
138+
121139
def cmd1():
122140
while True:
123141
state.executed += 1
124142
yield
125-
143+
126144
button.setPressed(False)
127-
145+
128146
button.toggleWhenPressed(cmd1)
129147
scheduler.run()
130148

@@ -162,4 +180,4 @@ def increment():
162180
buttonWhenReleased.setPressed(False)
163181
scheduler.run()
164182

165-
assert counter.value == 4
183+
assert counter.value == 4

tests/test_button_coroutines.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ def setPressed(self, value: bool):
2020
def test_when_pressed_coroutine(scheduler: commands2.CommandScheduler):
2121
button = MyButton()
2222

23-
class state: pass
23+
class state:
24+
pass
25+
2426
state.executed = False
27+
2528
def cmd1():
2629
state.executed = True
2730
return
@@ -43,8 +46,11 @@ def cmd1():
4346
def test_when_released_coroutine(scheduler: commands2.CommandScheduler):
4447
button = MyButton()
4548

46-
class state: pass
49+
class state:
50+
pass
51+
4752
state.executed = False
53+
4854
def cmd1():
4955
state.executed = True
5056
return
@@ -62,12 +68,16 @@ def cmd1():
6268

6369
assert state.executed
6470

71+
6572
@pytest.mark.xfail(strict=True)
6673
def test_while_held_coroutine(scheduler: commands2.CommandScheduler):
6774
button = MyButton()
6875

69-
class state: pass
76+
class state:
77+
pass
78+
7079
state.executed = 0
80+
7181
def cmd1():
7282
state.executed += 1
7383
return
@@ -83,17 +93,21 @@ def cmd1():
8393
scheduler.run()
8494
scheduler.run()
8595
assert state.executed == 2
86-
96+
8797
button.setPressed(False)
8898
scheduler.run()
8999

90100
assert state.executed == 2
91101

102+
92103
def test_when_held_coroutine(scheduler: commands2.CommandScheduler):
93104
button = MyButton()
94105

95-
class state: pass
106+
class state:
107+
pass
108+
96109
state.executed = 0
110+
97111
def cmd1():
98112
while True:
99113
state.executed += 1
@@ -109,23 +123,27 @@ def cmd1():
109123
scheduler.run()
110124
scheduler.run()
111125
assert state.executed == 2
112-
126+
113127
button.setPressed(False)
114128

115129
assert state.executed == 2
116130

131+
117132
def test_toggle_when_pressed_coroutine(scheduler: commands2.CommandScheduler):
118133
button = MyButton()
119134

120-
class state: pass
135+
class state:
136+
pass
137+
121138
state.executed = 0
139+
122140
def cmd1():
123141
while True:
124142
state.executed += 1
125143
yield
126-
144+
127145
button.setPressed(False)
128-
146+
129147
button.toggleWhenPressed(cmd1())
130148
scheduler.run()
131149

@@ -136,6 +154,7 @@ def cmd1():
136154

137155
assert state.executed
138156

157+
139158
@pytest.mark.xfail(strict=True)
140159
def test_function_bindings_coroutine(scheduler: commands2.CommandScheduler):
141160

@@ -163,4 +182,4 @@ def increment():
163182
buttonWhenReleased.setPressed(False)
164183
scheduler.run()
165184

166-
assert counter.value == 4
185+
assert counter.value == 4

tests/test_button_decorator_coroutines.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def test_when_pressed_coroutine(scheduler: commands2.CommandScheduler):
2121
button = MyButton()
2222
button.setPressed(False)
2323

24-
class state: pass
24+
class state:
25+
pass
26+
2527
state.executed = False
2628

2729
@button.whenPressed
@@ -45,7 +47,9 @@ def test_when_released_coroutine(scheduler: commands2.CommandScheduler):
4547
button = MyButton()
4648
button.setPressed(True)
4749

48-
class state: pass
50+
class state:
51+
pass
52+
4953
state.executed = False
5054

5155
@button.whenReleased()
@@ -64,11 +68,14 @@ def cmd1():
6468

6569
assert state.executed
6670

71+
6772
def test_while_held_coroutine(scheduler: commands2.CommandScheduler):
6873
button = MyButton()
6974
button.setPressed(False)
7075

71-
class state: pass
76+
class state:
77+
pass
78+
7279
state.executed = 0
7380

7481
@button.whileHeld(interruptible=True)
@@ -85,17 +92,20 @@ def cmd1():
8592
scheduler.run()
8693
scheduler.run()
8794
assert state.executed == 2
88-
95+
8996
button.setPressed(False)
9097
scheduler.run()
9198

9299
assert state.executed == 2
93100

101+
94102
def test_when_held_coroutine(scheduler: commands2.CommandScheduler):
95103
button = MyButton()
96104
button.setPressed(False)
97105

98-
class state: pass
106+
class state:
107+
pass
108+
99109
state.executed = 0
100110

101111
@button.whenHeld(runs_when_disabled=True)
@@ -112,25 +122,27 @@ def cmd1():
112122
scheduler.run()
113123
scheduler.run()
114124
assert state.executed == 2
115-
125+
116126
button.setPressed(False)
117127

118128
assert state.executed == 2
119129

130+
120131
def test_toggle_when_pressed_coroutine(scheduler: commands2.CommandScheduler):
121132
button = MyButton()
122133
button.setPressed(False)
123134

124-
class state: pass
135+
class state:
136+
pass
137+
125138
state.executed = 0
126139

127140
@button.toggleWhenPressed
128141
def cmd1():
129142
while True:
130143
state.executed += 1
131144
yield
132-
133-
145+
134146
scheduler.run()
135147

136148
assert not state.executed

0 commit comments

Comments
 (0)