1
0
Fork 0

Added first tests

This commit is contained in:
Andrea Esuli 2021-04-29 16:07:39 +02:00
parent 3d544135f1
commit d86c402916
4 changed files with 52 additions and 0 deletions

0
quapy/tests/__init__.py Normal file
View File

5
quapy/tests/test_base.py Normal file
View File

@ -0,0 +1,5 @@
import pytest
def test_import():
import quapy as qp
assert qp.__version__ is not None

View File

@ -0,0 +1,18 @@
import pytest
from quapy.data.datasets import REVIEWS_SENTIMENT_DATASETS, TWITTER_SENTIMENT_DATASETS_TEST, \
TWITTER_SENTIMENT_DATASETS_TRAIN, UCI_DATASETS, fetch_reviews, fetch_twitter, fetch_UCIDataset
@pytest.mark.parametrize('dataset_name', REVIEWS_SENTIMENT_DATASETS)
def test_fetch_reviews(dataset_name):
fetch_reviews(dataset_name)
@pytest.mark.parametrize('dataset_name', TWITTER_SENTIMENT_DATASETS_TEST + TWITTER_SENTIMENT_DATASETS_TRAIN)
def test_fetch_twitter(dataset_name):
fetch_twitter(dataset_name)
@pytest.mark.parametrize('dataset_name', UCI_DATASETS)
def test_fetch_UCIDataset(dataset_name):
fetch_UCIDataset(dataset_name)

View File

@ -0,0 +1,29 @@
import numpy
import pytest
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import MultinomialNB
from sklearn.svm import LinearSVC
import quapy as qp
datasets = [qp.datasets.fetch_twitter('semeval16')]
aggregative_methods = [qp.method.aggregative.CC, qp.method.aggregative.ACC, qp.method.aggregative.ELM]
learners = [LogisticRegression, MultinomialNB, LinearSVC]
@pytest.mark.parametrize('dataset', datasets)
@pytest.mark.parametrize('aggregative_method', aggregative_methods)
@pytest.mark.parametrize('learner', learners)
def test_aggregative_methods(dataset, aggregative_method, learner):
model = aggregative_method(learner())
model.fit(dataset.training)
estim_prevalences = model.quantify(dataset.test.instances)
true_prevalences = dataset.test.prevalence()
error = qp.error.mae(true_prevalences, estim_prevalences)
assert type(error) == numpy.float64