From 43654deb92d27afc63e97b06c2afcb332d41d668 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Mon, 16 Dec 2024 13:09:01 +0000 Subject: [PATCH 1/2] Fixing pilot times argument --- src/textual/pilot.py | 3 ++- tests/test_pilot.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/textual/pilot.py b/src/textual/pilot.py index 473341b7e9..2554bf3b8d 100644 --- a/src/textual/pilot.py +++ b/src/textual/pilot.py @@ -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 diff --git a/tests/test_pilot.py b/tests/test_pilot.py index 008d711389..a44e827a74 100644 --- a/tests/test_pilot.py +++ b/tests/test_pilot.py @@ -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 @@ -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 + ) From 9b447b42543afd891ee238ba157b45e1356b2185 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Mon, 16 Dec 2024 13:09:51 +0000 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46ff52f8ca..6ae6c95834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) 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 + ## [1.0.0] - 2024-12-12 ### Added