Description: Tests: wait a while after sending keys to tina
 Make the tests wait for a little while after each send-keys
 command to make it less probable that we check for something
 before tina has had a chance to do it in busy environments
 .
 Wait for a little longer when telling tina to save the database
 before we check the file on disk.
Forwarded: yes
Author: Peter Pentchev <roam@ringlet.net>
Last-Update: 2025-01-28

--- a/tests/python/unit/combined/test_mgr_convert.py
+++ b/tests/python/unit/combined/test_mgr_convert.py
@@ -67,14 +67,14 @@
         no_db()
 
         print("Creating a single 'Flip' entry")
-        tina.pane.send_keys("oFlip", enter=True, literal=True)
+        tina.send_keys("oFlip", enter=True, literal=True)
         tina.assert_text_at(0, 1, "Flip")
         tina.assert_no_text_at(4, 1)
         tina.assert_no_text_at(0, 2)
         no_db()
 
         print("Saving the single 'Flip' entry")
-        tina.pane.send_keys("$", enter=False, literal=True)
+        tina.send_keys("$", enter=False, literal=True)
         tina.assert_text_at(0, 1, "Flip")
         tina.assert_no_text_at(4, 1)
         tina.assert_no_text_at(0, 2)
@@ -88,7 +88,7 @@
                 pytest.fail(repr(other))
 
         print("Putting the 'Flip' entry into the 'Flop' category")
-        tina.pane.send_keys("CFlop", enter=True, literal=True)
+        tina.send_keys("CFlop", enter=True, literal=True)
         print("Telling 'tina' to quit, hopefully it will save the database")
         tina.quit()
 
--- a/tests/python/unit/mgr/test_many.py
+++ b/tests/python/unit/mgr/test_many.py
@@ -35,7 +35,7 @@
         assert not cfgpath.exists()
 
         for idx in range(MANY):
-            tina.pane.send_keys(f"oItem {idx + 1}", enter=True, literal=True)
+            tina.send_keys(f"oItem {idx + 1}", enter=True, literal=True)
 
         tina.quit()
 
@@ -67,7 +67,7 @@
                 assert len(db_contents) == idx - 1
 
                 print(f"Creating item {idx}")
-                tina.pane.send_keys(f"GoItem {idx}", enter=True, literal=True)
+                tina.send_keys(f"GoItem {idx}", enter=True, literal=True)
 
                 print("Quitting tina so that it will save the database")
                 tina.quit()
@@ -94,7 +94,7 @@
                 assert len(db_contents) == MANY
 
                 print(f"Creating item {large_idx}")
-                tina.pane.send_keys(f"dGoItem {large_idx}", enter=True, literal=True)
+                tina.send_keys(f"dGoItem {large_idx}", enter=True, literal=True)
 
                 print("Quitting tina so that it will save the database")
                 tina.quit()
--- a/tests/python/unit/mgr/test_simple.py
+++ b/tests/python/unit/mgr/test_simple.py
@@ -5,7 +5,6 @@
 from __future__ import annotations
 
 import dataclasses
-import time
 import typing
 
 from tina_mgr import db
@@ -56,8 +55,7 @@
                 tina.assert_text_at(0, item_idx, item.desc)
 
                 print(f"Recursing into {item.desc!r}")
-                tina.pane.send_keys("l", enter=None, literal=True)
-                time.sleep(0.1)
+                tina.send_keys("l", enter=False, literal=True)
 
                 if not item.children:
                     print("No child entries to check")
@@ -67,19 +65,16 @@
                     walk_recursive(item.children)
 
                 print(f"Coming back from {item.desc!r}")
-                tina.pane.send_keys("h", enter=None)
-                time.sleep(0.1)
+                tina.send_keys("h", enter=False)
                 tina.assert_text_at(0, item_idx, item.desc)
 
                 print(f"Going back down to {item.desc!r}")
                 for _ in range(1, item_idx):
-                    tina.pane.send_keys("j", enter=None)
-                    time.sleep(0.1)
+                    tina.send_keys("j", enter=False)
                     tina.assert_no_text_at(0, last_y)
 
                 print("Proceeding to the next item")
