From 6eb8ab6235a7f41284af1359322b542bd661dc86 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 26 Sep 2025 10:00:19 +0200 Subject: [PATCH] In testing, for "repeat" instruction, use named anchors rather than (constantly changing) line numbers. --- src/ircplom/testing.py | 10 ++++++++-- src/tests/test.txt | 15 +++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ircplom/testing.py b/src/ircplom/testing.py index 558dc45..23062e5 100644 --- a/src/ircplom/testing.py +++ b/src/ircplom/testing.py @@ -102,6 +102,10 @@ class TestingClientTui(ClientTui): 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_anchors: dict[str, int] = {} + for idx, line in enumerate(self._playbook): + if line[:1] == '|': + self._playbook_anchors[line[1:]] = idx + 1 self._playbook_idx = -1 self._play_till_next_log() @@ -140,11 +144,13 @@ class TestingClientTui(ClientTui): while True: self._playbook_idx += 1 line = self._playbook[self._playbook_idx] - if line[:1] == '#' or not line.strip(): + if line[:1] in '#|' or not line.strip(): continue context, msg = line.split(' ', maxsplit=1) if context == 'repeat': - start, end = msg.split(':') + start_key, end_key = msg.split(' ') + start = self._playbook_anchors[start_key] + end = self._playbook_anchors[end_key] self._playbook = (self._playbook[:self._playbook_idx + 1] + self._playbook[int(start):int(end)] + self._playbook[self._playbook_idx + 1:]) diff --git a/src/tests/test.txt b/src/tests/test.txt index dc0d9ac..5af8ac6 100644 --- a/src/tests/test.txt +++ b/src/tests/test.txt @@ -19,9 +19,12 @@ 1 $ realname set to: [baz] 1 $ password set to: [bar] 1 $ port set to: [6697] +|conn0 1 $ connection_state set to: [connecting] 1 $ connection_state set to: [connected] +|conn1 , $ CONNECTED +|conn2 1 > CAP LS :302 1 > USER foobarbazquux 0 * :baz 1 > NICK :foo @@ -76,6 +79,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 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 @@ -113,6 +117,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 # check difference in available commands when switching to client window > /join #test @@ -123,6 +128,7 @@ 0 # 1) foo.bar.baz :DEBUG 0 # 2) foo.bar.baz server 0 # 3) foo.bar.baz SaslServ +|conn5 > /window 1 > /help 1 # commands available in this window: @@ -336,6 +342,7 @@ 1 !$ cannot send, connection seems closed > /privmsg #test test 1 !$ not sending, since not in channel +|conn6 # test setting up second client, but 432 irrecoverably > /connect baz.bar.foo ?foo foo:foo @@ -401,12 +408,12 @@ # check that (save TUI tests assuming start on window 0, and no 4 yet) on reconnect, all the same effects can be expected > /reconnect -repeat 21:23 +repeat conn0 conn1 2,3,4,5,6,7 $ CONNECTED -repeat 24:78 +repeat conn2 conn3 1 > JOIN :#testtest -repeat 78:116 -repeat 126:340 +repeat conn3 conn4 +repeat conn5 conn6 > /quit 0 < -- 2.30.2