From c60990797b35215b3ba5f4676ef07f133f1669ab Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 26 Sep 2025 16:55:34 +0200 Subject: [PATCH] Minor refactoring. --- src/ircplom/testing.py | 45 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/ircplom/testing.py b/src/ircplom/testing.py index b97e09f..22977a7 100644 --- a/src/ircplom/testing.py +++ b/src/ircplom/testing.py @@ -101,7 +101,7 @@ class TestingClientTui(ClientTui): assert isinstance(self._term, TestTerminal) self._q_keypresses = self._term._q_keypresses with self._path_test.open('r', encoding='utf8') as f: - self._playbook = tuple(line[:-1] for line in f.readlines()) + self._playbook = tuple(line.rstrip() for line in f.readlines()) self._playbook_anchors: dict[str, int] = {} while True: self._playbook_anchors.clear() @@ -110,12 +110,9 @@ class TestingClientTui(ClientTui): self._playbook_anchors[line[1:]] = idx found_repeat = False for idx, line in enumerate(self._playbook): - if line[:1] in '#|' or not line.strip(): - continue - context, msg = line.split(' ', maxsplit=1) - if context == 'repeat': + if (t := self.split_active_line(line)) and t[0] == 'repeat': found_repeat = True - start_key, end_key = msg.split(' ') + start_key, end_key = t[1].split(' ', maxsplit=1) start = self._playbook_anchors[start_key] + 1 end = self._playbook_anchors[end_key] self._playbook = (self._playbook[:idx] @@ -128,6 +125,13 @@ class TestingClientTui(ClientTui): self._playbook_idx = -1 self._play_till_next_log() + @staticmethod + def split_active_line(line: str) -> Optional[tuple[str, ...]]: + 'Return two-items tuple of split line, or None if inactive one.' + if line[:1] in '#|' or ' ' not in line: + return None + return tuple(line.split(' ', maxsplit=1)) + @classmethod def on_file(cls, path_test: Path): 'Return cls with ._path_test set.' @@ -163,19 +167,18 @@ class TestingClientTui(ClientTui): while True: self._playbook_idx += 1 line = self._playbook[self._playbook_idx] - if line[:1] in '#|' or not line.strip(): - continue - context, msg = line.split(' ', maxsplit=1) - if context == '>': - for c in msg: - self._q_keypresses.put(c) - self._q_keypresses.put('KEY_ENTER') - continue - if ':' in context and msg.startswith('< '): - client_id, win_ids = context.split(':') - client = self._clients[int(client_id)] - assert isinstance(client.conn, _FakeIrcConnection) - client.conn.put_server_msg(msg[2:]) - if not win_ids: + if (result := self.split_active_line(line)): + context, msg = result + if context == '>': + for c in msg: + self._q_keypresses.put(c) + self._q_keypresses.put('KEY_ENTER') continue - break + if ':' in context and msg.startswith('< '): + client_id, win_ids = context.split(':') + client = self._clients[int(client_id)] + assert isinstance(client.conn, _FakeIrcConnection) + client.conn.put_server_msg(msg[2:]) + if not win_ids: + continue + break -- 2.30.2