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()
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]
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.'
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