From 7e8bf663a65111fb648b01d9f45ad08eddbf2515 Mon Sep 17 00:00:00 2001 From: historia Date: Tue, 18 Aug 2026 19:32:48 -0400 Subject: feat: include narrator in output filenames --- tests/test_converter.py | 54 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'tests/test_converter.py') diff --git a/tests/test_converter.py b/tests/test_converter.py index 351849a..ae307a2 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -97,6 +97,50 @@ class FindExistingOutputsTests(unittest.TestCase): found = [p.name for p in find_existing_outputs("book [1]", "mp3")] self.assertEqual(sorted(found), ["book [1].mp3", "book [1]_1.5x.mp3"]) + def test_narrator_named_outputs_detected(self): + for name in ("dune_Vivian.mp3", "dune_Vivian_1.5.mp3", "dune_Vivian_01_Dune.mp3"): + self._touch(name) + found = [p.name for p in find_existing_outputs("dune_Vivian", "mp3")] + self.assertEqual(len(found), 3) + + def test_legacy_outputs_without_narrator_ignored(self): + self._touch("dune.mp3") + self._touch("dune_1.5.mp3") + self.assertEqual(find_existing_outputs("dune_Vivian", "mp3"), []) + + +class NarratorTagTests(unittest.TestCase): + def _converter(self, voice_mode, ref_audio=None): + converter = AudiobookConverter.__new__(AudiobookConverter) + converter.voice_mode = voice_mode + converter.voice_clone_ref_audio = ref_audio + return converter + + def test_custom_voice_uses_speaker_display_name(self): + self.assertEqual(self._converter(config.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(), + "Uncle_Fu") + + def test_clone_uses_reference_audio_stem(self): + self.assertEqual(self._converter(config.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(), + "my_voice") + + def test_invalid_characters_sanitized(self): + self.assertEqual(self._converter(config.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(), + "narrator") + class PromptOverwriteTests(unittest.TestCase): def test_single_file_yes(self): @@ -160,22 +204,22 @@ class RunOverwritePromptTests(unittest.TestCase): self._output_tmp.cleanup() def test_declined_book_is_skipped(self): - (config.AUDIOBOOKS_FOLDER / "book.mp3").write_bytes(b"existing") + (config.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.mp3").exists()) + self.assertTrue((config.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").exists()) def test_accepted_book_is_converted(self): - (config.AUDIOBOOKS_FOLDER / "book.mp3").write_bytes(b"existing") + (config.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")]) + self.assertEqual(self.converted, [("book.txt", "book_Vivian")]) def test_new_book_converted_without_prompt(self): with patch("builtins.input", side_effect=AssertionError("should not prompt")): self.assertTrue(self.converter.run()) - self.assertEqual(self.converted, [("book.txt", "book")]) + self.assertEqual(self.converted, [("book.txt", "book_Vivian")]) if __name__ == "__main__": -- cgit v1.2.3