aboutsummaryrefslogtreecommitdiff
path: root/tests/test_tts.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-19 03:55:13 -0400
committerhistoria <historiavg@proton.me>2026-08-19 03:55:13 -0400
commit87e5216cd287f411b2ffab04dbc435f48c1d4aae (patch)
treed24346d6793233a2af6305f8463ae17765e00d44 /tests/test_tts.py
parentf1f8e899c46de80d7f9fbb8f0b53983e18167bd2 (diff)
downloadtts-audiobook-generator-87e5216cd287f411b2ffab04dbc435f48c1d4aae.tar.gz
refactor: config.py simplified
Diffstat (limited to 'tests/test_tts.py')
-rw-r--r--tests/test_tts.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/tests/test_tts.py b/tests/test_tts.py
index dfeda6f..47a8309 100644
--- a/tests/test_tts.py
+++ b/tests/test_tts.py
@@ -7,7 +7,7 @@ import wave
from pathlib import Path
from unittest.mock import MagicMock, patch
-from converter import config
+from converter import config, tts
from converter.converter import AudiobookConverter
from converter.tts import FasterTTSClient, QwenTTSClient, normalize_language
@@ -35,7 +35,7 @@ class NormalizeLanguageTests(unittest.TestCase):
self.assertEqual(normalize_language("it"), "Italian")
def test_all_supported_languages_round_trip(self):
- for name in config.TTS_LANGUAGES:
+ for name in tts.TTS_LANGUAGES:
self.assertEqual(normalize_language(name.lower()), name)
def test_unknown_language_rejected_with_guidance(self):
@@ -60,14 +60,14 @@ class QwenTTSClientLanguageTests(unittest.TestCase):
return QwenTTSClient(**kwargs)
def test_default_follows_config_for_each_mode(self):
- custom = self._make_client(voice_mode=config.VOICE_MODE_CUSTOM)
- self.assertEqual(custom.language, config.CUSTOM_VOICE_LANGUAGE)
- clone = self._make_client(voice_mode=config.VOICE_MODE_CLONE,
+ custom = self._make_client(voice_mode=tts.VOICE_MODE_CUSTOM)
+ self.assertEqual(custom.language, config.LANGUAGE)
+ clone = self._make_client(voice_mode=tts.VOICE_MODE_CLONE,
voice_clone_ref_audio="ref.wav")
- self.assertEqual(clone.language, config.VOICE_CLONE_LANGUAGE)
+ self.assertEqual(clone.language, config.LANGUAGE)
def test_explicit_language_normalized(self):
- client = self._make_client(voice_mode=config.VOICE_MODE_CUSTOM, language="ja")
+ client = self._make_client(voice_mode=tts.VOICE_MODE_CUSTOM, language="ja")
self.assertEqual(client.language, "Japanese")
def test_invalid_language_fails_before_connect(self):
@@ -90,7 +90,7 @@ class PayloadLanguageTests(unittest.TestCase):
def _custom_client(self, language, endpoint, api_info=None):
client = QwenTTSClient.__new__(QwenTTSClient)
- client.voice_mode = config.VOICE_MODE_CUSTOM
+ client.voice_mode = tts.VOICE_MODE_CUSTOM
client.language = language
client.api_info = api_info if api_info is not None else {
"named_endpoints": {endpoint: {}}
@@ -100,7 +100,7 @@ class PayloadLanguageTests(unittest.TestCase):
def _clone_client(self, language, endpoint, api_info=None, ref_text="hello"):
client = QwenTTSClient.__new__(QwenTTSClient)
- client.voice_mode = config.VOICE_MODE_CLONE
+ client.voice_mode = tts.VOICE_MODE_CLONE
client.language = language
client.voice_clone_ref_audio = str(self.ref_audio)
client.voice_clone_ref_text = ref_text
@@ -149,8 +149,8 @@ class PayloadLanguageTests(unittest.TestCase):
client = self._clone_client("English", "/generate_voice_clone", api_info=api_info)
client._generate_voice_clone("text")
kwargs = client.clone_client.predict.call_args.kwargs
- self.assertEqual(kwargs["model_size"], config.VOICE_CLONE_MODEL_SIZE)
- self.assertEqual(kwargs["seed"], config.VOICE_CLONE_SEED)
+ self.assertEqual(kwargs["model_size"], tts.MODEL_SIZE)
+ self.assertEqual(kwargs["seed"], config.SEED)
self.assertNotIn("max_chunk_chars", kwargs)
@@ -201,7 +201,7 @@ class FasterTTSClientGenerateTests(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
- self._chunks = patch.object(config, "CHUNKS_FOLDER", Path(self._tmp.name))
+ self._chunks = patch.object(tts, "CHUNKS_FOLDER", Path(self._tmp.name))
self._chunks.start()
self._sleep = patch("converter.tts.time.sleep")
self._sleep.start()
@@ -233,7 +233,7 @@ class FasterTTSClientGenerateTests(unittest.TestCase):
channels, sampwidth, framerate, frames = self._read_wav(path)
self.assertEqual(channels, 1)
self.assertEqual(sampwidth, 2)
- self.assertEqual(framerate, config.FASTER_TTS_SAMPLE_RATE)
+ self.assertEqual(framerate, tts.SAMPLE_RATE)
self.assertEqual(frames, pcm)
def test_long_text_is_subchunked_and_concatenated_in_order(self):
@@ -241,7 +241,7 @@ class FasterTTSClientGenerateTests(unittest.TestCase):
sentences = [" ".join(f"word{i}" for i in range(6)) + "." for _ in range(3)]
text = " ".join(sentences)
pcm_parts = [b"\x01\x00" * 10, b"\x02\x00" * 20, b"\x03\x00" * 30]
- with patch.object(config, "FASTER_SUBCHUNK_WORDS", 10), \
+ with patch.object(config, "CHUNK_SIZE_WORDS", 10), \
patch.object(client, "_request_pcm", side_effect=pcm_parts) as mock_pcm:
result = client.generate_chunk(text, 1)
self.assertEqual(mock_pcm.call_count, 3)
@@ -290,7 +290,7 @@ class FasterTTSClientGenerateTests(unittest.TestCase):
side_effect=RuntimeError("down")) as mock_pcm:
result = client.generate_chunk("Hello.", 1)
self.assertIsNone(result)
- self.assertEqual(mock_pcm.call_count, config.FASTER_SUBCHUNK_RETRIES)
+ self.assertEqual(mock_pcm.call_count, config.MAX_RETRIES)
def test_empty_text_fails_the_chunk(self):
client = self._make_client()
@@ -322,7 +322,7 @@ class FasterModeWiringTests(unittest.TestCase):
def test_faster_mode_uses_faster_client_without_reference(self):
with patch("converter.converter.FasterTTSClient") as mock_faster, \
patch("converter.converter.QwenTTSClient") as mock_qwen:
- AudiobookConverter(voice_mode=config.VOICE_MODE_CLONE,
+ AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE,
faster=True, faster_voice="narrator")
mock_faster.assert_called_once_with(voice="narrator")
mock_qwen.assert_not_called()
@@ -330,7 +330,7 @@ class FasterModeWiringTests(unittest.TestCase):
def test_non_faster_clone_mode_still_requires_reference(self):
with patch("converter.converter.QwenTTSClient"):
with self.assertRaises(ValueError):
- AudiobookConverter(voice_mode=config.VOICE_MODE_CLONE)
+ AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE)
def test_faster_mode_still_validates_other_settings(self):
with patch("converter.converter.FasterTTSClient"):
@@ -341,7 +341,7 @@ class FasterModeWiringTests(unittest.TestCase):
def _faster_converter(self, faster_voice=None):
with patch("converter.converter.FasterTTSClient"):
- return AudiobookConverter(voice_mode=config.VOICE_MODE_CLONE,
+ return AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE,
faster=True, faster_voice=faster_voice)
def test_narrator_tag_uses_faster_voice_name(self):
@@ -362,7 +362,7 @@ class FasterModeWiringTests(unittest.TestCase):
ref = Path(tmp) / "ref.wav"
ref.write_bytes(b"x")
with patch("converter.converter.QwenTTSClient"):
- converter = AudiobookConverter(voice_mode=config.VOICE_MODE_CLONE,
+ converter = AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE,
voice_clone_ref_audio=str(ref))
self.assertEqual(converter._narrator_tag(), "ref")