From 82a5b201d4bab3e8a3886bf044d01de6df05aa32 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Sun, 10 Sep 2023 01:02:35 -0400 Subject: [PATCH] WIP: make test recorder more generic to apps --- tests/pilot_recorder.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/pilot_recorder.py b/tests/pilot_recorder.py index 0852a9c..eb0cb12 100644 --- a/tests/pilot_recorder.py +++ b/tests/pilot_recorder.py @@ -4,6 +4,7 @@ import os from typing import Any, Callable from rich.text import Text +from textual.app import App from textual.css.query import NoMatches, TooManyMatches from textual.dom import DOMNode from textual.errors import NoWidget @@ -69,19 +70,19 @@ def get_selector(target: DOMNode) -> tuple[str, int|None]: return selector, None -original_on_event = PaintApp.on_event +original_on_event = App.on_event # type: ignore class PilotRecorder(): """Record (and undo and replay) interactions with an app, and save as a test.""" def __init__(self) -> None: - self.app: PaintApp | None = None + self.app: App[Any] | None = None self.steps: list[tuple[Event, Offset, str, int|None]] = [] self.replaying: bool = False self.output_file = unique_file("tests/test_paint_something.py") self.next_after_exit: Callable[[], None] | None = None recorder = self - async def on_event(self: PaintApp, event: Event) -> None: + async def on_event(self: App[Any], event: Event) -> None: # - Record before the event is handled, so a clicked widget that removes itself, # such as an OK button in a dialog, will still be in the DOM when we record it. # - Every event seems to be received twice, once with _forwarded set and once without.