diff options
| author | historia <historiavg@proton.me> | 2026-08-26 03:02:23 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-26 03:02:23 -0400 |
| commit | c147087c9d4707bffaeee58d390653637a21cce8 (patch) | |
| tree | b080c40eaa388609dea38c2cc413cb912aa7b4af /app/tests/test_backends.py | |
| parent | 8b5c8697740ff415cf7f1d03c9fb5a8c8851d420 (diff) | |
| download | tts-audiobook-generator-c147087c9d4707bffaeee58d390653637a21cce8.tar.gz | |
refactor: put shared ui screen code into ui.viewkit
Diffstat (limited to 'app/tests/test_backends.py')
| -rw-r--r-- | app/tests/test_backends.py | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/app/tests/test_backends.py b/app/tests/test_backends.py index 4ff6f6e..dc2b4d0 100644 --- a/app/tests/test_backends.py +++ b/app/tests/test_backends.py @@ -5,7 +5,16 @@ import unittest from pathlib import Path from unittest.mock import patch -from backends import REGISTRY, ServerSpec, detect_all, format_launch_hint, get +import backends +from backends import ( + REGISTRY, + BackendStatus, + ServerSpec, + detect_all, + format_launch_hint, + get, + invalidate_detect_cache, +) class FormatLaunchHintTests(unittest.TestCase): @@ -294,6 +303,50 @@ class RemoteSuppressionTests(unittest.TestCase): self.assertEqual(status.remote_urls, {}) +class DetectCacheTests(unittest.TestCase): + """detect_all's short-TTL cache (menu renders re-probe only after it).""" + + def setUp(self): + get("audiocpp") # build the lazy registry before patching its entries + invalidate_detect_cache() + self.addCleanup(invalidate_detect_cache) + self.probes = [] + self.patches = [] + for info in REGISTRY: + def fake_detect(key=info.key): + self.probes.append(key) + return BackendStatus(key, key, installed=False, configured=False) + self.patches.append(patch.object(info, "detect", + side_effect=fake_detect)) + for p in self.patches: + p.start() + self.addCleanup(p.stop) + + def test_repeated_calls_within_the_ttl_probe_once(self): + first = detect_all() + second = detect_all() + self.assertEqual(first, second) + self.assertEqual(sorted(self.probes), sorted(i.key for i in REGISTRY)) + self.assertEqual(len(self.probes), len(REGISTRY)) + + def test_refresh_bypasses_the_cache(self): + detect_all() + detect_all(refresh=True) + self.assertEqual(len(self.probes), 2 * len(REGISTRY)) + + def test_invalidate_forces_the_next_call_to_reprobe(self): + detect_all() + invalidate_detect_cache() + detect_all() + self.assertEqual(len(self.probes), 2 * len(REGISTRY)) + + def test_expiry_after_the_ttl_reprobes(self): + with patch.object(backends, "DETECT_TTL_SECONDS", 0.0): + detect_all() + detect_all() + self.assertEqual(len(self.probes), 2 * len(REGISTRY)) + + if __name__ == "__main__": unittest.main() |
