Coverage for tests/test_wrapper_xtts.py: 100%

37 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-09 04:47 +0000

1#!/usr/bin/env python3 

2 

3import sys 

4import pytest 

5 

6from unittest.mock import patch, MagicMock 

7from tests.torch_mock import TorchMock 

8 

9mock_torch = TorchMock() 

10 

11sys.path.append("wrapper") 

12sys.path.append("wrapper/xtts") 

13 

14mock_modules = { 

15 'nvidia_smi': MagicMock(), 

16 'numpy': MagicMock(), 

17 'TTS': MagicMock(), 

18 'TTS.tts': MagicMock(), 

19 'TTS.tts.configs': MagicMock(), 

20 'TTS.tts.configs.xtts_config': MagicMock(), 

21 'TTS.tts.models': MagicMock(), 

22 'TTS.tts.models.xtts': MagicMock(), 

23 'torch': mock_torch, 

24} 

25mock_modules.update(mock_torch.get_sub_modules()) 

26 

27with patch.dict(sys.modules, mock_modules): 

28 from xtts.wrapper_xtts import XTTSGeneration 

29 

30 

31@pytest.mark.asyncio 

32async def test_xtts_basic() -> None: 

33 model = XTTSGeneration() 

34 assert model is not None 

35 assert model.model_name == "xtts" 

36 assert model.status == "initializing" 

37 

38 

39@pytest.mark.asyncio 

40async def test_xtts_init() -> None: 

41 model = XTTSGeneration() 

42 # init succeeds since all heavy deps are mocked 

43 model.init() 

44 assert model.status == "ok" 

45 

46 

47@pytest.mark.asyncio 

48async def test_xtts_get_rest_args_validation() -> None: 

49 model = XTTSGeneration() 

50 

51 with pytest.raises(ValueError): 

52 await model.get_rest_args(None) 

53 

54 with pytest.raises(ValueError): 

55 await model.get_rest_args({}) 

56 

57 result = await model.get_rest_args({"text": "hello"}) 

58 assert result["task"] == "xtts" 

59 assert result["args"]["text"] == "hello" 

60 

61 

62@pytest.mark.asyncio 

63async def test_xtts_get_health() -> None: 

64 model = XTTSGeneration() 

65 health = model.get_health() 

66 assert isinstance(health, dict)