Skip to content

Commit 43654de

Browse files
committed
Fixing pilot times argument
1 parent 5cb6cd0 commit 43654de

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/textual/pilot.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ async def _post_mouse_events(
442442
# the driver works and emits a click event.
443443
kwargs = message_arguments
444444
if mouse_event_cls is Click:
445-
kwargs["chain"] = chain
445+
kwargs = {**kwargs, "chain": chain}
446+
446447
widget_at, _ = app.get_widget_at(*offset)
447448
event = mouse_event_cls(**kwargs)
448449
# Bypass event processing in App.on_event. Because App.on_event

tests/test_pilot.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from string import punctuation
2+
from typing import Type
23

34
import pytest
45

56
from textual import events, work
7+
from textual._on import on
68
from textual.app import App, ComposeResult
79
from textual.binding import Binding
810
from textual.containers import Center, Middle
@@ -424,3 +426,27 @@ def on_button_pressed(self):
424426
assert not pressed
425427
await pilot.click(button)
426428
assert pressed
429+
430+
431+
@pytest.mark.parametrize("times", [1, 2, 3])
432+
async def test_click_times(times: int):
433+
"""Test that Pilot.click() can be called with a `times` argument."""
434+
435+
events_received: list[Type[events.Event]] = []
436+
437+
class TestApp(App[None]):
438+
def compose(self) -> ComposeResult:
439+
yield Label("Click counter")
440+
441+
@on(events.Click)
442+
@on(events.MouseDown)
443+
@on(events.MouseUp)
444+
def on_label_clicked(self, event: events.Event):
445+
events_received.append(event.__class__)
446+
447+
app = TestApp()
448+
async with app.run_test() as pilot:
449+
await pilot.click(Label, times=times)
450+
assert (
451+
events_received == [events.MouseDown, events.MouseUp, events.Click] * times
452+
)

0 commit comments

Comments
 (0)