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

This commit is contained in:
davidmezzetti
2020-08-21 14:08:33 -04:00
parent da0add2191
commit 5a5247e1d0
7 changed files with 121 additions and 11 deletions
+10 -5
View File
@@ -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
+6 -1
View File
@@ -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}
+2 -2
View File
@@ -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)
+3 -2
View File
@@ -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)
+78
View File
@@ -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
-1
View File
@@ -4,7 +4,6 @@ Tokenizer module tests
import unittest
from txtai.tokenizer import Tokenizer
class TestTokenizer(unittest.TestCase):
+22
View File
@@ -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"))