Skip to content

Commit c977711

Browse files
authored
fix whileHeld instant command
1 parent d8078e7 commit c977711

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

commands2/coroutinecommand.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def ensure_generator_function(func: Coroutineable) -> Callable[..., Coroutine]:
2828
@wraps(func)
2929
def wrapper(*args, **kwargs):
3030
func(*args, **kwargs)
31+
return
3132
yield
3233

3334
return wrapper
@@ -81,6 +82,7 @@ def initialize(self) -> None:
8182
self.is_finished = False
8283

8384
def execute(self):
85+
print("r")
8486
try:
8587
if not self.is_finished:
8688
if not self.coroutine:

tests/test_button.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_cancel_when_pressed(scheduler: commands2.CommandScheduler):
161161
assert cmd1.canceled == 1
162162
assert not scheduler.isScheduled(cmd1)
163163

164-
@pytest.mark.xfail(strict=False)
164+
165165
def test_function_bindings(scheduler: commands2.CommandScheduler):
166166

167167
buttonWhenPressed = MyButton()
@@ -174,9 +174,9 @@ def test_function_bindings(scheduler: commands2.CommandScheduler):
174174

175175
counter = Counter()
176176

177-
buttonWhenPressed.whenPressed(lambda: (print("wp"), counter.increment(), None)[2])
178-
buttonWhileHeld.whileHeld(lambda: (print("wh"), counter.increment(), None)[2])
179-
buttonWhenReleased.whenReleased(lambda: (print("wr"), counter.increment(), None)[2])
177+
buttonWhenPressed.whenPressed(counter.increment)
178+
buttonWhileHeld.whileHeld(counter.increment)
179+
buttonWhenReleased.whenReleased(counter.increment)
180180

181181
scheduler.run()
182182
buttonWhenPressed.setPressed(True)

0 commit comments

Comments
 (0)