You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtextual_tryout.appimportMyAppasyncdeftest_app_click():
app=MyApp()
asyncwithapp.run_test() aspilot:
awaitpilot.click(times=2) # Any number of times more than 1
Traceback
__________________________________________ test_app_click ___________________________________________
async def test_app_click():
app = MyApp()
async with app.run_test() as pilot:
> await pilot.click(times=2)
tests\test_app.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv\Lib\site-packages\textual\pilot.py:234: in click
return await self._post_mouse_events(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Pilot app=MyApp(title='MyApp', classes={'-dark-mode'}, pseudo_classes={'dark', 'focus'})>
events = [<class 'textual.events.MouseDown'>, <class 'textual.events.MouseUp'>, <class 'textual.events.Click'>]
widget = None, offset = Offset(x=0, y=0), button = 1, shift = False, meta = False, control = False
times = 2
async def _post_mouse_events(
self,
events: list[type[MouseEvent]],
widget: Widget | type[Widget] | str | None | None = None,
offset: tuple[int, int] = (0, 0),
button: int = 0,
shift: bool = False,
meta: bool = False,
control: bool = False,
times: int = 1,
) -> bool:
"""Simulate a series of mouse events to be fired at a given position. The final position for the events is computed based on the selector provided and the offset specified and it must be within the visible area of the screen. This function abstracts away the commonalities of the other mouse event-related functions that the pilot exposes. Args: widget: A widget or selector used as the origin for the event's offset. If this is not specified, the offset is interpreted relative to the screen. You can use this parameter to try to target a specific widget. However, if the widget is currently hidden or obscured by another widget, the events may not land on the widget you specified. offset: The offset for the events. The offset is relative to the widget / selector provided or to the screen, if no selector is provided. shift: Simulate the events with the shift key held down. meta: Simulate the events with the meta key held down. control: Simulate the events with the control key held down. times: The number of times to click. 2 will double-click, 3 will triple-click, etc. Raises: OutOfBounds: If the position for the events is outside of the (visible) screen. Returns: True if no selector was specified or if the *final* event landed on the selected widget, False otherwise."""
app = self.app
screen = app.screen
target_widget: Widget
if widget is None:
target_widget = screen
elif isinstance(widget, Widget):
target_widget = widget
else:
target_widget = app.query_one(widget)
message_arguments = _get_mouse_message_arguments(
target_widget,
offset,
button=button,
shift=shift,
meta=meta,
control=control,
)
offset = Offset(message_arguments["x"], message_arguments["y"])
if offset not in screen.region:
raise OutOfBounds(
"Target offset is outside of currently-visible screen region."
)
widget_at = None
forchainin range(1, times + 1):
formouse_event_clsin events:
# Get the widget under the mouse before the event because the app might# react to the event and move things around. We override on each iteration# because we assume the final event in `events` is the actual event we care# about and that all the preceding events are just setup.# E.g., the click event is preceded by MouseDown/MouseUp to emulate how# the driver works and emits a click event.
kwargs = message_arguments
if mouse_event_cls is Click:
kwargs["chain"] = chain
widget_at, _ = app.get_widget_at(*offset)
> event = mouse_event_cls(**kwargs)
E TypeError: MouseEvent.__init__() got an unexpected keyword argument 'chain'
.venv\Lib\site-packages\textual\pilot.py:447: TypeError
====================================== short test summary info ======================================
FAILED tests/test_app.py::test_app_click - TypeError: MouseEvent.__init__() got an unexpected keyword argument 'chain'
========================================= 1 failed in 0.49s =========================================
Description
When using
pilot.click()
with thetimes
argument set to more than 1 to test for chained click events gives aTypeError
.AFAIK this issue happens to any
times
argument value that isn't 1.This also applies to the
double_click
andtriple_click
aliases.MRE
In
app.py
In
test_app.py
Traceback
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
The text was updated successfully, but these errors were encountered: