home · contact · privacy
In testing, for TUI directives call .redraw_affected directly when needed.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 14 Oct 2025 22:03:48 +0000 (00:03 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 14 Oct 2025 22:03:48 +0000 (00:03 +0200)
src/ircplom/testing.py

index 58b39fa8ef3377791c7fe704f1c8fec45c2d9f30..b63a3ad6275756392dc069b729d9373fdaf9d65a 100644 (file)
@@ -144,6 +144,7 @@ _TOK_TUI = 'TUI'
 class _Playbook:
     put_keypress: Optional[Callable] = None
     assert_screen_line: Optional[Callable] = None
+    redraw_affected: Optional[Callable] = None
 
     def __init__(self, path: Path, get_client: Callable, verbose: bool
                  ) -> None:
@@ -269,6 +270,8 @@ class _Playbook:
                 client.conn.put_server_msg(msg)
             elif context == _TOK_TUI:
                 assert self.assert_screen_line is not None
+                assert self.redraw_affected is not None
+                self.redraw_affected()
                 position, attrs_str, msg = msg.split('.', maxsplit=2)
                 y, x = ((int(item) for item in position.split(','))
                         if ',' in position
@@ -307,6 +310,7 @@ class TestingClientTui(ClientTui):
         super().__init__(**kwargs)
         assert isinstance(self._term, TestTerminal)
         self._playbook.assert_screen_line = self._term.assert_screen_line
+        self._playbook.redraw_affected = self.redraw_affected
         self._playbook.put_keypress = self._term._q_keypresses.put
         self._playbook.ensure_has_started()  # if .__init__ didn't yet by log()
 
@@ -324,12 +328,6 @@ class TestingClientTui(ClientTui):
 
     def log(self, msg: str, **kwargs) -> tuple[tuple[int, ...], str]:
         win_ids, logged_msg = super().log(msg, **kwargs)
-        # usually whatever called log would call .redraw_affected directly
-        # after, but for TUI display tests on the effects of .log that might
-        # follow directly in the playbook (i.e. will run before .log actually
-        # finishes, signaling to caller they should call .redraw_affected) we
-        # want this available immediately
-        self.redraw_affected()
         fmt, time_str, msg_sans_time = logged_msg.split(' ', maxsplit=2)
         msg_sans_time = fmt + ' ' + msg_sans_time
         assert len(time_str) == 8