diff options
Diffstat (limited to 'app/tests')
| -rw-r--r-- | app/tests/test_hub.py | 55 | ||||
| -rw-r--r-- | app/tests/test_selfupdate.py | 21 |
2 files changed, 44 insertions, 32 deletions
diff --git a/app/tests/test_hub.py b/app/tests/test_hub.py index 228a103..8d5edd9 100644 --- a/app/tests/test_hub.py +++ b/app/tests/test_hub.py @@ -396,7 +396,8 @@ class SubmenuStatusTableTests(unittest.TestCase): def setUp(self): # These tests concern the backend actions; the host's git-checkout - # state (which gates the "Update Generator" entry) must not leak in. + # state (which gates the "Update tts-audiobook-generator" entry) + # must not leak in. patcher = patch.object(hub.selfupdate, "is_git_checkout", return_value=False) patcher.start() @@ -4049,7 +4050,7 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): self.assertEqual(flashes[-1][1], "err") self.assertIn("did not complete", flashes[-1][0]) - def test_update_backends_action_flashes_warn_when_cancelled(self): + def test_update_backends_action_silent_when_cancelled(self): infos = [BackendInfo("qwen", "qwen-tts", lambda: None, lambda: 0, update=lambda **kw: 0)] statuses = [BackendStatus("qwen", "qwen-tts", installed=True, @@ -4057,11 +4058,14 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): patch_flash, flashes = self._capture_flashes() with patch.object(hub, "REGISTRY", infos), \ patch.object(hub, "detect_all", return_value=statuses), \ - patch.object(hub.taskview, "run_steps", return_value=130), \ + patch.object(hub.taskview, "run_steps", + return_value=130) as mk_run, \ patch_flash: hub._update_backends_action(None) - self.assertEqual(flashes[-1][1], "warn") - self.assertIn("cancelled", flashes[-1][0]) + # The task view already showed "cancelled" and waited for a key, + # so the hub adds no flash on top of it. + mk_run.assert_called_once() + self.assertEqual(flashes, []) def test_update_backends_action_without_targets_flashes_a_hint(self): # An installed backend without an update action (and nothing else @@ -4129,8 +4133,8 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): hub._Hub(None).screen_configure() return [opt[0] for opt in captured["options"]] - self.assertIn("Update Generator", options_for(True)) - self.assertNotIn("Update Generator", options_for(False)) + self.assertIn("Update tts-audiobook-generator", options_for(True)) + self.assertNotIn("Update tts-audiobook-generator", options_for(False)) def test_selecting_update_generator_runs_the_action_and_reshows(self): titles = [] @@ -4170,8 +4174,6 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): patch_flash, flashes = self._capture_flashes() with patch.object(hub.selfupdate, "is_git_checkout", return_value=True), \ - patch.object(hub.selfupdate, "current_commit", - return_value="aaa"), \ patch.object(hub.selfupdate, "modified_tracked_files", return_value=["app/converter/config.py"]), \ patch.object(hub.tui, "confirm", @@ -4185,12 +4187,10 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): body = mk_confirm.call_args[1]["body"] self.assertIn("app/converter/config.py", body) - def test_update_self_action_runs_step_and_flashes_update(self): + def test_update_self_action_runs_step_silently_on_success(self): patch_flash, flashes = self._capture_flashes() with patch.object(hub.selfupdate, "is_git_checkout", return_value=True), \ - patch.object(hub.selfupdate, "current_commit", - side_effect=["aaa", "bbb"]), \ patch.object(hub.selfupdate, "modified_tracked_files", return_value=[]), \ patch.object(hub.taskview, "run_steps", @@ -4201,7 +4201,8 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): hub._update_self_action(None) mk_run.assert_called_once() self.assertEqual(mk_run.call_args[0][0], None) - self.assertEqual(mk_run.call_args[0][1], "Update Generator") + self.assertEqual(mk_run.call_args[0][1], + "Update tts-audiobook-generator") steps = mk_run.call_args[0][2] self.assertEqual([step.title for step in steps], ["Fetch and reset the checkout"]) @@ -4211,48 +4212,38 @@ class ConfigureBackendsDispatchTests(unittest.TestCase): steps[0].work(emit, "CANCEL") mk_update.assert_called_once_with(emit=emit, cancel="CANCEL") - self.assertEqual(len(flashes), 1) - text, kind = flashes[0] - self.assertEqual(kind, "ok") - self.assertIn("aaa", text) - self.assertIn("bbb", text) - self.assertIn("Restart to apply", text) + # The task view already showed "completed" and waited for a key; + # the restart reminder lives in the run's console output. + self.assertEqual(flashes, []) - def test_update_self_action_flashes_already_up_to_date(self): + def test_update_self_action_silent_when_already_up_to_date(self): patch_flash, flashes = self._capture_flashes() with patch.object(hub.selfupdate, "is_git_checkout", return_value=True), \ - patch.object(hub.selfupdate, "current_commit", - side_effect=["aaa", "aaa"]), \ patch.object(hub.selfupdate, "modified_tracked_files", return_value=[]), \ patch.object(hub.taskview, "run_steps", return_value=0), \ patch_flash: hub._update_self_action(None) - self.assertEqual(flashes, - [("The generator is already up to date (aaa).", - "ok")]) + # The console already said so; no flash after the key press. + self.assertEqual(flashes, []) - def test_update_self_action_flashes_warn_when_cancelled(self): + def test_update_self_action_silent_when_cancelled(self): patch_flash, flashes = self._capture_flashes() with patch.object(hub.selfupdate, "is_git_checkout", return_value=True), \ - patch.object(hub.selfupdate, "current_commit", - side_effect=["aaa", "aaa"]), \ patch.object(hub.selfupdate, "modified_tracked_files", return_value=[]), \ patch.object(hub.taskview, "run_steps", return_value=130), \ patch_flash: hub._update_self_action(None) - self.assertEqual(flashes[-1][1], "warn") - self.assertIn("cancelled", flashes[-1][0]) + # The task view already showed "cancelled" and waited for a key. + self.assertEqual(flashes, []) def test_update_self_action_flashes_err_when_failed(self): patch_flash, flashes = self._capture_flashes() with patch.object(hub.selfupdate, "is_git_checkout", return_value=True), \ - patch.object(hub.selfupdate, "current_commit", - side_effect=["aaa", "aaa"]), \ patch.object(hub.selfupdate, "modified_tracked_files", return_value=[]), \ patch.object(hub.taskview, "run_steps", return_value=1), \ diff --git a/app/tests/test_selfupdate.py b/app/tests/test_selfupdate.py index bf2f6b3..b69c6e3 100644 --- a/app/tests/test_selfupdate.py +++ b/app/tests/test_selfupdate.py @@ -155,6 +155,9 @@ class UpdateGeneratorTests(unittest.TestCase): self.assertEqual(self.config.read_bytes(), b"# user settings\n") self.assertTrue(any("already up to date" in line for line in self.emitted)) + # A no-op update needs no restart, so no reminder either. + self.assertFalse(any("Restart to apply" in line + for line in self.emitted)) def test_fetch_failure_short_circuits(self): run = self._patch_git(fetch_rc=128) @@ -200,6 +203,24 @@ class UpdateGeneratorTests(unittest.TestCase): self.assertEqual(run.call_args_list[1][1]["emit"], self.emitted.append) + def test_successful_reset_prints_the_restart_reminder(self): + # The hub no longer flashes after the task view's summary, so the + # console output itself must tell the user to restart. + self._patch_git() + rc = selfupdate.update_generator(root=self.root, + emit=self.emitted.append) + self.assertEqual(rc, 0) + self.assertTrue(any("Restart to apply" in line + for line in self.emitted)) + + def test_failed_reset_prints_no_restart_reminder(self): + self._patch_git(reset_rc=1) + rc = selfupdate.update_generator(root=self.root, + emit=self.emitted.append) + self.assertEqual(rc, 1) + self.assertFalse(any("Restart to apply" in line + for line in self.emitted)) + def test_reset_failure_still_restores_the_snapshot(self): self._patch_git(reset_rc=1, on_reset=lambda: self.config.write_bytes( b"# upstream settings\n")) |
