aboutsummaryrefslogtreecommitdiff
path: root/tests/test_backends.py
blob: 4017cd490f5ee9a4fa5d94136c32bd228533fbbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Tests for the backends package registry and detection aggregation."""

import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch

from backends import REGISTRY, detect_all, get


class RegistryTests(unittest.TestCase):
    def test_registry_has_the_three_backends(self):
        keys = [info.key for info in REGISTRY]
        self.assertEqual(keys, ["audiocpp", "qwen", "faster"])

    def test_every_entry_has_detect_and_setup_tui(self):
        for info in REGISTRY:
            self.assertTrue(callable(info.detect), info.key)
            self.assertTrue(callable(info.setup_tui), info.key)
            self.assertIsInstance(info.modify_actions, list)
            for action in info.modify_actions:
                self.assertTrue(callable(action.run))

    def test_get_returns_entry_by_key(self):
        self.assertIs(get("audiocpp").key, "audiocpp")
        self.assertIsNone(get("nonexistent"))


class DetectAllTests(unittest.TestCase):
    def test_detect_all_returns_one_status_per_backend(self):
        statuses = detect_all()
        self.assertEqual([s.key for s in statuses],
                         ["audiocpp", "qwen", "faster"])
        for s in statuses:
            self.assertIn(s.key, ("audiocpp", "qwen", "faster"))
            # ready requires both installed and configured; on a clean
            # machine none are ready.
            if s.ready:
                self.assertTrue(s.installed and s.configured)

    def test_audiocpp_status_when_cloned_built_configured(self):
        with tempfile.TemporaryDirectory() as td:
            root = Path(td)
            checkout = root / "audio.cpp"
            checkout.mkdir()
            (checkout / "model_specs").mkdir()
            (checkout / "build" / "linux-cuda-release" / "bin").mkdir(
                parents=True)
            (checkout / "build" / "linux-cuda-release" / "bin"
             / "audiocpp_server").write_bytes(b"x")
            (checkout / "server.json").write_text('{"models":[]}',
                                                  encoding="utf-8")
            from backends import audiocpp
            with patch.object(audiocpp, "find_local_checkout",
                              return_value=checkout):
                status = audiocpp.detect()
            self.assertTrue(status.installed)
            self.assertTrue(status.configured)
            self.assertTrue(status.ready)
            self.assertIn("audiocpp_server", status.launch_hint)

    def test_qwen_status_reflects_install(self):
        from backends import qwen
        with patch.object(qwen, "_is_installed", return_value=True):
            status = qwen.detect()
        self.assertTrue(status.installed)
        self.assertTrue(status.configured)
        self.assertIn("qwen-tts-demo", status.launch_hint)
        with patch.object(qwen, "_is_installed", return_value=False):
            status = qwen.detect()
        self.assertFalse(status.installed)
        self.assertFalse(status.configured)

    def test_faster_status_reflects_install_clone_voices(self):
        from backends import faster
        with tempfile.TemporaryDirectory() as td:
            checkout = Path(td) / "faster-qwen3-tts"
            (checkout / "examples").mkdir(parents=True)
            (checkout / "examples" / "openai_server.py").write_text("x")
            (checkout / "voices.json").write_text('{"default":{}}',
                                                  encoding="utf-8")
            with patch.object(faster, "_is_installed", return_value=True), \
                    patch.object(faster, "_checkout", return_value=checkout):
                status = faster.detect()
            self.assertTrue(status.installed)
            self.assertTrue(status.configured)
            self.assertIn("openai_server.py", status.launch_hint)


if __name__ == "__main__":
    unittest.main()