25 lines
1.3 KiB
Python
25 lines
1.3 KiB
Python
import tempfile,unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from unittest.mock import Mock
|
|
from tts_test import TTSTests
|
|
from tts_runtime import TTSRuntime,REPO,REVISION
|
|
class TTSTestsValidation(unittest.TestCase):
|
|
def test_validation_and_reservation_release(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
t=TTSTests(d,SimpleNamespace(status=lambda:{'profiles':[]}),TTSRuntime(Path(d)/'runtime'));release=Mock();t.acquire=Mock(return_value=release)
|
|
for kwargs in ({'text':''},{'text':'ok','speaker':'unknown'},{'text':'ok','language':'invalid'},{'text':'ok','speed':9}):
|
|
with self.assertRaises(ValueError):t.start('p',**kwargs)
|
|
t.acquire.assert_not_called()
|
|
with self.assertRaises(ValueError):t.start('p','valid')
|
|
release.assert_called_once()
|
|
def test_audio_path_and_model_format(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
r=TTSRuntime(Path(d)/'runtime');t=TTSTests(d,None,r)
|
|
for ident in ('../secret','a'*32):
|
|
with self.assertRaises(ValueError):t.audio(ident)
|
|
self.assertTrue(t.blockers({'model':{'repo':'mlx-community/example','file':'model.safetensors'}}))
|
|
self.assertTrue(t.blockers({'model':{'repo':REPO,'revision':REVISION,'file':'speech_tokenizer/model.safetensors'}}))
|
|
self.assertFalse(r.status()['installed'])
|
|
if __name__=='__main__':unittest.main()
|