Skip to content

Commit bcb01bf

Browse files
add unit tests for CLI and supervised learning components
1 parent b3daea2 commit bcb01bf

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

tests/test_cli.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from click.testing import CliRunner
3+
from lazypredict import cli
4+
5+
def test_cli_main():
6+
runner = CliRunner()
7+
result = runner.invoke(cli.main)
8+
assert result.exit_code == 0
9+
assert "lazypredict.cli.main" in result.output
10+
11+
def test_cli_help():
12+
runner = CliRunner()
13+
result = runner.invoke(cli.main, ["--help"])
14+
assert result.exit_code == 0
15+
assert "--help Show this message and exit." in result.output

tests/test_helpers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
import pandas as pd
3+
from lazypredict.Supervised import get_card_split
4+
5+
def test_get_card_split():
6+
df = pd.DataFrame({
7+
'A': ['a', 'b', 'c', 'd', 'e'],
8+
'B': ['f', 'g', 'h', 'i', 'j'],
9+
'C': [1, 2, 3, 4, 5]
10+
})
11+
cols = ['A', 'B']
12+
card_low, card_high = get_card_split(df, cols, n=3)
13+
assert len(card_low) == 2
14+
assert len(card_high) == 0

tests/test_init.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import lazypredict
2+
3+
def test_import():
4+
assert lazypredict is not None

tests/test_supervised.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import pytest
2+
import numpy as np
3+
import pandas as pd
4+
from lazypredict.Supervised import LazyClassifier, LazyRegressor
5+
from sklearn.datasets import load_breast_cancer, load_boston
6+
from sklearn.model_selection import train_test_split
7+
from sklearn.utils import shuffle
8+
9+
def test_lazy_classifier_fit():
10+
data = load_breast_cancer()
11+
X = data.data
12+
y = data.target
13+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=123)
14+
clf = LazyClassifier(verbose=0, ignore_warnings=True, custom_metric=None)
15+
models, predictions = clf.fit(X_train, X_test, y_train, y_test)
16+
assert isinstance(models, pd.DataFrame)
17+
assert isinstance(predictions, pd.DataFrame)
18+
19+
def test_lazy_classifier_provide_models():
20+
data = load_breast_cancer()
21+
X = data.data
22+
y = data.target
23+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=123)
24+
clf = LazyClassifier(verbose=0, ignore_warnings=True, custom_metric=None)
25+
clf.fit(X_train, X_test, y_train, y_test)
26+
models = clf.provide_models(X_train, X_test, y_train, y_test)
27+
assert isinstance(models, dict)
28+
29+
def test_lazy_regressor_fit():
30+
boston = load_boston()
31+
X, y = shuffle(boston.data, boston.target, random_state=13)
32+
X = X.astype(np.float32)
33+
offset = int(X.shape[0] * 0.9)
34+
X_train, y_train = X[:offset], y[:offset]
35+
X_test, y_test = X[offset:], y[offset:]
36+
reg = LazyRegressor(verbose=0, ignore_warnings=False, custom_metric=None)
37+
models, predictions = reg.fit(X_train, X_test, y_train, y_test)
38+
assert isinstance(models, pd.DataFrame)
39+
assert isinstance(predictions, pd.DataFrame)
40+
41+
def test_lazy_regressor_provide_models():
42+
boston = load_boston()
43+
X, y = shuffle(boston.data, boston.target, random_state=13)
44+
X = X.astype(np.float32)
45+
offset = int(X.shape[0] * 0.9)
46+
X_train, y_train = X[:offset], y[:offset]
47+
X_test, y_test = X[offset:], y[offset:]
48+
reg = LazyRegressor(verbose=0, ignore_warnings=False, custom_metric=None)
49+
reg.fit(X_train, X_test, y_train, y_test)
50+
models = reg.provide_models(X_train, X_test, y_train, y_test)
51+
assert isinstance(models, dict)

0 commit comments

Comments
 (0)