Skip to content

Commit

Permalink
enable pytest . script
Browse files Browse the repository at this point in the history
  • Loading branch information
AHReccese committed Jun 19, 2023
1 parent d689814 commit f46de2f
Show file tree
Hide file tree
Showing 38 changed files with 118 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
pip install --upgrade --upgrade-strategy=only-if-needed -r test-requirements.txt
- name: Test with pytest
run: |
python -m pytest tests/test_linear_models/test_linear_models.py tests/test_exceptions/test_exceptions.py --cov=pymilo --cov-report=term
python -m pytest . --cov=pymilo --cov-report=term
- name: Other tests
run: |
python -m vulture pymilo/ otherfiles/ setup.py --min-confidence 65 --exclude=__init__.py --sort-by-size
Expand Down
31 changes: 12 additions & 19 deletions tests/test_exceptions/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import unittest

from test_export_exceptions import invalid_model, valid_model_invalid_structure
from test_import_exceptions import invalid_json

class TestExceptionalCases(unittest.TestCase):

EXCEPTION_TESTS = {
'IMPORT': [invalid_json],
'EXPORT': [invalid_model, valid_model_invalid_structure]
}

def test_full(self):
for category in self.EXCEPTION_TESTS.keys():
category_all_test_pass = True
for test in self.EXCEPTION_TESTS[category]:
category_all_test_pass = category_all_test_pass and test()
self.assertTrue(category_all_test_pass)
print("Test of Category: " + category + " with granularity of: " + test.__name__ + " executed successfully." )

if __name__ == '__main__':
unittest.main()
EXCEPTION_TESTS = {
'IMPORT': [invalid_json],
'EXPORT': [invalid_model, valid_model_invalid_structure]
}

def test_full():
for category in EXCEPTION_TESTS.keys():
category_all_test_pass = True
for test in EXCEPTION_TESTS[category]:
category_all_test_pass = category_all_test_pass and test()
assert category_all_test_pass == True
print("Test of Category: " + category + " with granularity of: " + test.__name__ + " executed successfully." )
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Automatic-Relevance-Determination-Regression"


def test_ard_regression():
def ard_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create ARD regression object
ard_regression = ARDRegression()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Bayesian-Ridge-Regression"


def test_bayesian_regression():
def bayesian_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create bayesian ridge regression object
bayesian_ridge_regression = BayesianRidge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Elastic-Net-Regression"


def test_elastic_net():
def elastic_net():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Elastic Net regression object
elasticnet_alpha = 0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Elastic-Net-CV-Regression"


