aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_taskview.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-25 14:37:16 -0400
committerhistoria <historiavg@proton.me>2026-08-25 14:37:16 -0400
commit061406b608c5a77b33259506648e0166367b2b9f (patch)
treec18633630d160016af285389a629da53a3a4161c /app/tests/test_taskview.py
parent0badc06550ed2e46c7c4b9f83db755737ffc0412 (diff)
downloadtts-audiobook-generator-061406b608c5a77b33259506648e0166367b2b9f.tar.gz
feat: simpler menu for start/stop backend servers
Diffstat (limited to 'app/tests/test_taskview.py')
-rw-r--r--app/tests/test_taskview.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/app/tests/test_taskview.py b/app/tests/test_taskview.py
index d1bc658..5d97902 100644
--- a/app/tests/test_taskview.py
+++ b/app/tests/test_taskview.py
@@ -212,6 +212,66 @@ class RenderTests(_FakeTui, unittest.TestCase):
self.assertIn("Progress", text)
+class NoWaitTests(_FakeTui, unittest.TestCase):
+ """wait_on_finish=False: the view returns to the caller on finish."""
+
+ def make_view(self, steps=(), width=80, height=24, wait_on_finish=False):
+ screen = FakeScreen(width=width, height=height)
+ with patch.object(taskview.TaskView, "_worker_main", lambda self: None):
+ view = taskview.TaskView(screen, "Setup", list(steps),
+ clock=lambda: 1000.0,
+ wait_on_finish=wait_on_finish)
+ return view, screen
+
+ def _strings(self, screen):
+ return " ".join(text for _, _, text, _ in screen.strings)
+
+ def _run_view(self, wait_on_finish):
+ """Run() with a synchronous worker that posts a successful finish."""
+ screen = FakeScreen(width=80, height=24)
+ step = _step("one")
+
+ def fake_worker_main(self):
+ self._queue.put({"kind": "step_start", "index": 0,
+ "title": "one"})
+ self._queue.put({"kind": "step_done", "index": 0, "rc": 0})
+ self._queue.put({"kind": "finish", "phase": "done", "rc": 0})
+
+ with patch.object(taskview.TaskView, "_worker_main",
+ fake_worker_main):
+ view = taskview.TaskView(screen, "Setup", [step],
+ clock=lambda: 1000.0,
+ wait_on_finish=wait_on_finish)
+ # Replace the daemon thread with a synchronous runner so the
+ # events are queued before run() enters its loop (deterministic).
+ view._worker = _SyncWorker(view._worker_main)
+ return view.run()
+
+ def test_returns_immediately_when_not_waiting(self):
+ # No scripted keys: run() must return on finish without asking for one.
+ self.assertEqual(self._run_view(wait_on_finish=False), 0)
+
+ def test_done_footer_omits_key_hint_when_not_waiting(self):
+ view, screen = self.make_view(steps=[_step("one")])
+ view.handle_event({"kind": "step_start", "index": 0, "title": "one"})
+ view.handle_event({"kind": "step_done", "index": 0, "rc": 0})
+ view.handle_event({"kind": "finish", "phase": "done", "rc": 0})
+ view.render()
+ text = self._strings(screen)
+ self.assertIn("completed", text)
+ self.assertNotIn("press any key", text)
+
+
+class _SyncWorker:
+ """A stand-in for threading.Thread that runs the target synchronously."""
+
+ def __init__(self, fn):
+ self._fn = fn
+
+ def start(self):
+ self._fn()
+
+
class LabelTests(unittest.TestCase):
def test_fmt_bytes(self):
self.assertEqual(taskview._fmt_bytes(512), "512B")