diff options
Diffstat (limited to 'app/tests/test_backends_faster.py')
| -rw-r--r-- | app/tests/test_backends_faster.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/tests/test_backends_faster.py b/app/tests/test_backends_faster.py index eb1fa28..7e27b47 100644 --- a/app/tests/test_backends_faster.py +++ b/app/tests/test_backends_faster.py @@ -3,6 +3,7 @@ import json import sys import tempfile +import threading import unittest import contextlib from pathlib import Path @@ -276,3 +277,60 @@ class SetupScreenTests(unittest.TestCase): self.assertIs(mk_steps.call_args[0][0], settings) mk_run.assert_called_once() self.assertEqual(mk_run.call_args[0][2], steps) + + +class UninstallTests(unittest.TestCase): + """uninstall: stop the server, pip-uninstall, delete the checkout.""" + + def test_pips_and_removes_checkout(self): + with tempfile.TemporaryDirectory() as td: + checkout = Path(td) / "faster-qwen3-tts" + checkout.mkdir() + with patch.object(make_voices, "_checkout", + return_value=checkout), \ + patch.object(make_voices.servers, "stop") as mk_stop, \ + patch.object(make_voices.common, "pip_uninstall", + return_value=0) as mk_pip: + rc = make_voices.uninstall(emit="EMIT") + self.assertEqual(rc, 0) + mk_stop.assert_called_once_with("faster") + # The task view's emit is forwarded so pip never touches the terminal. + mk_pip.assert_called_once_with(["faster-qwen3-tts"], emit="EMIT") + self.assertFalse(checkout.exists()) + + def test_no_checkout_still_uninstalls_the_package(self): + with patch.object(make_voices, "_checkout", + return_value=Path("/no/such/dir")), \ + patch.object(make_voices.servers, "stop"), \ + patch.object(make_voices.common, "pip_uninstall", + return_value=0) as mk_pip: + rc = make_voices.uninstall() + self.assertEqual(rc, 0) + mk_pip.assert_called_once_with(["faster-qwen3-tts"], emit=None) + + def test_cancel_before_pip_skips_everything_after_stopping(self): + cancel = threading.Event() + cancel.set() + with patch.object(make_voices.servers, "stop") as mk_stop, \ + patch.object(make_voices.common, "pip_uninstall") as mk_pip: + rc = make_voices.uninstall(cancel=cancel) + self.assertEqual(rc, 130) + mk_stop.assert_called_once_with("faster") + mk_pip.assert_not_called() + + def test_cancel_before_delete_keeps_checkout(self): + # Cancel between phases: pip runs to completion, but a pending + # cancellation stops the checkout deletion from starting. + with tempfile.TemporaryDirectory() as td: + checkout = Path(td) / "faster-qwen3-tts" + checkout.mkdir() + cancel = threading.Event() + cancel.set() + with patch.object(make_voices, "_checkout", + return_value=checkout), \ + patch.object(make_voices.servers, "stop"), \ + patch.object(make_voices.common, "pip_uninstall", + return_value=0): + rc = make_voices.uninstall(cancel=cancel) + self.assertEqual(rc, 130) + self.assertTrue(checkout.exists()) |
