Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Updated Travis build with calls to coveralls. Added more tests.

davidmezzetti5a5247e1d0f0
diff --git a/.travis.yml b/.travis.yml
index c3373417..c6deb81e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,9 @@
# Travis CI build script - test on all supported platforms
+os: linux
+language: python
matrix:
include:
- name: "Linux"
- os: linux
- language: python
- name: "macOS"
os: osx
osx_image: xcode11.4
@@ -17,16 +17,21 @@ matrix:
- name: "Windows"
os: windows
language: shell
+ env: PATH=/c/Python36:/c/Python36/Scripts:$PATH
before_install:
- choco install make
- choco install python --version 3.6.8
- python --version
- python -m pip install --upgrade pip wheel
- python -m pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
- env: PATH=/c/Python36:/c/Python36/Scripts:$PATH
+ script:
+ - pip install .
+ - make test
before_install:
- - pip install -U pip
+ - pip install -U pip coverage coveralls
- python --version
script:
- pip install .
- - make test
+ - make coverage
+after_success:
+ - coveralls
diff --git a/Makefile b/Makefile
index cef6045b..7047e83c 100644
--- a/Makefile
+++ b/Makefile
@@ -6,10 +6,15 @@ export SRC_DIR := ./src/python
export TEST_DIR := ./test/python
export PYTHONPATH := ${SRC_DIR}:${TEST_DIR}:${PYTHONPATH}
export PATH := ${TEST_DIR}:${PATH}
+export PYTHONWARNINGS := ignore
# Default python executable if not provided
PYTHON ?= python
# Unit tests
test:
- ${PYTHON} -W ignore::DeprecationWarning -m unittest discover -v -s ${TEST_DIR}
+ ${PYTHON} -m unittest discover -v -s ${TEST_DIR}
+
+# Run tests while calculating code coverage
+coverage:
+ coverage run --source=${SRC_DIR} -m unittest discover -v -s ${TEST_DIR}
diff --git a/test/python/testann.py b/test/python/testann.py
index b55e2603..3ba08d6d 100644
--- a/test/python/testann.py
+++ b/test/python/testann.py
@@ -43,8 +43,8 @@ class TestANN(unittest.TestCase):
Tests ANN save/load.
"""
- with tempfile.NamedTemporaryFile(mode="wb") as output:
- index = output.name
+ # Generate temp file path
+ index = os.path.join(tempfile.gettempdir(), "ann")
model = self.backend("annoy")
model.save(index)
diff --git a/test/python/testembeddings.py b/test/python/testembeddings.py
index 54eb380a..2fb1f32c 100644
--- a/test/python/testembeddings.py
+++ b/test/python/testembeddings.py
@@ -2,6 +2,7 @@
Embeddings module tests
"""
+import os
import tempfile
import unittest
@@ -51,8 +52,8 @@ class TestEmbeddings(unittest.TestCase):
# Create an index for the list of sections
self.embeddings.index([(uid, text, None) for uid, text in enumerate(self.data)])
- with tempfile.NamedTemporaryFile(mode="wb") as output:
- index = output.name
+ # Generate temp file path
+ index = os.path.join(tempfile.gettempdir(), "embeddings")
self.embeddings.save(index)
self.embeddings.load(index)
diff --git a/test/python/testscoring.py b/test/python/testscoring.py
new file mode 100644
index 00000000..cb0f6a28
--- /dev/null
+++ b/test/python/testscoring.py
@@ -0,0 +1,78 @@
+"""
+Scoring module tests
+"""
+
+import os
+import tempfile
+import unittest
+
+from txtai.scoring import Scoring
+
+class TestScoring(unittest.TestCase):
+ """
+ Scoring tests.
+ """
+
+ def setUp(self):
+ """
+ Initialize test data.
+ """
+
+ self.data = ["US tops 5 million confirmed virus cases",
+ "Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
+ "Beijing mobilises invasion craft along coast as Taiwan tensions escalate",
+ "The National Park Service warns against sacrificing slower friends in a bear attack",
+ "Maine man wins $1M from $25 lottery ticket",
+ "wins wins wins",
+ "Make huge profits without work, earn up to $100,000 a day"]
+
+ self.data = [(uid, x, None) for uid, x in enumerate(self.data)]
+
+ def testBM25(self):
+ """
+ Test BM25
+ """
+
+ self.method("bm25")
+
+ def testSIF(self):
+ """
+ Test SIF
+ """
+
+ self.method("sif")
+
+ def testTFIDF(self):
+ """
+ Test tfidf
+ """
+
+ self.method("tfidf")
+
+ def testSave(self):
+ """
+ Test scoring index save/load
+ """
+
+ # Generate temp file path
+ index = os.path.join(tempfile.gettempdir(), "bm25")
+ os.makedirs(index)
+
+ model = self.method("bm25")
+ model.save(index)
+ model.load(index)
+
+ def method(self, method):
+ """
+ Runs scoring method
+ """
+
+ model = Scoring.create(method)
+ model.index(self.data)
+
+ keys = [k for k, v in sorted(model.idf.items(), key=lambda x: x[1])]
+
+ # Win should be lowest score for all models
+ self.assertEqual(keys[0], "wins")
+
+ return model
diff --git a/test/python/testtokenizer.py b/test/python/testtokenizer.py
index 82a509bd..97cc3b9e 100644
--- a/test/python/testtokenizer.py
+++ b/test/python/testtokenizer.py
@@ -4,7 +4,6 @@ Tokenizer module tests
import unittest
-
from txtai.tokenizer import Tokenizer
class TestTokenizer(unittest.TestCase):
diff --git a/test/python/testvectors.py b/test/python/testvectors.py
new file mode 100644
index 00000000..2e4562b9
--- /dev/null
+++ b/test/python/testvectors.py
@@ -0,0 +1,22 @@
+"""
+Vectors module tests
+"""
+
+import os
+import tempfile
+import unittest
+
+from txtai.vectors import WordVectors
+
+class TestVectors(unittest.TestCase):
+ """
+ Vectors tests
+ """
+
+ def testBuild(self):
+ """
+ Test a WordVectors build.
+ """
+
+ # Build word vectors on README file
+ WordVectors.build("README.md", 300, 3, os.path.join(tempfile.gettempdir(), "vectors"))