Skip to content

Commit d9f8e39

Browse files
authored
Merge pull request #5398 from Textualize/pilot-double-click-fix
Fixing pilot times argument
2 parents 39ddb85 + 9016a98 commit d9f8e39

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
### Fixed
11+
12+
- Fixed `Pilot.click` not working with `times` parameter https://github.com/Textualize/textual/pull/5398
13+
1014
### Added
1115

1216
- Added `from_app_focus` to `Focus` event to indicate if a widget is being focused because the app itself has regained focus or not https://github.com/Textualize/textual/pull/5379
@@ -15,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1519

1620
- The content of an `Input` will now only be automatically selected when the widget is focused by the user, not when the app itself has regained focus (similar to web browsers). https://github.com/Textualize/textual/pull/5379
1721

22+
1823
## [1.0.0] - 2024-12-12
1924

2025
### Added

src/textual/pilot.py

Lines changed: 2 additions & 1 deletion
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

Lines changed: 26 additions & 0 deletions
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)