diff options
Diffstat (limited to 'tests/test_converter.py')
| -rw-r--r-- | tests/test_converter.py | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/tests/test_converter.py b/tests/test_converter.py index a79ae58..91ab0b5 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -6,7 +6,8 @@ import unittest from pathlib import Path from unittest.mock import MagicMock, patch -from converter import config +from converter import config, tts +from converter import converter as converter_mod from converter.converter import ( AudiobookConverter, find_existing_outputs, @@ -66,11 +67,11 @@ class FindExistingOutputsTests(unittest.TestCase): def setUp(self): self._tmp = tempfile.TemporaryDirectory() self.folder = Path(self._tmp.name) - self._original = config.AUDIOBOOKS_FOLDER - config.AUDIOBOOKS_FOLDER = self.folder + self._original = converter_mod.AUDIOBOOKS_FOLDER + converter_mod.AUDIOBOOKS_FOLDER = self.folder def tearDown(self): - config.AUDIOBOOKS_FOLDER = self._original + converter_mod.AUDIOBOOKS_FOLDER = self._original self._tmp.cleanup() def _touch(self, name): @@ -125,28 +126,28 @@ class NarratorTagTests(unittest.TestCase): return converter def test_custom_voice_uses_speaker_display_name(self): - self.assertEqual(self._converter(config.VOICE_MODE_CUSTOM)._narrator_tag(), + self.assertEqual(self._converter(tts.VOICE_MODE_CUSTOM)._narrator_tag(), "Vivian") def test_multi_word_display_name_gets_underscores(self): with patch.object(config, "CUSTOM_VOICE_SPEAKER", "uncle_fu"): - self.assertEqual(self._converter(config.VOICE_MODE_CUSTOM)._narrator_tag(), + self.assertEqual(self._converter(tts.VOICE_MODE_CUSTOM)._narrator_tag(), "Uncle_Fu") def test_clone_uses_reference_audio_stem(self): - self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/ref.wav")._narrator_tag(), + self.assertEqual(self._converter(tts.VOICE_MODE_CLONE, "/x/ref.wav")._narrator_tag(), "ref") def test_clone_stem_spaces_become_underscores(self): - self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/my voice.wav")._narrator_tag(), + self.assertEqual(self._converter(tts.VOICE_MODE_CLONE, "/x/my voice.wav")._narrator_tag(), "my_voice") def test_invalid_characters_sanitized(self): - self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/bad:name?.wav")._narrator_tag(), + self.assertEqual(self._converter(tts.VOICE_MODE_CLONE, "/x/bad:name?.wav")._narrator_tag(), "bad_name") def test_empty_after_sanitize_falls_back(self): - self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/???.wav")._narrator_tag(), + self.assertEqual(self._converter(tts.VOICE_MODE_CLONE, "/x/???.wav")._narrator_tag(), "narrator") @@ -171,7 +172,7 @@ class DebugDumpTests(unittest.TestCase): def setUp(self): self._tmp = tempfile.TemporaryDirectory() - self._debug_folder = patch.object(config, "DEBUG_FOLDER", Path(self._tmp.name)) + self._debug_folder = patch.object(converter_mod, "DEBUG_FOLDER", Path(self._tmp.name)) self._debug_folder.start() self.debug_root = Path(self._tmp.name) self.converter = AudiobookConverter.__new__(AudiobookConverter) @@ -259,7 +260,7 @@ class SetupLoggingTests(unittest.TestCase): def setUp(self): self._tmp = tempfile.TemporaryDirectory() - self._logs_folder = patch.object(config, "LOGS_FOLDER", Path(self._tmp.name)) + self._logs_folder = patch.object(converter_mod, "LOGS_FOLDER", Path(self._tmp.name)) self._logs_folder.start() self._root = logging.getLogger() self._saved_handlers = self._root.handlers[:] @@ -376,12 +377,12 @@ class RunOverwritePromptTests(unittest.TestCase): def setUp(self): self._books_tmp = tempfile.TemporaryDirectory() self._output_tmp = tempfile.TemporaryDirectory() - self._original_folders = (config.BOOKS_FOLDER, config.AUDIOBOOKS_FOLDER) - config.BOOKS_FOLDER = Path(self._books_tmp.name) - config.AUDIOBOOKS_FOLDER = Path(self._output_tmp.name) - (config.BOOKS_FOLDER / "book.txt").write_text("hello world", encoding="utf-8") + self._original_folders = (converter_mod.BOOKS_FOLDER, converter_mod.AUDIOBOOKS_FOLDER) + converter_mod.BOOKS_FOLDER = Path(self._books_tmp.name) + converter_mod.AUDIOBOOKS_FOLDER = Path(self._output_tmp.name) + (converter_mod.BOOKS_FOLDER / "book.txt").write_text("hello world", encoding="utf-8") self.converter = AudiobookConverter.__new__(AudiobookConverter) - self.converter.voice_mode = config.VOICE_MODE_CUSTOM + self.converter.voice_mode = tts.VOICE_MODE_CUSTOM self.converter.voice_clone_ref_audio = None self.converter.faster = False self.converter.faster_voice = None @@ -396,19 +397,19 @@ class RunOverwritePromptTests(unittest.TestCase): not self.converted.append((file_path.name, output_name)) or True) def tearDown(self): - config.BOOKS_FOLDER, config.AUDIOBOOKS_FOLDER = self._original_folders + converter_mod.BOOKS_FOLDER, converter_mod.AUDIOBOOKS_FOLDER = self._original_folders self._books_tmp.cleanup() self._output_tmp.cleanup() def test_declined_book_is_skipped(self): - (config.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").write_bytes(b"existing") + (converter_mod.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").write_bytes(b"existing") with patch("builtins.input", return_value="n"): self.assertTrue(self.converter.run()) self.assertEqual(self.converted, []) - self.assertTrue((config.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").exists()) + self.assertTrue((converter_mod.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").exists()) def test_accepted_book_is_converted(self): - (config.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").write_bytes(b"existing") + (converter_mod.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").write_bytes(b"existing") with patch("builtins.input", return_value="y"): self.assertTrue(self.converter.run()) self.assertEqual(self.converted, [("book.txt", "book_Vivian")]) |
