Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Update tests

davidmezzetti7ec9ff335a88
diff --git a/test/python/testpipeline/testtranscription.py b/test/python/testpipeline/testtranscription.py
index 871b28d6..11c38d1a 100644
--- a/test/python/testpipeline/testtranscription.py
+++ b/test/python/testpipeline/testtranscription.py
@@ -2,6 +2,7 @@
Transcription module tests
"""
+import os
import unittest
import numpy as np
@@ -15,36 +16,33 @@ from txtai.pipeline import Transcription
from utils import Utils
[email protected](os.name == "nt", "Transcription tests skipped on Windows")
class TestTranscription(unittest.TestCase):
"""
Transcription tests.
"""
- @classmethod
- def setUpClass(cls):
- """
- Create single transcription instance.
- """
-
- cls.transcribe = Transcription()
-
def testArray(self):
"""
Test audio data to text transcription
"""
+ transcribe = Transcription()
+
# Read audio data
raw, samplerate = sf.read(Utils.PATH + "/Make_huge_profits.wav")
- self.assertEqual(self.transcribe((raw, samplerate)), "Make huge profits without working make up to one hundred thousand dollars a day")
- self.assertEqual(self.transcribe(raw, samplerate), "Make huge profits without working make up to one hundred thousand dollars a day")
+ self.assertEqual(transcribe((raw, samplerate)), "Make huge profits without working make up to one hundred thousand dollars a day")
+ self.assertEqual(transcribe(raw, samplerate), "Make huge profits without working make up to one hundred thousand dollars a day")
def testChunks(self):
"""
Test splitting transcription into chunks
"""
- result = self.transcribe(Utils.PATH + "/Make_huge_profits.wav", join=False)[0]
+ transcribe = Transcription()
+
+ result = transcribe(Utils.PATH + "/Make_huge_profits.wav", join=False)[0]
self.assertIsInstance(result["raw"], np.ndarray)
self.assertIsNotNone(result["rate"])
@@ -55,8 +53,10 @@ class TestTranscription(unittest.TestCase):
Test audio file to text transcription
"""
+ transcribe = Transcription()
+
self.assertEqual(
- self.transcribe(Utils.PATH + "/Make_huge_profits.wav"), "Make huge profits without working make up to one hundred thousand dollars a day"
+ transcribe(Utils.PATH + "/Make_huge_profits.wav"), "Make huge profits without working make up to one hundred thousand dollars a day"
)
def testResample(self):
@@ -64,6 +64,8 @@ class TestTranscription(unittest.TestCase):
Test resampled audio file to text transcription
"""
+ transcribe = Transcription()
+
# Read audio data
raw, samplerate = sf.read(Utils.PATH + "/Make_huge_profits.wav")
@@ -71,17 +73,19 @@ class TestTranscription(unittest.TestCase):
samples = round(len(raw) * float(22050) / samplerate)
raw, samplerate = signal.resample(raw, samples), 22050
- self.assertEqual(self.transcribe(raw, samplerate), "Make huge profits without working make up to one hundred thousand dollars a day")
+ self.assertEqual(transcribe(raw, samplerate), "Make huge profits without working make up to one hundred thousand dollars a day")
def testStereo(self):
"""
Test audio file in stereo to text transcription
"""
+ transcribe = Transcription()
+
# Read audio data
raw, samplerate = sf.read(Utils.PATH + "/Make_huge_profits.wav")
# Convert mono to stereo
raw = np.column_stack((raw, raw))
- self.assertEqual(self.transcribe(raw, samplerate), "Make huge profits without working make up to one hundred thousand dollars a day")
+ self.assertEqual(transcribe(raw, samplerate), "Make huge profits without working make up to one hundred thousand dollars a day")
diff --git a/test/python/testpipeline/testtranslation.py b/test/python/testpipeline/testtranslation.py
index 67e6602e..37643a1a 100644
--- a/test/python/testpipeline/testtranslation.py
+++ b/test/python/testpipeline/testtranslation.py
@@ -8,26 +8,20 @@ import unittest
from txtai.pipeline import Translation
[email protected](os.name == "nt", "Translation tests skipped on Windows")
class TestTranslation(unittest.TestCase):
"""
Translation tests.
"""
- @classmethod
- def setUpClass(cls):
- """
- Create single translation instance.
- """
-
- cls.translate = Translation()
-
def testDetect(self):
"""
Test language detection
"""
+ translate = Translation()
test = ["This is a test language detection."]
- language = self.translate.detect(test)
+ language = translate.detect(test)
self.assertListEqual(language, ["en"])
@@ -46,14 +40,15 @@ class TestTranslation(unittest.TestCase):
self.assertListEqual(language, ["en"])
- @unittest.skipIf(os.name == "nt", "testLongTranslation skipped on Windows")
def testLongTranslation(self):
"""
Test a translation longer than max tokenization length
"""
+ translate = Translation()
+
text = "This is a test translation to Spanish. " * 100
- translation = self.translate(text, "es")
+ translation = translate(text, "es")
# Validate translation text
self.assertIsNotNone(translation)
@@ -64,25 +59,28 @@ class TestTranslation(unittest.TestCase):
Test a translation using M2M100 models
"""
- text = self.translate("This is a test translation to Croatian", "hr")
+ translate = Translation()
+
+ text = translate("This is a test translation to Croatian", "hr")
# Validate translation text
self.assertEqual(text, "Ovo je testni prijevod na hrvatski")
- @unittest.skipIf(os.name == "nt", "testMarianTranslation skipped on Windows")
def testMarianTranslation(self):
"""
Test a translation using Marian models
"""
+ translate = Translation()
+
text = "This is a test translation into Spanish"
- translation = self.translate(text, "es")
+ translation = translate(text, "es")
# Validate translation text
self.assertEqual(translation, "Esta es una traducción de prueba al español")
# Validate translation back
- translation = self.translate(translation, "en")
+ translation = translate(translation, "en")
self.assertEqual(translation, text)
def testNoLang(self):
@@ -90,35 +88,40 @@ class TestTranslation(unittest.TestCase):
Test no matching language id
"""
- self.assertIsNone(self.translate.langid([], "zz"))
+ translate = Translation()
+ self.assertIsNone(translate.langid([], "zz"))
def testNoModel(self):
"""
Test no known available model found
"""
- self.assertEqual(self.translate.modelpath("zz", "en"), "Helsinki-NLP/opus-mt-mul-en")
+ translate = Translation()
+ self.assertEqual(translate.modelpath("zz", "en"), "Helsinki-NLP/opus-mt-mul-en")
def testNoTranslation(self):
"""
Test translation skipped when text already in destination language
"""
+ translate = Translation()
+
text = "This is a test translation to English"
- translation = self.translate(text, "en")
+ translation = translate(text, "en")
# Validate no translation
self.assertEqual(text, translation)
- @unittest.skipIf(os.name == "nt", "testTranslationWithShowModels skipped on Windows")
def testTranslationWithShowmodels(self):
"""
Test a translation using Marian models and showmodels flag to return
model and language.
"""
+ translate = Translation()
+
text = "This is a test translation into Spanish"
- result = self.translate(text, "es", showmodels=True)
+ result = translate(text, "es", showmodels=True)
translation, language, modelpath = result
# Validate translation text
@@ -129,7 +132,7 @@ class TestTranslation(unittest.TestCase):
self.assertEqual(modelpath, "Helsinki-NLP/opus-mt-en-es")
# Validate translation back
- result = self.translate(translation, "en", showmodels=True)
+ result = translate(translation, "en", showmodels=True)
translation, language, modelpath = result
self.assertEqual(translation, text)