Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing pilot times argument #5398

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed

- Fixed `Pilot.click` not working with `times` parameter https://github.com/Textualize/textual/pull/5398

### Added

- 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
Expand All @@ -15,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- 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


## [1.0.0] - 2024-12-12

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/textual/pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ async def _post_mouse_events(
# the driver works and emits a click event.
kwargs = message_arguments
if mouse_event_cls is Click:
kwargs["chain"] = chain
kwargs = {**kwargs, "chain": chain}

widget_at, _ = app.get_widget_at(*offset)
event = mouse_event_cls(**kwargs)
# Bypass event processing in App.on_event. Because App.on_event
Expand Down
26 changes: 26 additions & 0 deletions tests/test_pilot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from string import punctuation
from typing import Type

import pytest

from textual import events, work
from textual._on import on
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import Center, Middle
Expand Down Expand Up @@ -424,3 +426,27 @@ def on_button_pressed(self):
assert not pressed
await pilot.click(button)
assert pressed


@pytest.mark.parametrize("times", [1, 2, 3])
async def test_click_times(times: int):
"""Test that Pilot.click() can be called with a `times` argument."""

events_received: list[Type[events.Event]] = []

class TestApp(App[None]):
def compose(self) -> ComposeResult:
yield Label("Click counter")

@on(events.Click)
@on(events.MouseDown)
@on(events.MouseUp)
def on_label_clicked(self, event: events.Event):
events_received.append(event.__class__)

app = TestApp()
async with app.run_test() as pilot:
await pilot.click(Label, times=times)
assert (
events_received == [events.MouseDown, events.MouseUp, events.Click] * times
)
Loading