Skip to content

Commit ae84985

Browse files
committed
reformat; add docstrings; make callables private
1 parent 4a54873 commit ae84985

45 files changed

Lines changed: 302 additions & 72 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test package for Hyperactive library functionality."""

tests/_local_test_timings/_search_space_list.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,6 @@ def func3():
7575
"func1": [func1, func2, func3],
7676
}
7777

78-
class class1:
79-
pass
80-
81-
class class2:
82-
pass
83-
84-
class class3:
85-
pass
86-
87-
def wr_func_1():
88-
return class1
89-
90-
def wr_func_2():
91-
return class2
92-
93-
def wr_func_3():
94-
return class3
95-
96-
search_space_6 = {
97-
"x1": pad_cat,
98-
"class_1": [wr_func_1, wr_func_2, wr_func_3],
99-
}
100-
10178
class class1:
10279
def __init__(self):
10380
pass
@@ -119,6 +96,11 @@ def wr_func_2():
11996
def wr_func_3():
12097
return class3()
12198

99+
search_space_6 = {
100+
"x1": pad_cat,
101+
"class_1": [wr_func_1, wr_func_2, wr_func_3],
102+
}
103+
122104
search_space_7 = {
123105
"x1": pad_cat,
124106
"class_obj_1": [wr_func_1, wr_func_2, wr_func_3],

tests/_local_test_timings/_test_memory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ def objective_function(opt):
5050

5151

5252
def test_memory_timeSave_1():
53-
data = load_breast_cancer()
54-
X, y = data.data, data.target
55-
5653
def objective_function(opt):
5754
time.sleep(0.001)
5855
return 1

tests/_local_test_timings/_test_memory_warm_start_n_jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def test_memory_warm_start_1(search_space):
283283

284284

285285
@pytest.mark.parametrize("search_space", search_space_list)
286-
def test_memory_warm_start_1(search_space):
286+
def test_memory_warm_start_n_jobs(search_space):
287287
n_iter = 1500
288288

289289
c_time = time.perf_counter()

tests/_test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
try:
1919
print("\033[0;33;40m Testing", file_name, end="...\r")
20-
subprocess.check_call(["python", file_path], stdout=DEVNULL, stderr=STDOUT)
20+
subprocess.check_call(["python", file_path], stdout=DEVNULL, stderr=STDOUT) # noqa: S603, S607
2121
except subprocess.CalledProcessError:
2222
print("\033[0;31;40m Error in", file_name)
2323
else:

tests/integrations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test package for integration tests with external libraries."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test package for sklearn integration tests."""

tests/integrations/sklearn/test_parametrize_with_checks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Test module for sklearn parametrize_with_checks integration."""
2+
13
from sklearn import svm
24
from sklearn.model_selection import KFold
35
from sklearn.utils.estimator_checks import parametrize_with_checks
@@ -19,4 +21,5 @@
1921

2022
@parametrize_with_checks(ESTIMATORS)
2123
def test_estimators(estimator, check):
24+
"""Test estimators with sklearn estimator checks."""
2225
check(estimator)

tests/integrations/sklearn/test_sklearn_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Test module for sklearn API integration."""
2+
13
import numpy as np
24
import pytest
35
from sklearn import datasets, svm
@@ -30,13 +32,15 @@
3032

3133

3234
def test_fit():
35+
"""Test fitting the HyperactiveSearchCV estimator."""
3336
search = HyperactiveSearchCV(svc, svc_params, opt)
3437
search.fit(X, y)
3538

3639
check_is_fitted(search)
3740

3841

3942
def test_not_fitted():
43+
"""Test behavior when estimator is not fitted."""
4044
search = HyperactiveSearchCV(svc, svc_params, opt)
4145
assert not search.fit_successful
4246

@@ -47,6 +51,7 @@ def test_not_fitted():
4751

4852

4953
def test_false_params():
54+
"""Test error handling with invalid parameters."""
5055
search = HyperactiveSearchCV(svc, nb_params, opt)
5156
with pytest.raises(ValueError):
5257
search.fit(X, y)
@@ -55,6 +60,7 @@ def test_false_params():
5560

5661

