Add additional tests

This commit is contained in:
davidmezzetti
2022-02-02 22:13:38 -05:00
parent 52f6cb1657
commit cbba20adb4
4 changed files with 40 additions and 1 deletions
@@ -124,6 +124,14 @@ class TestEmbeddings(unittest.TestCase):
self.assertEqual(self.embeddings.count(), 5)
self.assertEqual(result["text"], self.data[5])
def testEmpty(self):
"""
Test empty index
"""
embeddings = Embeddings({"path": "sentence-transformers/nli-mpnet-base-v2", "content": True})
self.assertEqual(embeddings.search("test"), [])
def testGenerator(self):
"""
Test index with a generator
+8
View File
@@ -65,6 +65,14 @@ class TestEmbeddings(unittest.TestCase):
self.assertEqual(self.embeddings.count(), 5)
self.assertEqual(uid, 5)
def testEmpty(self):
"""
Test empty index
"""
embeddings = Embeddings()
self.assertEqual(embeddings.search("test"), [])
def testExternal(self):
"""
Test embeddings backed by external vectors
+22
View File
@@ -7,6 +7,7 @@ import glob
import io
import os
import tempfile
import sys
import unittest
import numpy as np
@@ -410,6 +411,27 @@ class TestWorkflow(unittest.TestCase):
results = np.array([x.numpy() for x in workflow(torch.tensor([2, 4, 6]))])
self.assertTrue(np.array_equal(np.array(results), np.array([[4, 16, 36], [8, 64, 216]])))
def testYamlFunctionWorkflow(self):
"""
Tests YAML workflow with a function action
"""
# Create function and add to module
def action(elements):
return [x * 2 for x in elements]
sys.modules[__name__].action = action
workflow = """
workflow:
run:
tasks:
- testworkflow.action
"""
app = API(workflow)
self.assertEqual(list(app.workflow("run", [1, 2])), [2, 4])
def testYamlIndexWorkflow(self):
"""
Tests reading a YAML index workflow in Python.