diff options
Diffstat (limited to 'app/tests/test_runview.py')
| -rw-r--r-- | app/tests/test_runview.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/tests/test_runview.py b/app/tests/test_runview.py index 31a8ebe..f2d5180 100644 --- a/app/tests/test_runview.py +++ b/app/tests/test_runview.py @@ -363,6 +363,45 @@ class WorkerTests(_FakeTui, unittest.TestCase): self.assertIn("ERROR - boom", text) self.assertIn("error", [e["kind"] for e in self._drain(view)]) + def test_restart_first_stops_then_boots_the_new_model(self): + # The managed qwen server hosts another model than this run picked: + # the worker stops it (releasing the single port) before booting + # the spec again — whose argv now names the newly-selected model. + from types import SimpleNamespace + spec = SimpleNamespace(name="qwen") + events = [] + + def fake_start(spec_, progress=None, cancel=None): + events.append(("start", progress)) + progress({"kind": "ready", "name": "qwen", + "url": "http://127.0.0.1:7860"}) + return True + + with patch("audiobook.convert") as mk_convert, \ + patch.object(runview.servers, "stop") as mk_stop, \ + patch.object(runview.servers, "start", + side_effect=fake_start): + view = self.make_view(autostart_spec=spec, restart_first=True, + server_name="qwen") + view._worker_main() + mk_stop.assert_called_once_with("qwen") + events = self._drain(view) + kinds = [e["kind"] for e in events] + self.assertIn("ready", kinds) + self.assertNotIn("error", kinds) + mk_convert.assert_called_once() + + def test_no_restart_without_the_flag(self): + # A plain autostart never stops a server first. + from types import SimpleNamespace + spec = SimpleNamespace(name="qwen") + with patch("audiobook.convert"), \ + patch.object(runview.servers, "stop") as mk_stop, \ + patch.object(runview.servers, "start", return_value=True): + view = self.make_view(autostart_spec=spec, server_name="qwen") + view._worker_main() + mk_stop.assert_not_called() + if __name__ == "__main__": unittest.main() |
