29 lines
1.4 KiB
Python
29 lines
1.4 KiB
Python
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from unittest.mock import Mock
|
|
from embeddings import Embeddings,REPO,FILE,supported
|
|
from profiles import Profiles
|
|
from execution_setup import assess
|
|
|
|
class EmbeddingTests(unittest.TestCase):
|
|
def test_recipe_is_exact_and_does_not_invent_components(self):
|
|
model=dict(kind='embeddings',repo=REPO,file=FILE,id='a'*64)
|
|
self.assertTrue(supported(model));self.assertFalse(supported(dict(model,file='other.gguf')))
|
|
with tempfile.TemporaryDirectory() as d:
|
|
catalog=Mock();catalog.entry.return_value=model
|
|
p=Profiles(Path(d)/'profiles.json',catalog)
|
|
p.embedding_blockers=lambda _:[]
|
|
result=p.components(model['id'])
|
|
self.assertTrue(result['no_components']);self.assertEqual(result['requirements'],[])
|
|
self.assertTrue(result['runtime_installed']);catalog.files.assert_not_called()
|
|
result=assess(model,{'embeddings':True},dict(runnable=True,blockers=[]))
|
|
self.assertEqual(result['state'],'ready');self.assertEqual(result['components'],[])
|
|
def test_runtime_failure_is_actionable(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
worker=Mock();worker.build.side_effect=ValueError('Build fehlt')
|
|
e=Embeddings(d,Mock(),worker)
|
|
self.assertEqual(e.blockers({'model':dict(kind='embeddings',repo=REPO,file=FILE)}),['Build fehlt'])
|
|
self.assertTrue(e.blockers({'model':dict(kind='embeddings',repo='unknown/model',file='model.gguf')}))
|