home · contact · privacy
Add TOML config test.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 28 Sep 2025 14:15:45 +0000 (16:15 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 28 Sep 2025 14:15:45 +0000 (16:15 +0200)
src/ircplom/testing.py
src/run.py
src/tests/_test.toml_test.txt [new file with mode: 0644]
src/tests/test.toml [new file with mode: 0644]

index 7bd422b59ad21a14165f6deecedc1536bc0ad4d3..990ca4bfcc9c697ae8de8748973f60681b285fb2 100644 (file)
@@ -91,15 +91,12 @@ class TestingClientTui(ClientTui):
     'Collects keypresses via TestTerminal and test file, compares log results.'
     _client_cls = _TestClientKnowingTui
     _clients: list[_TestClientKnowingTui]
-    _path_config = None
+    _path_config: 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 self._path_test.open('r', encoding='utf8') as f:
             self._playbook = [line.rstrip() for line in f.readlines()]
         self._playbook_anchors: dict[str, int] = {}
@@ -128,8 +125,12 @@ class TestingClientTui(ClientTui):
                 break
             if not inserts:
                 break
-        self._playbook_idx = -1
-        self._play_till_next_log()
+        self._playbook_idx = 0
+        super().__init__(**kwargs)
+        assert isinstance(self._term, TestTerminal)
+        self._q_keypresses = self._term._q_keypresses
+        if self._playbook_idx == 0:  # __init__ called no ._play_till_next_log
+            self._play_till_next_log()
 
     @staticmethod
     def split_active_line(line: str) -> Optional[tuple[str, ...]]:
@@ -139,10 +140,11 @@ class TestingClientTui(ClientTui):
         return tuple(line.split(' ', maxsplit=1))
 
     @classmethod
-    def on_file(cls, path_test: Path):
+    def on_files(cls, path_test: Path, path_config: Optional[Path] = None):
         '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]):
index 8b9cf2d560a3467af20fe4add67d940020e8aabb..5a9f1c32d35d7e953ae45a310c0348fa201d6258 100755 (executable)
@@ -42,11 +42,19 @@ 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():
+        for path in _PATH_TESTS.iterdir():
+            fname = path.parts[-1]
+            if fname.endswith('.toml'):
+                continue
             print(f'running test: {path}')
-            main_loop(TestTerminal, TestingClientTui.on_file(path))
+            path_toml = (None if fname[0] != '_'
+                         else _PATH_TESTS.joinpath(fname.split('_')[1]))
+            main_loop(TestTerminal, TestingClientTui.on_files(path, path_toml))
             print('(success!)')
     else:
         main_loop(Terminal, ClientTui)
diff --git a/src/tests/_test.toml_test.txt b/src/tests/_test.toml_test.txt
new file mode 100644 (file)
index 0000000..0a000ef
--- /dev/null
@@ -0,0 +1,25 @@
+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/test.toml b/src/tests/test.toml
new file mode 100644 (file)
index 0000000..68c5c90
--- /dev/null
@@ -0,0 +1,11 @@
+[[server]]
+hostname = 'irc.test0.net'
+nickname = 'foo'
+password = 'bar'
+username = 'baz'
+realname = 'quux'
+port = 1234
+channels = [
+  '#test',
+  '##testtest',
+]