From: Christian Heller Date: Tue, 30 Sep 2025 23:32:45 +0000 (+0200) Subject: In tests, refactor context splitting, add separator to anchor syntax. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=7947af0abe57043c5df3f70bcabb6fe5f1979a45;p=ircplom In tests, refactor context splitting, add separator to anchor syntax. --- diff --git a/src/ircplom/testing.py b/src/ircplom/testing.py index c36dd15..f7db844 100644 --- a/src/ircplom/testing.py +++ b/src/ircplom/testing.py @@ -128,7 +128,7 @@ class _Playbook: return bool(inserts) def split_server_put_and_log(line: str, **_) -> list[str]: - context, msg = line.split(_CHAR_CONTEXT_SEP, maxsplit=1) + context, msg = self._split_by_context_separator(line) assert msg[0] in '.*' and msg[1:3] == f'{LOG_PREFIX_IN} ' c_id, win_ids = context[1:].split(_CHAR_ID_TYPE_SEP, maxsplit=1) return [f'{_CHAR_SERVER_MSG}{c_id}{_CHAR_CONTEXT_SEP}{msg[3:]}', @@ -144,9 +144,10 @@ class _Playbook: if len(range_data) == 2: return inserts for jdx, insert in enumerate(inserts): - if (result := self._split_active_line(insert)): - inserts[jdx] = _CHAR_CONTEXT_SEP.join([range_data[2]] - + [result[1]]) + context, msg = self._split_by_context_separator(insert) + if context == _CHAR_ANCHOR: + continue + inserts[jdx] = _CHAR_CONTEXT_SEP.join([range_data[2]] + [msg]) return inserts while expand_parsed(_CHAR_ID_TYPE_SEP, split_server_put_and_log): @@ -155,7 +156,7 @@ class _Playbook: anchors: dict[str, int] = {} for idx, line in enumerate(self._lines): if line[:1] == _CHAR_ANCHOR: - anchors[line[1:]] = idx + anchors[line[2:]] = idx if not expand_parsed(_TOK_REPEAT, repeat, anchors=anchors): break self._lines = [ln for ln in self._lines @@ -173,7 +174,7 @@ class _Playbook: def next_log(self) -> tuple[int, tuple[int, ...], str]: 'Return index, win IDs, and context of next expected log line.' - context, msg = self._current_line.split(_CHAR_CONTEXT_SEP, maxsplit=1) + context, msg = self._split_by_context_separator(self._current_line) if _CHAR_RANGE in context: _, context = context.split(_CHAR_RANGE) expected_win_ids = tuple( @@ -185,26 +186,23 @@ class _Playbook: def _play_till_log(self) -> None: while True: - if (result := self._split_active_line(self._current_line)): - context, msg = result - if context == _CHAR_PROMPT: - assert self.put_keypress is not None - for c in msg: - self.put_keypress(c) - self.put_keypress('KEY_ENTER') - elif context.startswith(_CHAR_SERVER_MSG): - client = self._get_client(int(context[1:])) - assert isinstance(client.conn, _FakeIrcConnection) - client.conn.put_server_msg(msg) - else: - break + context, msg = self._split_by_context_separator(self._current_line) + if context == _CHAR_PROMPT: + assert self.put_keypress is not None + for c in msg: + self.put_keypress(c) + self.put_keypress('KEY_ENTER') + elif context.startswith(_CHAR_SERVER_MSG): + client = self._get_client(int(context[1:])) + assert isinstance(client.conn, _FakeIrcConnection) + client.conn.put_server_msg(msg) + else: + break self._idx += 1 @staticmethod - def _split_active_line(line: str) -> Optional[tuple[str, ...]]: - 'Return 2-items tuple of split line, or None if empty/comment/anchor.' - if _CHAR_CONTEXT_SEP not in line: - return None + def _split_by_context_separator(line: str) -> tuple[str, ...]: + 'Return two-items tuple of CHAR_CONTEXT_SEP-split line, or None.' return tuple(line.split(_CHAR_CONTEXT_SEP, maxsplit=1)) diff --git a/src/tests/test.txt b/src/tests/test.txt index babd6e2..72a007b 100644 --- a/src/tests/test.txt +++ b/src/tests/test.txt @@ -2,17 +2,17 @@ # on /connect init databases, log in new windows > /connect foo.bar.baz foo:bar baz:foobarbazquux -|standard-clears-in -|isupport-clear-in +| standard-clears-in +| isupport-clear-in 1 .$ isupport cleared 1 .$ isupport:CHANTYPES set to: [#&] 1 .$ isupport:PREFIX set to: [(ov)@+] 1 .$ isupport:USERLEN set to: [10] -|isupport-clear-out +| isupport-clear-out 1 .$ caps cleared 1 .$ users cleared 1 .$ channels cleared -|standard-clears-out +| standard-clears-out , .$ DISCONNECTED # connect with values set by /connect, init CAP negotation @@ -23,12 +23,12 @@ 1 .$ realname set to: [baz] 1 .$ password set to: [bar] 1 .$ port set to: [6697] -|conn0 +| conn0 1 .$ connection_state set to: [connecting] 1 .$ connection_state set to: [connected] -|conn1 +| conn1 , .$ CONNECTED -|conn2 +| conn2 1 .> CAP LS :302 1 .> USER foobarbazquux 0 * :baz 1 .> NICK :foo @@ -85,7 +85,7 @@ # of all pre-MOTD greeting messages, only process isupports :0:1 .< :foo.bar.baz 001 foo1 :Welcome to the foo.bar.baz network -|conn3 +| conn3 :0:1 .< :foo.bar.baz 002 foo1 :Your host is foo.bar.baz :0:1 .< :foo.bar.baz 003 foo1 :This server was created Jan 1 2020 :0:1 .< :foo.bar.baz 004 foo1 foo.bar.baz ircserver-1.0 abc def ghi @@ -123,7 +123,7 @@ # handle bot query NOTICE :0:1 .< :SaslServ!SaslServ@services.bar.baz NOTICE foo1 :Last login from ~foobarbaz@foo.bar.baz on Jan 1 22:00:00 2021 +0000. 3 .< *** [SaslServ] Last login from ~foobarbaz@foo.bar.baz on Jan 1 22:00:00 2021 +0000. -|conn4 +| conn4 # check difference in available commands when switching to client window > /join #test @@ -134,7 +134,7 @@ 0 .# 1) foo.bar.baz :DEBUG 0 .# 2) foo.bar.baz server 0 .# 3) foo.bar.baz SaslServ -|conn5 +| conn5 > /window 1 > /help 1 .# commands available in this window: @@ -352,7 +352,7 @@ repeat isupport-clear-in isupport-clear-out 1 .!$ cannot send, connection seems closed > /privmsg #test test 1 .!$ not sending, since not in channel -|conn6 +| conn6 # test setting up second client, but 432 irrecoverably > /connect baz.bar.foo ?foo foo:foo