mirror of
https://github.com/remsky/Kokoro-FastAPI.git
synced 2025-08-05 16:48:53 +00:00
Update TTS service tests: Enhance test_get_voice_path_combined by mocking os.path.join to ensure correct path generation for combined voices.
This commit is contained in:
parent
888e3121ff
commit
0b2260602a
1 changed files with 5 additions and 1 deletions
|
@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
|
import os
|
||||||
|
|
||||||
from api.src.services.tts_service import TTSService
|
from api.src.services.tts_service import TTSService
|
||||||
|
|
||||||
|
@ -93,17 +94,20 @@ async def test_get_voice_path_combined():
|
||||||
patch("torch.load") as mock_load,
|
patch("torch.load") as mock_load,
|
||||||
patch("torch.save") as mock_save,
|
patch("torch.save") as mock_save,
|
||||||
patch("tempfile.gettempdir") as mock_temp,
|
patch("tempfile.gettempdir") as mock_temp,
|
||||||
|
patch("os.path.join") as mock_join,
|
||||||
):
|
):
|
||||||
mock_get_model.return_value = model_manager
|
mock_get_model.return_value = model_manager
|
||||||
mock_get_voice.return_value = voice_manager
|
mock_get_voice.return_value = voice_manager
|
||||||
mock_temp.return_value = "/tmp"
|
mock_temp.return_value = "/tmp"
|
||||||
|
mock_join.return_value = "/tmp/voice1+voice2.pt"
|
||||||
mock_load.return_value = torch.ones(10)
|
mock_load.return_value = torch.ones(10)
|
||||||
|
|
||||||
service = await TTSService.create("test_output")
|
service = await TTSService.create("test_output")
|
||||||
name, path = await service._get_voices_path("voice1+voice2")
|
name, path = await service._get_voices_path("voice1+voice2")
|
||||||
assert name == "voice1+voice2"
|
assert name == "voice1+voice2"
|
||||||
assert path.endswith("voice1+voice2.pt")
|
assert path == "/tmp/voice1+voice2.pt"
|
||||||
mock_save.assert_called_once()
|
mock_save.assert_called_once()
|
||||||
|
mock_join.assert_called_with("/tmp", "voice1+voice2.pt")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|
Loading…
Add table
Reference in a new issue