aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_backends_audiocpp.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-24 20:17:11 -0400
committerhistoria <historiavg@proton.me>2026-08-24 20:17:11 -0400
commitcf24fa74188cee498eeb7b94422371c952278d4a (patch)
tree302244a8b09b9173fbde542874cfa549f26be7a2 /app/tests/test_backends_audiocpp.py
parent0522e73b68291af62e43c387ab8f9b8ffa2cab47 (diff)
downloadtts-audiobook-generator-cf24fa74188cee498eeb7b94422371c952278d4a.tar.gz
fix: stepping back steps in tui
Diffstat (limited to 'app/tests/test_backends_audiocpp.py')
-rw-r--r--app/tests/test_backends_audiocpp.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/app/tests/test_backends_audiocpp.py b/app/tests/test_backends_audiocpp.py
index 3d042db..dd19cd5 100644
--- a/app/tests/test_backends_audiocpp.py
+++ b/app/tests/test_backends_audiocpp.py
@@ -1,5 +1,6 @@
"""Tests for the audio.cpp backend setup module (backends/audiocpp.py)."""
+import contextlib
import io
import json
import sys
@@ -11,6 +12,7 @@ from unittest.mock import MagicMock, patch
from converter import config
from backends import audiocpp as make_server
+from ui import tui
FAKE_CONFIG = (
'LANGUAGE = "English"\n'
@@ -1542,6 +1544,68 @@ class HandInstallGuidanceTests(unittest.TestCase):
self.assertIn("download", message.lower())
+class WizardNavigationTests(unittest.TestCase):
+ """Esc in the audio.cpp wizard goes back one screen (via tui.Wizard)."""
+
+ def _args(self):
+ return make_server.build_parser().parse_args([])
+
+ def _checkout(self):
+ tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(tmp.cleanup)
+ return _make_checkout(Path(tmp.name))
+
+ def test_esc_on_first_screen_aborts(self):
+ # Configure audio.cpp (modify flow): the families tree is the first
+ # screen, so Esc on it must abort the wizard — not re-show itself.
+ checkout = self._checkout()
+ with patch.object(make_server, "find_local_checkout",
+ return_value=checkout), \
+ patch.object(tui, "checkbox_tree",
+ return_value=make_server._GO_BACK):
+ settings = make_server._wizard(None, self._args(),
+ make_server.build_parser())
+ self.assertIsNone(settings)
+
+ def test_bind_host_esc_returns_to_families_tree(self):
+ # Esc on "Bind host" must fall back to the model-family tree, then
+ # re-selecting proceeds through the rest of the wizard.
+ checkout = self._checkout()
+ catalog = make_server.load_model_catalog(checkout)
+ supertonic = next(i for i, entry in enumerate(catalog)
+ if entry["family"] == "supertonic")
+ tree_calls = []
+ hosts = iter([make_server._GO_BACK, "127.0.0.1"])
+
+ def fake_tree(*args, **kwargs):
+ tree_calls.append(1)
+ return [(supertonic, "Supertonic-GGUF")]
+
+ def fake_line_edit(stdscr, title, default, **kwargs):
+ if title == "Bind host":
+ return next(hosts)
+ if title == "Port":
+ return "8080"
+ return default
+
+ with patch.object(make_server, "find_local_checkout",
+ return_value=checkout), \
+ patch.object(tui, "checkbox_tree",
+ side_effect=fake_tree), \
+ patch.object(tui, "line_edit",
+ side_effect=fake_line_edit), \
+ patch.object(tui, "menu", return_value="cuda"), \
+ patch.object(tui, "confirm", return_value=True):
+ settings = make_server._wizard(None, self._args(),
+ make_server.build_parser())
+ self.assertIsNotNone(settings)
+ # The tree was re-shown after the host screen's Esc.
+ self.assertEqual(len(tree_calls), 2)
+ self.assertEqual(settings["host"], "127.0.0.1")
+ self.assertEqual([m["id"] for m in settings["model_entries"]],
+ ["supertonic"])
+
+
class UninstallTests(unittest.TestCase):
"""uninstall: stop the server and remove the checkout."""
@@ -1568,3 +1632,27 @@ class UninstallTests(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
+
+
+class SetupScreenTests(unittest.TestCase):
+ """setup_screen: the wizard run on the hub's screen, console tail via
+ suspend."""
+
+ def test_abort_returns_one_without_executing(self):
+ with patch.object(make_server, "_wizard", return_value=None) as mk_wizard, \
+ patch.object(make_server, "_execute") as mk_execute:
+ rc = make_server.setup_screen(None)
+ self.assertEqual(rc, 1)
+ mk_wizard.assert_called_once()
+ mk_execute.assert_not_called()
+
+ def test_success_executes_the_tail_under_suspend(self):
+ settings = {"audiocpp_dir": Path("/x")}
+ with patch.object(make_server, "_wizard", return_value=settings), \
+ patch.object(make_server, "_execute",
+ return_value=0) as mk_execute, \
+ patch.object(tui, "suspend", contextlib.nullcontext):
+ rc = make_server.setup_screen(None)
+ self.assertEqual(rc, 0)
+ mk_execute.assert_called_once()
+ self.assertIs(mk_execute.call_args[0][0], settings)