💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Increase test coverage
davidmezzetticbd684969768
diff --git a/test/python/testextractor.py b/test/python/testextractor.pyindex d11890ed..6f81e34f 100644--- a/test/python/testextractor.py+++ b/test/python/testextractor.py@@ -60,6 +60,13 @@ class TestExtractor(unittest.TestCase):answers = self.extractor([(question, question, question, False)], self.data)self.assertEqual("Flyers", answers[0][1])+ def testEmptyQuery(self):+ """+ Tests an empty extractor queries list.+ """++ self.assertEqual(self.extractor.query(None, None), [])+def testNoAnswer(self):"""Test qa extraction with no answer@@ -70,6 +77,10 @@ class TestExtractor(unittest.TestCase):answers = self.extractor([(question, question, question, False)], self.data)self.assertIsNone(answers[0][1])+ question = "abcdef"+ answers = self.extractor([(question, question, question, False)], self.data)+ self.assertIsNone(answers[0][1])+@unittest.skipIf(platform.system() == "Darwin", "Quantized models not supported on macOS")def testQuantize(self):"""diff --git a/test/python/testoptional.py b/test/python/testoptional.pyindex e265833d..426bb592 100644--- a/test/python/testoptional.py+++ b/test/python/testoptional.py@@ -23,6 +23,7 @@ class TestOptional(unittest.TestCase):modules = ["annoy",+ "fastapi","fasttext","hnswlib","nltk",@@ -80,6 +81,14 @@ class TestOptional(unittest.TestCase):with self.assertRaises(ImportError):ANNFactory.create({"backend": "hnsw"})+ def testApi(self):+ """+ Test missing api dependencies+ """++ with self.assertRaises(ImportError):+ import txtai.api+def testModels(self):"""Test missing model dependenciesdiff --git a/test/python/testquantization.py b/test/python/testquantization.pynew file mode 100644index 00000000..7289ee50--- /dev/null+++ b/test/python/testquantization.py@@ -0,0 +1,35 @@+"""+Quantization module tests+"""++import platform+import unittest++from transformers import AutoModel++from txtai.pipeline import HFModel, HFPipeline+++class TestQuantization(unittest.TestCase):+ """+ Quantization tests+ """++ @unittest.skipIf(platform.system() == "Darwin", "Quantized models not supported on macOS")+ def testModel(self):+ """+ Tests quantizing a model through HFModel.+ """++ model = HFModel(quantize=True, gpu=False)+ model = model.prepare(AutoModel.from_pretrained("google/bert_uncased_L-2_H-128_A-2"))+ self.assertIsNotNone(model)++ @unittest.skipIf(platform.system() == "Darwin", "Quantized models not supported on macOS")+ def testPipeline(self):+ """+ Tests quantizing a model through HFPipeline.+ """++ pipeline = HFPipeline("text-classification", "google/bert_uncased_L-2_H-128_A-2", True, False)+ self.assertIsNotNone(pipeline)diff --git a/test/python/testsummary.py b/test/python/testsummary.pyindex 144521c4..b2d08f97 100644--- a/test/python/testsummary.py+++ b/test/python/testsummary.py@@ -36,6 +36,13 @@ class TestSummary(unittest.TestCase):self.assertEqual(self.summary(self.text, minlength=15, maxlength=15), "txtai is an AI-powered search engine that")+ def testSummaryShort(self):+ """+ Test that summarization is skipped+ """++ self.assertEqual(self.summary("Text", maxlength=15), "Text")+def testSummaryBatch(self):"""Test batch summarization of textdiff --git a/test/python/testtranslation.py b/test/python/testtranslation.pyindex 1a0cfc67..f8da8b29 100644--- a/test/python/testtranslation.py+++ b/test/python/testtranslation.py@@ -13,6 +13,19 @@ class TestTranslation(unittest.TestCase):Translation tests"""+ def testLongTranslation(self):+ """+ Tests a translation longer than max tokenization length.+ """++ translate = Translation()++ text = "This is a test translation to Spanish. " * 100+ translation = translate(text, "es")++ # Validate translation text+ self.assertIsNotNone(translation)+@unittest.skipIf(os.name == "nt", "M2M100 skipped on Windows")def testM2M100Translation(self):"""@@ -43,18 +56,21 @@ class TestTranslation(unittest.TestCase):translation = translate(translation, "en")self.assertEqual(translation, text)- def testLongTranslation(self):+ def testNoLang(self):"""- Tests a translation longer than max tokenization length.+ Test no matching language id."""translate = Translation()+ self.assertIsNone(translate.langid([], "zz"))- text = "This is a test translation to Spanish. " * 100- translation = translate(text, "es")+ def testNoModel(self):+ """+ Tests no known available model found.+ """- # Validate translation text- self.assertIsNotNone(translation)+ translate = Translation()+ self.assertEqual(translate.modelpath("zz", "en"), "Helsinki-NLP/opus-mt-mul-en")def testNoTranslation(self):"""