From: Christian Heller Date: Sun, 28 Sep 2025 17:08:31 +0000 (+0200) Subject: On config toml testing, move file identification from file path into testing code... X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=b7419e8e57a7580f2382840c45acdb68af8d39d4;p=ircplom On config toml testing, move file identification from file path into testing code directive. --- diff --git a/src/ircplom/testing.py b/src/ircplom/testing.py index 5e32835..5b32e58 100644 --- a/src/ircplom/testing.py +++ b/src/ircplom/testing.py @@ -10,6 +10,9 @@ from ircplom.irc_conn import IrcConnAbortException, IrcMessage from ircplom.tui_base import TerminalInterface, TuiEvent +PATH_TESTS = Path('tests') + + class TestTerminal(QueueMixin, TerminalInterface): 'Collects keypresses from string queue, otherwise mostly dummy.' @@ -166,6 +169,15 @@ class _Playbook: return None return tuple(line.split(' ', maxsplit=1)) + def check_start_for_config(self) -> Optional[Path]: + 'While on first line, if config file identified, inc idx, return path.' + assert self._idx == 0 + if self._lines[self._idx].startswith('#config '): + _, toml_name = self._lines[0].split(maxsplit=1) + self._idx += 1 + return PATH_TESTS.joinpath(toml_name) + return None + class TestingClientTui(ClientTui): 'Collects keypresses via TestTerminal and test file, compares log results.' @@ -179,17 +191,17 @@ class TestingClientTui(ClientTui): self._clients = [] self._playbook = _Playbook(path=self._path_test, get_client=lambda idx: self._clients[idx]) + self._path_config = self._playbook.check_start_for_config() super().__init__(**kwargs) assert isinstance(self._term, TestTerminal) self._playbook.put_keypress = self._term._q_keypresses.put self._playbook.ensure_has_started() # if .__init__ didn't yet by log() @classmethod - def on_files(cls, path_test: Path, path_config: Optional[Path] = None): + def on_file(cls, path_test: Path): 'Return cls with ._path_test set.' class _Bound(TestingClientTui): _path_test = path_test - _path_config = path_config return _Bound def _new_client(self, conn_setup: IrcConnSetup, channels: set[str]): diff --git a/src/run.py b/src/run.py index 5a9f1c3..053240c 100755 --- a/src/run.py +++ b/src/run.py @@ -2,7 +2,6 @@ 'Attempt at an IRC client.' # standard libs -from pathlib import Path from queue import SimpleQueue from sys import argv # non-standard libs @@ -12,7 +11,7 @@ try: from ircplom.client import ClientsDb, ClientEvent, NewClientEvent from ircplom.tui_base import BaseTui, Terminal, TerminalInterface, TuiEvent from ircplom.client_tui import ClientTui - from ircplom.testing import TestTerminal, TestingClientTui + from ircplom.testing import TestTerminal, TestingClientTui, PATH_TESTS except ModuleNotFoundError as e: dependency_hint(e) @@ -42,19 +41,13 @@ def main_loop(cls_term: type[TerminalInterface], cls_tui: type[BaseTui] client.close() -_PATH_TESTS = Path('tests') - - if __name__ == '__main__': if len(argv) > 1 and argv[1] == 'test': - for path in _PATH_TESTS.iterdir(): - fname = path.parts[-1] - if fname.endswith('.toml'): + for path in PATH_TESTS.iterdir(): + if path.parts[-1].endswith('.toml'): continue print(f'running test: {path}') - path_toml = (None if fname[0] != '_' - else _PATH_TESTS.joinpath(fname.split('_')[1])) - main_loop(TestTerminal, TestingClientTui.on_files(path, path_toml)) + main_loop(TestTerminal, TestingClientTui.on_file(path)) print('(success!)') else: main_loop(Terminal, ClientTui) diff --git a/src/tests/_test.toml_test.txt b/src/tests/_test.toml_test.txt deleted file mode 100644 index 0a000ef..0000000 --- a/src/tests/_test.toml_test.txt +++ /dev/null @@ -1,25 +0,0 @@ -0 # Found config at tests/test.toml, reading … -0 # Connecting: {'hostname': 'irc.test0.net', 'nickname': 'foo', 'password': 'bar', 'username': 'baz', 'realname': 'quux', 'port': 1234, 'channels': ['#test', '##testtest']} -1 $ isupport cleared -1 $ isupport:CHANTYPES set to: [#&] -1 $ isupport:PREFIX set to: [(ov)@+] -1 $ isupport:USERLEN set to: [10] -1 $ caps cleared -1 $ users cleared -1 $ channels cleared -, $ DISCONNECTED -1 $ hostname set to: [irc.test0.net] -1 $ port set to: [1234] -1 $ nick_wanted set to: [foo] -1 $ user_wanted set to: [baz] -1 $ realname set to: [quux] -1 $ password set to: [bar] -1 $ connection_state set to: [connecting] -1 $ connection_state set to: [connected] -, $ CONNECTED -1 > CAP LS :302 -1 > USER baz 0 * :quux -1 > NICK :foo - -> /quit -0 < diff --git a/src/tests/config.txt b/src/tests/config.txt new file mode 100644 index 0000000..71037a3 --- /dev/null +++ b/src/tests/config.txt @@ -0,0 +1,26 @@ +#config test.toml +0 # Found config at tests/test.toml, reading … +0 # Connecting: {'hostname': 'irc.test0.net', 'nickname': 'foo', 'password': 'bar', 'username': 'baz', 'realname': 'quux', 'port': 1234, 'channels': ['#test', '##testtest']} +1 $ isupport cleared +1 $ isupport:CHANTYPES set to: [#&] +1 $ isupport:PREFIX set to: [(ov)@+] +1 $ isupport:USERLEN set to: [10] +1 $ caps cleared +1 $ users cleared +1 $ channels cleared +, $ DISCONNECTED +1 $ hostname set to: [irc.test0.net] +1 $ port set to: [1234] +1 $ nick_wanted set to: [foo] +1 $ user_wanted set to: [baz] +1 $ realname set to: [quux] +1 $ password set to: [bar] +1 $ connection_state set to: [connecting] +1 $ connection_state set to: [connected] +, $ CONNECTED +1 > CAP LS :302 +1 > USER baz 0 * :quux +1 > NICK :foo + +> /quit +0 <