5762
def test_score():
63+
"""Test scoring functionality of the fitted estimator."""
5864
search = HyperactiveSearchCV(svc, svc_params, opt)
5965
search.fit(X, y)
6066
score = search.score(X, y)
@@ -63,13 +69,15 @@ def test_score():
6369

6470

6571
def test_classes_():
72+
"""Test access to fitted classes."""
6673
search = HyperactiveSearchCV(svc, svc_params, opt)
6774
search.fit(X, y)
6875

6976
assert [0, 1, 2] == list(search.classes_)
7077

7178

7279
def test_score_samples():
80+
"""Test score_samples method raises AttributeError."""
7381
search = HyperactiveSearchCV(svc, svc_params, opt)
7482
search.fit(X, y)
7583

@@ -78,6 +86,7 @@ def test_score_samples():
7886

7987

8088
def test_predict():
89+
"""Test prediction functionality."""
8190
search = HyperactiveSearchCV(svc, svc_params, opt)
8291
search.fit(X, y)
8392
result = search.predict(X)
@@ -86,6 +95,7 @@ def test_predict():
8695

8796

8897
def test_predict_proba():
98+
"""Test predict_proba method behavior."""
8999
search = HyperactiveSearchCV(svc, svc_params, opt)
90100
search.fit(X, y)
91101

@@ -100,6 +110,7 @@ def test_predict_proba():
100110

101111

102112
def test_predict_log_proba():
113+
"""Test predict_log_proba method behavior."""
103114
search = HyperactiveSearchCV(svc, svc_params, opt)
104115
search.fit(X, y)
105116

@@ -114,6 +125,7 @@ def test_predict_log_proba():
114125

115126

116127
def test_decision_function():
128+
"""Test decision_function method."""
117129
search = HyperactiveSearchCV(svc, svc_params, opt)
118130
search.fit(X, y)
119131
result = search.decision_function(X)
@@ -122,6 +134,7 @@ def test_decision_function():
122134

123135

124136
def test_transform():
137+
"""Test transform method behavior."""
125138
search = HyperactiveSearchCV(svc, svc_params, opt)
126139
search.fit(X, y)
127140

@@ -136,6 +149,7 @@ def test_transform():
136149

137150

138151
def test_inverse_transform():
152+
"""Test inverse_transform method behavior."""
139153
search = HyperactiveSearchCV(svc, svc_params, opt)
140154
search.fit(X, y)
141155

@@ -150,6 +164,7 @@ def test_inverse_transform():
150164

151165

152166
def test_best_params_and_score():
167+
"""Test access to best parameters and score."""
153168
search = HyperactiveSearchCV(svc, svc_params, opt)
154169
search.fit(X, y)
155170

@@ -161,6 +176,7 @@ def test_best_params_and_score():
161176

162177

163178
def test_search_data():
179+
"""Test access to search data after optimization."""
164180
n_iter = 50
165181
search = HyperactiveSearchCV(svc, svc_params, opt, n_iter=n_iter)
166182
search.fit(X, y)

tests/test_callbacks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Test module for callback functionality."""
2+
13
import numpy as np
24

35
from hyperactive import Hyperactive
@@ -8,6 +10,7 @@
810

911

1012
def test_callback_0():
13+
"""Test callbacks executed before objective function."""
1114
def callback_1(access):
1215
access.stuff1 = 1
1316

@@ -31,6 +34,7 @@ def objective_function(access):
3134

3235

3336
def test_callback_1():
37+
"""Test callbacks executed before and after objective function."""
3438
def callback_1(access):
3539
access.stuff1 = 1
3640

@@ -53,6 +57,7 @@ def objective_function(access):
5357

5458

5559
def test_callback_2():
60+
"""Test callbacks with pass_through parameter."""
5661
def callback_1(access):
5762
access.pass_through["stuff1"] = 1
5863

@@ -73,6 +78,7 @@ def objective_function(access):
7378

7479

7580
def test_callback_3():
81+
"""Test callbacks executed after objective function with pass_through."""
7682
def callback_1(access):
7783
access.pass_through["stuff1"] = 1
7884

0 commit comments

Comments
 (0)