33 lines
2.2 KiB
Python
33 lines
2.2 KiB
Python
import io,json,tempfile,unittest,wave
|
|
from pathlib import Path
|
|
from unittest.mock import Mock,patch
|
|
from profiles import qwen_clone_model
|
|
from tts_runtime import TTSRuntime,REPO,REVISION
|
|
from voxcpm_test import VoxCPMTests
|
|
class QwenCloneTests(unittest.TestCase):
|
|
def model(self):return dict(kind='voice',repo=REPO,revision=REVISION,file='model.safetensors')
|
|
def test_customvoice_and_wrong_revisions_cannot_be_cloned(self):
|
|
self.assertTrue(qwen_clone_model(self.model()))
|
|
for change in ({'kind':'audio'},{'repo':REPO.replace('Base','CustomVoice')},{'revision':'other'}):self.assertFalse(qwen_clone_model(dict(self.model(),**change)))
|
|
def test_existing_weights_are_linked_without_copy_or_download(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
t=TTSRuntime(Path(d)/'tts-runtime');source=t.root.parent/'models'/'source';source.mkdir(parents=True)
|
|
weights=source/'model.safetensors';weights.write_bytes(b'synthetic')
|
|
(source/'entry.json').write_text(json.dumps(dict(kind='audio',repo=REPO,revision=REVISION,file='model.safetensors',sha256='synthetic')))
|
|
with patch.object(t,'ensure_library',return_value='source'):
|
|
ident=t.ensure_voice_library();target=t.root.parent/'models'/ident
|
|
self.assertTrue((target/'model.safetensors').is_symlink());self.assertEqual((target/'model.safetensors').resolve(),weights.resolve())
|
|
self.assertTrue(qwen_clone_model(json.loads((target/'entry.json').read_text())))
|
|
def test_reference_required_before_scheduler_admission(self):
|
|
profiles=Mock();profiles.status.return_value={'profiles':[dict(id='qwen',model=self.model())]}
|
|
t=VoxCPMTests('/tmp/unused-qwen',profiles,Mock());t.acquire=Mock()
|
|
with self.assertRaisesRegex(ValueError,'Referenz'):t.start('qwen','Hallo')
|
|
t.acquire.assert_not_called()
|
|
def test_staging_uses_complete_existing_base_package(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
root=Path(d);model=root/'model';model.mkdir();session=root/'session';session.mkdir()
|
|
t=VoxCPMTests(root,Mock(),Mock());t.qwen_runtime=Mock();t.qwen_runtime.paths.return_value=(root/'python',model)
|
|
t.stage(dict(model=self.model()),session)
|
|
self.assertEqual((session/'model').resolve(),model.resolve())
|
|
if __name__=='__main__':unittest.main()
|