def test_elastic_net_cv():
def elastic_net_cv():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Elastic Net CV regression object
elasticnet_alphas = [1e-3, 1e-2, 1e-1, 1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Multi-Task-Elastic-Net-Regression"


def test_multi_task_elastic_net():
def multi_task_elastic_net():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
y_train = [[y, y**2] for y in y_train]
y_test = [[y, y**2] for y in y_test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Multi-Task-Elastic-Net-CV-Regression"


def test_multi_task_elastic_net_cv():
def multi_task_elastic_net_cv():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
y_train = [[y, y**2] for y in y_train]
y_test = [[y, y**2] for y in y_test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Gamma-Regression"


def test_gamma_regression():
def gamma_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Gamma regression object
gamma_alpha = 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Poisson-Regression"


def test_poisson_regression():
def poisson_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Poisson regression object
poisson_alpha = 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Tweedie-Regression"


def test_tweedie_regression():
def tweedie_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Tweedie Regression object
tweedie_alpha = 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Lasso-Regression"


def test_lasso():
def lasso():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Lasso regression object
lasso_alpha = 0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Lasso-Regression-CV"


def test_lasso_cv():
def lasso_cv():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Lasso CV regression object
lasso_alphas = [1e-3, 1e-2, 1e-1, 1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Lasso-Lars-Regression"


def test_lasso_lars():
def lasso_lars():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Lasso Lars regression object
lasso_alpha = 0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Lasso-Lars-CV-Regression"


def test_lasso_lars_cv():
def lasso_lars_cv():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Lasso Lars CV regression object
lasso_cv = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Lasso-Lars-IC-Regression"


def test_lasso_lars_ic():
def lasso_lars_ic():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Lasso Lars IC regression object
lasso_criterian = "bic"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Multi-Task-Lasso-Regression"


def test_multi_task_lasso():
def multi_task_lasso():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
y_train = [[y, y**2] for y in y_train]
y_test = [[y, y**2] for y in y_test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Multi-Task-Lasso-CV-Regression"


def test_multi_task_lasso_cv():
def multi_task_lasso_cv():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
y_train = [[y, y**2] for y in y_train]
y_test = [[y, y**2] for y in y_test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Linear-Regression"


def test_linear_regression():
def linear_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create linear regression object
linear_regression = LinearRegression()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Logistic-Regression"


def test_logistic_regression():
def logistic_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Logistic regression object
logistic_regression_random_state = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Logistic-Regression-CV"


def test_logistic_regression_cv():
def logistic_regression_cv():
x_train, y_train, x_test, y_test = prepare_logistic_regression_datasets()
# Create Logistic regression cv object
logistic_regression_cv = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Orthogonal-Matching-Pursuit-Regression"


def test_omp():
def omp():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Orthogonal Matching Pursuit regression object
omp_n_nonzero_coefs = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Orthogonal-Matching-Pursuit-CV-Regression"


def test_omp_cv():
def omp_cv():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Orthogonal Matching Pursuit CV regression object
omp_cv = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Passive-Aggressive-Classifier"


def test_passive_aggressive_classifier():
def passive_aggressive_classifier():
x_train, y_train, x_test, y_test = prepare_simple_classification_datasets()
# Create ridge regression object
pac_max_iter = 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Passive-Aggressive-Regressor"


def test_passive_agressive_regressor():
def passive_agressive_regressor():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Passive Aggressive Regression object
par_random_state = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Perceptron"


def test_perceptron():
def perceptron():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create perceptron regression object

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Quantile-Regressor"


def test_quantile_regressor():
def quantile_regressor():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Quantile regression object
quantile_regression = QuantileRegressor(quantile=0.8, solver="highs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Ridge-Classifier"


def test_ridge_classifier():
def ridge_classifier():
x_train, y_train, x_test, y_test = prepare_simple_classification_datasets()
# Create ridge classifier object
ridge_alpha = 0.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Ridge-Classifier-CV"


def test_ridge_classifier_cv():
def ridge_classifier_cv():
x_train, y_train, x_test, y_test = prepare_simple_classification_datasets()
# Create ridge classifier cv object
ridge_cv_alphas = [1e-3, 1e-2, 1e-1, 1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
MODEL_NAME = "Ridge-Regression"


def test_ridge_regression():
def ridge_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create ridge regression object
ridge_alpha = 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Ridge-Regression-CV"


def test_ridge_regression_cv():
def ridge_regression_cv():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create ridgeCV regression object
ridge_cv_alphas = [1e-3, 1e-2, 1e-1, 1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Huber-Regressor"


def test_huber_regression():
def huber_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create Huber regression object
huber_regresion = HuberRegressor(max_iter=300)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "RANSAC-Regressor"


def test_ransac_regression():
def ransac_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create ransac regression object
ransac_random_state = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "Theil-Sen-Regressor"


def test_theil_sen_regression():
def theil_sen_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create TheilSen Regression object
theilsen_random_state = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
MODEL_NAME = "SGD-Classifier"


def test_sgd_classifier():
def sgd_classifier():
x_train, y_train, x_test, y_test = prepare_simple_classification_datasets()
# Create SGDClassifier regression object
sgd_max_iter = 100000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "SGD-OneClass-Regression"


def test_sgd_oneclass_svm():
def sgd_oneclass_svm():
x_train, _, x_test, y_test = prepare_simple_regression_datasets()
# Create SGDOneClassSVM regression object
sgd_random_state = 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MODEL_NAME = "SGD-Regression"


def test_sgd_regression():
def sgd_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
# Create SGD Regression object
sgd_max_iter = 100000
Expand Down
Loading

0 comments on commit f46de2f

Please sign in to comment.