diff options
Diffstat (limited to 'app/tests/test_hub.py')
| -rw-r--r-- | app/tests/test_hub.py | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/app/tests/test_hub.py b/app/tests/test_hub.py index 965cbaa..ec079f5 100644 --- a/app/tests/test_hub.py +++ b/app/tests/test_hub.py @@ -1730,14 +1730,85 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): self.assertIs(result, tui.Wizard.BACK) self.assertEqual(flashes, ["kaboom"]) - def test_screen_uninstall_runs_uninstall_and_goes_back(self): - import contextlib + 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), \ + patch.object(hub.tui, "confirm", return_value=True), \ + patch.object(hub.taskview, "run_steps", + return_value=0) as mk_run, \ patch.object(info, "uninstall") as mk_uninstall, \ - patch.object(hub.tui, "suspend", contextlib.nullcontext): + patch.object(hub.tui, "flash"): result = hub._Hub(None).screen_uninstall() - mk_uninstall.assert_called_once_with() + # The uninstall runs as one task-view step on the session (no + # suspend); executing the step forwards emit/cancel to uninstall. + mk_run.assert_called_once() + self.assertEqual(mk_run.call_args[0][0], None) + steps = mk_run.call_args[0][2] + self.assertEqual([step.title for step in steps], + ["Uninstall qwen-tts"]) + self.assertFalse(mk_run.call_args.kwargs["wait_on_finish"]) + emit = lambda line: None + steps[0].work(emit, None) + mk_uninstall.assert_called_once_with(emit=emit, cancel=None) + self.assertIs(result, tui.Wizard.BACK) + + def test_screen_uninstall_success_flashes_ok(self): + flashes = [] + + def fake_flash(scr, text, kind="warn"): + flashes.append((text, kind)) + + info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) + with patch.object(hub._Hub, "_pick_backend", return_value=info), \ + patch.object(hub.tui, "confirm", return_value=True), \ + patch.object(hub.taskview, "run_steps", return_value=0), \ + patch.object(info, "uninstall"), \ + patch.object(hub.tui, "flash", fake_flash): + result = hub._Hub(None).screen_uninstall() + self.assertIs(result, tui.Wizard.BACK) + self.assertEqual(flashes[-1], ("qwen-tts uninstalled.", "ok")) + + def test_screen_uninstall_failure_flashes_error(self): + flashes = [] + + def fake_flash(scr, text, kind="warn"): + flashes.append((text, kind)) + + info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) + with patch.object(hub._Hub, "_pick_backend", return_value=info), \ + patch.object(hub.tui, "confirm", return_value=True), \ + patch.object(hub.taskview, "run_steps", return_value=1), \ + patch.object(info, "uninstall"), \ + patch.object(hub.tui, "flash", fake_flash): + result = hub._Hub(None).screen_uninstall() + self.assertIs(result, tui.Wizard.BACK) + self.assertEqual(flashes[-1][1], "err") + self.assertIn("Could not fully uninstall", flashes[-1][0]) + + def test_screen_uninstall_confirm_declined_skips_uninstall(self): + info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) + with patch.object(hub._Hub, "_pick_backend", return_value=info), \ + patch.object(hub.tui, "confirm", return_value=False) \ + as mk_confirm, \ + patch.object(hub.taskview, "run_steps") as mk_run, \ + patch.object(info, "uninstall") as mk_uninstall: + result = hub._Hub(None).screen_uninstall() + mk_run.assert_not_called() + mk_uninstall.assert_not_called() + self.assertIs(result, tui.Wizard.BACK) + # The confirm names the backend and is Esc-able (cancel_value set). + self.assertIn("Uninstall qwen-tts?", mk_confirm.call_args[0][1]) + + def test_screen_uninstall_esc_on_confirm_backs_out(self): + info = BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0) + with patch.object(hub._Hub, "_pick_backend", return_value=info), \ + patch.object(hub.tui, "confirm", + return_value=tui.Wizard.BACK), \ + patch.object(hub.taskview, "run_steps") as mk_run, \ + patch.object(info, "uninstall") as mk_uninstall: + result = hub._Hub(None).screen_uninstall() + mk_run.assert_not_called() + mk_uninstall.assert_not_called() self.assertIs(result, tui.Wizard.BACK) def _capture_flashes(self): |
