From f9e38ed3db520da0bf7a3d298b649d63d0cf1ca6 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 26 Sep 2025 08:36:13 +0200 Subject: [PATCH] Split testing into multiple test files. --- src/ircplom/testing.py | 15 ++++++---- src/run.py | 7 +++-- src/{ => tests}/test.txt | 50 +++------------------------------ src/tests/tui_prompt_basics.txt | 44 +++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 53 deletions(-) rename src/{ => tests}/test.txt (91%) create mode 100644 src/tests/tui_prompt_basics.txt diff --git a/src/ircplom/testing.py b/src/ircplom/testing.py index a33d203..558dc45 100644 --- a/src/ircplom/testing.py +++ b/src/ircplom/testing.py @@ -10,9 +10,6 @@ from ircplom.irc_conn import IrcConnAbortException, IrcMessage from ircplom.tui_base import TerminalInterface, TuiEvent -_PATH_TEST_TXT = Path('test.txt') - - class TestTerminal(QueueMixin, TerminalInterface): 'Collects keypresses from string queue, otherwise mostly dummy.' @@ -95,18 +92,26 @@ class TestingClientTui(ClientTui): _client_cls = _TestClientKnowingTui _clients: list[_TestClientKnowingTui] _path_config = None - _path_logs: Optional[Path] = None + _path_logs = None + _path_test: Path def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self._clients = [] assert isinstance(self._term, TestTerminal) self._q_keypresses = self._term._q_keypresses - with _PATH_TEST_TXT.open('r', encoding='utf8') as f: + with self._path_test.open('r', encoding='utf8') as f: self._playbook = tuple(line[:-1] for line in f.readlines()) self._playbook_idx = -1 self._play_till_next_log() + @classmethod + def on_file(cls, path_test: Path): + 'Return cls with ._path_test set.' + class _Bound(TestingClientTui): + _path_test = path_test + return _Bound + def _new_client(self, conn_setup: IrcConnSetup, channels: set[str]): self._clients += [super()._new_client(conn_setup, channels)] return self._clients[-1] diff --git a/src/run.py b/src/run.py index 32cd2f8..8b9cf2d 100755 --- a/src/run.py +++ b/src/run.py @@ -2,6 +2,7 @@ 'Attempt at an IRC client.' # standard libs +from pathlib import Path from queue import SimpleQueue from sys import argv # non-standard libs @@ -43,7 +44,9 @@ def main_loop(cls_term: type[TerminalInterface], cls_tui: type[BaseTui] if __name__ == '__main__': if len(argv) > 1 and argv[1] == 'test': - main_loop(TestTerminal, TestingClientTui) - print('test finished') + for path in Path('tests').iterdir(): + print(f'running test: {path}') + main_loop(TestTerminal, TestingClientTui.on_file(path)) + print('(success!)') else: main_loop(Terminal, ClientTui) diff --git a/src/test.txt b/src/tests/test.txt similarity index 91% rename from src/test.txt rename to src/tests/test.txt index 5371e01..dc0d9ac 100644 --- a/src/test.txt +++ b/src/tests/test.txt @@ -1,45 +1,3 @@ -# BASIC TUI PROMPT TESTS - -# nothing should happen on empty command input -> - -# expected complaints on wrong command inputs -> foo -0 !# invalid prompt command: not prefixed by / -> /foo -0 !# invalid prompt command: /foo unknown -> /help foo -0 !# invalid prompt command: /help given argument(s) while none expected -> /window -0 !# invalid prompt command: /window too few arguments (given 0, need 1) - -# some simple expected command successes -> /help -0 # commands available in this window: -0 # /connect HOST_PORT [NICKNAME_PW] [REALNAME_USERNAME] -0 # /help -0 # /list -0 # /prompt_enter -0 # /quit -0 # /window TOWARDS -0 # /window.history.scroll DIRECTION -0 # /window.paste -0 # /window.prompt.backspace -0 # /window.prompt.move_cursor DIRECTION -0 # /window.prompt.scroll DIRECTION -> /list -0 # windows available via /window: -0 # 0) :start - -# should probably not be available at all by explicit prompt writing, but for now this be the expected behavior … -> /prompt_enter -0 !# invalid prompt command: /prompt_enter would loop into ourselves -> /window.history.scroll foo -> /window.prompt.backspace -> /window.prompt.move_cursor foo -> /window.prompt.scroll foo -> /window.paste - # CONNECTED INTERACTIONS # on /connect init databases, log in new windows @@ -443,12 +401,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 63:65 +repeat 21:23 2,3,4,5,6,7 $ CONNECTED -repeat 66:120 +repeat 24:78 1 > JOIN :#testtest -repeat 120:158 -repeat 168:382 +repeat 78:116 +repeat 126:340 > /quit 0 < diff --git a/src/tests/tui_prompt_basics.txt b/src/tests/tui_prompt_basics.txt new file mode 100644 index 0000000..8355197 --- /dev/null +++ b/src/tests/tui_prompt_basics.txt @@ -0,0 +1,44 @@ +# BASIC TUI PROMPT TESTS + +# nothing should happen on empty command input +> + +# expected complaints on wrong command inputs +> foo +0 !# invalid prompt command: not prefixed by / +> /foo +0 !# invalid prompt command: /foo unknown +> /help foo +0 !# invalid prompt command: /help given argument(s) while none expected +> /window +0 !# invalid prompt command: /window too few arguments (given 0, need 1) + +# some simple expected command successes +> /help +0 # commands available in this window: +0 # /connect HOST_PORT [NICKNAME_PW] [REALNAME_USERNAME] +0 # /help +0 # /list +0 # /prompt_enter +0 # /quit +0 # /window TOWARDS +0 # /window.history.scroll DIRECTION +0 # /window.paste +0 # /window.prompt.backspace +0 # /window.prompt.move_cursor DIRECTION +0 # /window.prompt.scroll DIRECTION +> /list +0 # windows available via /window: +0 # 0) :start + +# should probably not be available at all by explicit prompt writing, but for now this be the expected behavior … +> /prompt_enter +0 !# invalid prompt command: /prompt_enter would loop into ourselves +> /window.history.scroll foo +> /window.prompt.backspace +> /window.prompt.move_cursor foo +> /window.prompt.scroll foo +> /window.paste + +> /quit +0 < -- 2.30.2