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:
Lukin 2025-06-01 10:28:35 +08:00
parent 888e3121ff
commit 0b2260602a

View file

@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import numpy as np
import pytest
import torch
import os
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.save") as mock_save,
patch("tempfile.gettempdir") as mock_temp,
patch("os.path.join") as mock_join,
):
mock_get_model.return_value = model_manager
mock_get_voice.return_value = voice_manager
mock_temp.return_value = "/tmp"
mock_join.return_value = "/tmp/voice1+voice2.pt"
mock_load.return_value = torch.ones(10)
service = await TTSService.create("test_output")
name, path = await service._get_voices_path("voice1+voice2")
assert name == "voice1+voice2"
assert path.endswith("voice1+voice2.pt")
assert path == "/tmp/voice1+voice2.pt"
mock_save.assert_called_once()
mock_join.assert_called_with("/tmp", "voice1+voice2.pt")
@pytest.mark.asyncio