Skip to content

Commit

Permalink
UT for assign_voices method
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimas committed Dec 21, 2024
1 parent f40f09d commit e7bc7dd
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/text_to_speech_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import tempfile

from typing import Mapping
from typing import List
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -49,7 +49,7 @@ def _convert_text_to_speech(
) -> str:
pass

def get_available_voices(self, language_code: str) -> Mapping[str, str]:
def get_available_voices(self, language_code: str) -> List[Voice]:
pass

def get_languages(self):
Expand Down Expand Up @@ -264,3 +264,31 @@ def test_get_voices_with_region_filter(self):
voices=voices, target_language_region=""
)
assert result[0].region == "US"

def test_assign_voices(self):
tts = TextToSpeechUT()

utterance_metadata = [
{
"assigned_voice": "en_voice",
"speaker_id": 1,
"gender": "Male",
}
]

voices = [
Voice(name="Voice1", gender="Male", region="US"),
Voice(name="Voice2", gender="Female", region="UK"),
Voice(name="Voice3", gender="Male", region="IN"),
Voice(name="Voice4", gender="Female", region="IN"),
]

tts = TextToSpeechUT()

with patch.object(tts, "get_available_voices", return_value=voices):
results = tts.assign_voices(
utterance_metadata=utterance_metadata,
target_language="",
target_language_region="IN",
)
assert {1: "Voice3"} == results

0 comments on commit e7bc7dd

Please sign in to comment.