-                tina.pane.send_keys("j", enter=None)
-                time.sleep(0.1)
+                tina.send_keys("j", enter=False)
                 if item_idx + 1 <= len(items):
                     tina.assert_no_text_at(0, last_y)
                 else:
@@ -97,15 +92,15 @@
         db_path: Final = tina.home / ".tina"
         assert db_path.read_text(encoding="UTF-8") == t_util.TEST_DB.read_text(encoding="UTF-8")
 
-        tina.pane.send_keys("Down", enter=False)
-        tina.pane.send_keys("Right", enter=False)
+        tina.send_keys("Down", enter=False)
+        tina.send_keys("Right", enter=False)
 
-        tina.pane.send_keys("/even look", enter=True, literal=True)
-        tina.pane.send_keys("c", enter=False, literal=True)
-        tina.pane.send_keys("End", enter=False)
-        tina.pane.send_keys(" and stuff", enter=True, literal=True)
+        tina.send_keys("/even look", enter=True, literal=True)
+        tina.send_keys("c", enter=False, literal=True)
+        tina.send_keys("End", enter=False)
+        tina.send_keys(" and stuff", enter=True, literal=True)
 
-        tina.pane.send_keys("$", enter=None, literal=True)
+        tina.send_keys("$", enter=False, literal=True, wait=1)
         assert db_path.read_text(encoding="UTF-8") != t_util.TEST_DB.read_text(encoding="UTF-8")
 
         tina.quit()
@@ -137,11 +132,11 @@
         assert db_path.read_text(encoding="UTF-8") == t_util.TEST_DB.read_text(encoding="UTF-8")
 
         print("Adding the 'nothing' entry")
-        tina.pane.send_keys("GOnothing", enter=True, literal=True)
+        tina.send_keys("GOnothing", enter=True, literal=True)
         assert db_path.read_text(encoding="UTF-8") == t_util.TEST_DB.read_text(encoding="UTF-8")
 
         print("Saving the 'nothing' entry")
-        tina.pane.send_keys("$", enter=False, literal=True)
+        tina.send_keys("$", enter=False, literal=True, wait=1)
         assert db_path.read_text(encoding="UTF-8") != t_util.TEST_DB.read_text(encoding="UTF-8")
         print("Parsing the database after the 'nothing' entry was added")
         contents_nothing: Final = db_path.read_text(encoding="UTF-8")
@@ -152,7 +147,7 @@
         assert mid == [*orig_entries[:-1], entry_nothing, orig_entries[-1]]
 
         print("Setting the category of the 'nothing' entry to 'something'")
-        tina.pane.send_keys("Csomething", enter=True, literal=True)
+        tina.send_keys("Csomething", enter=True, literal=True)
         print("Telling 'tina' to quit, hopefully it will save the database")
         tina.quit()
 
--- a/tests/python/unit/mgr/util.py
+++ b/tests/python/unit/mgr/util.py
@@ -39,6 +39,20 @@
     pane: libtmux.Pane
     """The tmux pane that tina runs in."""
 
+    def send_keys(
+        self,
+        cmd: str,
+        *,
+        enter: bool = True,
+        suppress_history: bool = False,
+        literal: bool = False,
+        wait: float = 0.1,
+    ) -> None:
+        """Send some keys to the current pane."""
+        self.pane.send_keys(cmd, enter=enter, suppress_history=suppress_history, literal=literal)
+        if wait > 0:
+            time.sleep(wait)
+
     def assert_text_at(self, x: int, y: int, text: str) -> None:
         """Make sure the pane contains the specified characters at the specified position."""
         print(f"Checking for {text!r} at ({x}, {y})")
@@ -80,7 +94,7 @@
     def quit(self) -> None:
         """Send 'q', wait for `tina` to go away."""
         print("Sending 'q'")
-        self.pane.send_keys("q", enter=False, literal=True)
+        self.send_keys("q", enter=False, literal=True, wait=0)
         self.assert_stopped()
 
     @classmethod
