diff options
Diffstat (limited to 'app/tests')
| -rw-r--r-- | app/tests/test_backends_audiocpp.py | 39 | ||||
| -rw-r--r-- | app/tests/test_hub.py | 34 | ||||
| -rw-r--r-- | app/tests/test_runview.py | 8 | ||||
| -rw-r--r-- | app/tests/test_taskview.py | 50 | ||||
| -rw-r--r-- | app/tests/test_tui.py | 21 |
5 files changed, 125 insertions, 27 deletions
diff --git a/app/tests/test_backends_audiocpp.py b/app/tests/test_backends_audiocpp.py index 665dbf0..3063e99 100644 --- a/app/tests/test_backends_audiocpp.py +++ b/app/tests/test_backends_audiocpp.py @@ -1895,7 +1895,6 @@ class SetupScreenTests(unittest.TestCase): self.assertEqual(rc, 0) mk_lanes.assert_called_once() self.assertIs(mk_lanes.call_args[0][0], settings) - self.assertTrue(mk_lanes.call_args[1]["parallel"]) mk_run.assert_called_once() self.assertEqual(mk_run.call_args[0][2], lanes) @@ -1956,48 +1955,34 @@ class ExecuteLanesTests(unittest.TestCase): "Write server.json & sync config", "Download models"]) - def test_download_step_prints_the_parallel_launch_hint(self): - args = make_server.build_parser().parse_args([]) - lanes = make_server._execute_lanes(self._settings(), args, - parallel=True) - install_step = lanes[1].steps[2] - with patch.object(make_server, "_install_models") as mk_install, \ - patch.object(make_server, "_print_launch_hint") as mk_hint: - install_step.work(lambda line: None, threading.Event()) - mk_hint.assert_called_once() - self.assertTrue(mk_hint.call_args[1]["pending_build"]) - - def test_download_step_console_hint_is_not_pending(self): + def test_download_step_prints_the_launch_hint(self): args = make_server.build_parser().parse_args([]) lanes = make_server._execute_lanes(self._settings(), args) install_step = lanes[1].steps[2] - with patch.object(make_server, "_install_models") as mk_install, \ + with patch.object(make_server, "_install_models"), \ patch.object(make_server, "_print_launch_hint") as mk_hint: install_step.work(lambda line: None, threading.Event()) - mk_hint.assert_called_once() - self.assertFalse(mk_hint.call_args[1]["pending_build"]) + mk_hint.assert_called_once_with(Path("/x"), Path("/x/server.json")) class LaunchHintTests(unittest.TestCase): - """_print_launch_hint: exact command vs. the pending-build message.""" + """_print_launch_hint: silent when built, remediation when not.""" - def _capture(self, audiocpp_dir, output_path, pending_build=False): + def _capture(self, audiocpp_dir, output_path, binary=None): buf = io.StringIO() with redirect_stdout(buf), \ patch.object(make_server, "find_audiocpp_server_bin", - return_value=None): - make_server._print_launch_hint(audiocpp_dir, output_path, - pending_build=pending_build) + return_value=binary): + make_server._print_launch_hint(audiocpp_dir, output_path) return buf.getvalue() - def test_pending_build_names_the_post_build_command(self): + def test_built_server_prints_nothing(self): + # The hub starts/stops the server itself; no manual instructions. out = self._capture(Path("/tmp/acpp"), Path("/tmp/acpp/server.json"), - pending_build=True) - self.assertIn("still building", out) - self.assertNotIn("Build it first", out) - self.assertIn("audiocpp_server --config /tmp/acpp/server.json", out) + binary=Path("/tmp/acpp/build/x/bin/audiocpp_server")) + self.assertEqual(out, "") def test_missing_binary_gives_build_remediation(self): out = self._capture(Path("/tmp/acpp"), Path("/tmp/acpp/server.json")) self.assertIn("Build it first", out) - self.assertNotIn("still building", out) + self.assertNotIn("Start the server with:", out) diff --git a/app/tests/test_hub.py b/app/tests/test_hub.py index ec079f5..3feaa05 100644 --- a/app/tests/test_hub.py +++ b/app/tests/test_hub.py @@ -1730,6 +1730,40 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): self.assertIs(result, tui.Wizard.BACK) self.assertEqual(flashes, ["kaboom"]) + def test_screen_install_runs_setup_inline_then_goes_back(self): + # No stack frame for the setup: BACK pops past the picker straight + # to the Configure menu instead of re-showing "Install Backend". + info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) + with patch.object(hub._Hub, "_pick_backend", return_value=info), \ + patch.object(info, "setup_screen") as mk_setup: + result = hub._Hub(None).screen_install() + mk_setup.assert_called_once_with(None) + self.assertIs(result, tui.Wizard.BACK) + + def test_screen_install_esc_on_picker_goes_back_without_setup(self): + info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) + with patch.object(hub._Hub, "_pick_backend", return_value=None), \ + patch.object(info, "setup_screen") as mk_setup: + result = hub._Hub(None).screen_install() + mk_setup.assert_not_called() + self.assertIs(result, tui.Wizard.BACK) + + def test_screen_install_flashes_on_crash_and_still_goes_back(self): + info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) + flashes = [] + + def boom(scr): + raise RuntimeError("kaboom") + + with patch.object(hub._Hub, "_pick_backend", return_value=info), \ + patch.object(info, "setup_screen", boom), \ + patch.object(hub.tui, "flash", + lambda scr, text, kind="warn": + flashes.append(text)): + result = hub._Hub(None).screen_install() + self.assertIs(result, tui.Wizard.BACK) + self.assertEqual(flashes, ["kaboom"]) + def test_screen_uninstall_runs_in_task_view_and_goes_back(self): info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) with patch.object(hub._Hub, "_pick_backend", return_value=info), \ diff --git a/app/tests/test_runview.py b/app/tests/test_runview.py index df697c8..7006427 100644 --- a/app/tests/test_runview.py +++ b/app/tests/test_runview.py @@ -191,6 +191,14 @@ class RunLoopTests(_FakeTui, unittest.TestCase): # (started_server is False). self.assertEqual(view.phase, "done") + def test_run_leaves_the_screen_blocking_again(self): + # The timed redraw cadence must not leak into the hub: blocking + # input is restored so later dialogs (tui.flash) wait for keys. + view, screen = self.make_view(keys=[ord("x")]) + view._queue.put({"kind": "done", "ok": 1, "total": 1}) + view.run() + self.assertEqual(screen.timeouts[-1], -1) + def test_esc_cancels_and_confirms_stop_server(self): confirm_answers = [True, True] # cancel? yes; stop server? yes with patch.object(runview.tui, "confirm", diff --git a/app/tests/test_taskview.py b/app/tests/test_taskview.py index 4b03b41..6c984ad 100644 --- a/app/tests/test_taskview.py +++ b/app/tests/test_taskview.py @@ -276,6 +276,42 @@ class NoWaitTests(_FakeTui, unittest.TestCase): self.assertNotIn("press any key", text) +class InputModeRestoreTests(_FakeTui, unittest.TestCase): + """run() must leave the screen blocking again when the view exits. + + The views drive their redraw loop with a timed getch; if that cadence + leaked into the hub, single-getch dialogs like tui.flash would dismiss + themselves after one timeout instead of waiting for a key. + """ + + def test_task_view_run_restores_blocking_getch(self): + def fake_worker_main(view): + view._queue.put({"kind": "step_start", "index": 0, + "title": "one"}) + view._queue.put({"kind": "step_done", "index": 0, "rc": 0}) + view._queue.put({"kind": "finish", "phase": "done", "rc": 0}) + + screen = FakeScreen(width=80, height=24) + with patch.object(taskview.TaskView, "_worker_main", + fake_worker_main): + view = taskview.TaskView(screen, "Setup", [_step("one")], + clock=lambda: 1000.0, + wait_on_finish=False) + view._worker = _SyncWorker(view._worker_main) + view.run() + self.assertEqual(screen.timeouts[-1], -1) + + def test_lanes_view_run_restores_blocking_getch(self): + screen = FakeScreen(keys=[27]) # any key leaves the finished view + lanes = [taskview.TaskLane("A", [_step("a")]), + taskview.TaskLane("B", [_step("b")])] + view = taskview.LanesView(screen, "Setup", lanes, + clock=lambda: 1000.0) + with patch.object(taskview.threading, "Thread", _SyncThread): + view.run() + self.assertEqual(screen.timeouts[-1], -1) + + class _SyncWorker: """A stand-in for threading.Thread that runs the target synchronously.""" @@ -286,6 +322,20 @@ class _SyncWorker: self._fn() +class _SyncThread: + """A threading.Thread stand-in that runs its target on start().""" + + def __init__(self, target=None, args=(), kwargs=None, daemon=None): + self._target = target + self._args = args + + def start(self): + self._target(*self._args) + + def join(self, timeout=None): + pass + + class LabelTests(unittest.TestCase): def test_fmt_bytes(self): self.assertEqual(taskview._fmt_bytes(512), "512B") diff --git a/app/tests/test_tui.py b/app/tests/test_tui.py index 543194e..1b7af86 100644 --- a/app/tests/test_tui.py +++ b/app/tests/test_tui.py @@ -88,6 +88,10 @@ class FakeScreen: self.height = height self.strings = [] # (y, x, text, attr) from addstr self.chars = [] # (y, x, ch, attr) from addch + self.timeouts = [] # ms values passed to timeout() + + def timeout(self, ms): + self.timeouts.append(ms) def getmaxyx(self): return self.height, self.width @@ -979,6 +983,23 @@ class FlashTests(TuiTestCase): self.assertEqual(attr, tui._THEME["warn"]) self.assert_inside_border(screen) + def test_timed_out_reads_are_ignored_until_a_real_key(self): + # A screen left in redraw-cadence mode feeds getch() -1s; the + # notice must still wait for an actual key press. + screen = FakeScreen(keys=[-1, -1, ord("x")]) + tui.flash(screen, "a notice", kind="err") + self.assertEqual(screen.keys, []) + + def test_ctrl_c_still_aborts(self): + screen = FakeScreen(keys=[-1, 3]) + with self.assertRaises(tui.WizardCancelled): + tui.flash(screen, "a notice") + + def test_frame_flash_ignores_timed_out_reads_too(self): + frame = tui.Frame(FakeScreen(keys=[-1, 10]), "Title", "footer") + frame.flash("status line notice", "err") + self.assertIsNone(frame.status) + class WizardTests(unittest.TestCase): """The tui.Wizard screen-stack driver: Esc steps back one screen.""" |
