scikit-base 0.4.6__py3-none-any.whl → 0.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/source/conf.py +299 -299
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/LICENSE +29 -29
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/METADATA +160 -159
- scikit_base-0.5.1.dist-info/RECORD +58 -0
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/WHEEL +1 -1
- scikit_base-0.5.1.dist-info/top_level.txt +5 -0
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/zip-safe +1 -1
- skbase/__init__.py +14 -14
- skbase/_exceptions.py +31 -31
- skbase/_nopytest_tests.py +35 -35
- skbase/base/__init__.py +20 -20
- skbase/base/_base.py +1249 -1249
- skbase/base/_meta.py +883 -871
- skbase/base/_pretty_printing/__init__.py +11 -11
- skbase/base/_pretty_printing/_object_html_repr.py +392 -392
- skbase/base/_pretty_printing/_pprint.py +412 -412
- skbase/base/_tagmanager.py +217 -217
- skbase/lookup/__init__.py +31 -31
- skbase/lookup/_lookup.py +1009 -1009
- skbase/lookup/tests/__init__.py +2 -2
- skbase/lookup/tests/test_lookup.py +991 -991
- skbase/testing/__init__.py +12 -12
- skbase/testing/test_all_objects.py +852 -856
- skbase/testing/utils/__init__.py +5 -5
- skbase/testing/utils/_conditional_fixtures.py +209 -209
- skbase/testing/utils/_dependencies.py +15 -15
- skbase/testing/utils/deep_equals.py +15 -15
- skbase/testing/utils/inspect.py +30 -30
- skbase/testing/utils/tests/__init__.py +2 -2
- skbase/testing/utils/tests/test_check_dependencies.py +49 -49
- skbase/testing/utils/tests/test_deep_equals.py +66 -66
- skbase/tests/__init__.py +2 -2
- skbase/tests/conftest.py +273 -273
- skbase/tests/mock_package/__init__.py +5 -5
- skbase/tests/mock_package/test_mock_package.py +74 -74
- skbase/tests/test_base.py +1202 -1202
- skbase/tests/test_baseestimator.py +130 -130
- skbase/tests/test_exceptions.py +23 -23
- skbase/tests/test_meta.py +170 -131
- skbase/utils/__init__.py +21 -21
- skbase/utils/_check.py +53 -53
- skbase/utils/_iter.py +238 -238
- skbase/utils/_nested_iter.py +180 -180
- skbase/utils/_utils.py +91 -91
- skbase/utils/deep_equals.py +358 -358
- skbase/utils/dependencies/__init__.py +11 -11
- skbase/utils/dependencies/_dependencies.py +253 -253
- skbase/utils/tests/__init__.py +4 -4
- skbase/utils/tests/test_check.py +24 -24
- skbase/utils/tests/test_iter.py +127 -127
- skbase/utils/tests/test_nested_iter.py +84 -84
- skbase/utils/tests/test_utils.py +37 -37
- skbase/validate/__init__.py +22 -22
- skbase/validate/_named_objects.py +403 -403
- skbase/validate/_types.py +345 -345
- skbase/validate/tests/__init__.py +2 -2
- skbase/validate/tests/test_iterable_named_objects.py +200 -200
- skbase/validate/tests/test_type_validations.py +370 -370
- scikit_base-0.4.6.dist-info/RECORD +0 -58
- scikit_base-0.4.6.dist-info/top_level.txt +0 -2
skbase/testing/utils/__init__.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""Utilities for the test framework."""
|
3
|
-
from typing import List
|
4
|
-
|
5
|
-
__all__: List[str] = []
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Utilities for the test framework."""
|
3
|
+
from typing import List
|
4
|
+
|
5
|
+
__all__: List[str] = []
|
@@ -1,209 +1,209 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""Testing utility for easy generation of conditional fixtures in pytest_generate_tests.
|
3
|
-
|
4
|
-
Exports create_conditional_fixtures_and_names utility
|
5
|
-
"""
|
6
|
-
from copy import deepcopy
|
7
|
-
from typing import Callable, Dict, List
|
8
|
-
|
9
|
-
from skbase._exceptions import FixtureGenerationError
|
10
|
-
from skbase.utils._nested_iter import _remove_single
|
11
|
-
from skbase.validate import check_sequence
|
12
|
-
|
13
|
-
__author__: List[str] = ["fkiraly"]
|
14
|
-
__all__: List[str] = ["create_conditional_fixtures_and_names"]
|
15
|
-
|
16
|
-
|
17
|
-
def create_conditional_fixtures_and_names(
|
18
|
-
test_name: str,
|
19
|
-
fixture_vars: List[str],
|
20
|
-
generator_dict: Dict[str, Callable],
|
21
|
-
fixture_sequence: List[str] = None,
|
22
|
-
raise_exceptions: bool = False,
|
23
|
-
deepcopy_fixtures: bool = False,
|
24
|
-
):
|
25
|
-
"""Create conditional fixtures for pytest_generate_tests.
|
26
|
-
|
27
|
-
Creates arguments for pytest.fixture.parameterize,
|
28
|
-
using conditional fixture generation functions in generator_dict.
|
29
|
-
|
30
|
-
Example: we want to loop over two fixture variables, "number" and "multiples"
|
31
|
-
"number" are integers from 1 to 10,
|
32
|
-
"multiples" are multiples of "number" up to "number"-squared
|
33
|
-
we then write a generator_dict with two entries
|
34
|
-
generator_dict["number"] is a function (test_name, **kwargs) -> list
|
35
|
-
that returns [1, 2, ..., 10]
|
36
|
-
generator_dict["multiples"] is a function (test_name, number, **kwargs) -> list
|
37
|
-
that returns [number, 2* number, ..., number*number]
|
38
|
-
|
39
|
-
This function automatically creates the inputs for pytest.mark.parameterize
|
40
|
-
fixture_param_str = "number,multiples"
|
41
|
-
fixture_prod = [(1, 1), (2, 2), (2, 4), (3, 3), (3, 6), ...]
|
42
|
-
fixture_names = ["1-1", "2-2", "2-4", "3-3", "3-6", ...]
|
43
|
-
|
44
|
-
Parameters
|
45
|
-
----------
|
46
|
-
test_name : str, name of the test, from pytest_generate_tests
|
47
|
-
fixture_vars : list of str
|
48
|
-
fixture variable names used in parameterization of tests
|
49
|
-
generator_dict : dict of generator functions
|
50
|
-
keys are possible str in fixture_vars, expected signature is
|
51
|
-
(test_name: str, **kwargs) -> fixtures: Listof[object], or
|
52
|
-
(returning only fixtures)
|
53
|
-
(test_name: str, **kwargs) -> fixtures, fixture_names: Listof[object]
|
54
|
-
(returning fixture names as well as fixtures)
|
55
|
-
generator_dict[my_variable] can take arguments with names
|
56
|
-
in fixture_sequence to the left of my_variable
|
57
|
-
it should return a list of fixtures for my_variable
|
58
|
-
under the assumption that arguments have given values
|
59
|
-
fixture_sequence : list of str, optional, default = None
|
60
|
-
used in prioritizing conditional generators, sequentially (see above)
|
61
|
-
raise_exceptions : bool, optional, default = False
|
62
|
-
whether fixture generation errors or other Exceptions are raised
|
63
|
-
if False, exceptions are returned instead of fixtures
|
64
|
-
deepcopy_fixtures : bool. optional, default = False
|
65
|
-
whether returned fixture list in fixture_prod are deecopy-independent
|
66
|
-
if False, identical list/tuple elements will be identical by reference
|
67
|
-
if True, identical elements will be identical by value but no by reference
|
68
|
-
"elements" refer to fixture[i] as described below, in fixture_prod
|
69
|
-
|
70
|
-
Returns
|
71
|
-
-------
|
72
|
-
fixture_param_str : str, string to use in pytest.fixture.parameterize
|
73
|
-
this is strings in "fixture_vars" concatenated, separated by ","
|
74
|
-
fixture_prod : list of tuples, fixtures to use in pytest.fixture.parameterize
|
75
|
-
fixture tuples, generated according to the following conditional rule:
|
76
|
-
let fixture_vars = [fixture_var1, fixture_var2, ..., fixture_varN]
|
77
|
-
all fixtures are obtained as following:
|
78
|
-
for i in 1 to N
|
79
|
-
pick fixture[i] any element of generator_dict[fixture_vari](
|
80
|
-
test_name,
|
81
|
-
fixture_var1 = fixture[1], ...,
|
82
|
-
fixture_var(i-1) = fixture[i-1],
|
83
|
-
)
|
84
|
-
return (fixture[1], fixture[2], ..., fixture[N])
|
85
|
-
if deepcopy_fixtures = False, identical fixture[i] are identical by reference
|
86
|
-
if deepcopy_fixtures = True, identical fixture[i] are not identical references
|
87
|
-
fixture_names : list of str, fixture ids to use in pytest.fixture.parameterize
|
88
|
-
fixture names, generated according to the following conditional rule:
|
89
|
-
let fixture_vars = [fixture_var1, fixture_var2, ..., fixture_varN]
|
90
|
-
all fixtures names are obtained as following:
|
91
|
-
for i in 1 to N
|
92
|
-
pick fixture_str_pt[i] any element of generator_dict[fixture_vari](
|
93
|
-
test_name,
|
94
|
-
fixture_var1 = fixture[1], ...,
|
95
|
-
fixture_var(i-1) = fixture[i-1],
|
96
|
-
), second return is exists; otherwise str(first return)
|
97
|
-
return "fixture_str_pt[1]-fixture_str_pt[2]-...-fixture_str_pt[N]"
|
98
|
-
fixture names correspond to fixtures with the same indices at picks (from lists)
|
99
|
-
"""
|
100
|
-
fixture_vars = check_sequence(
|
101
|
-
fixture_vars, sequence_type=list, element_type=str, sequence_name="fixture_vars"
|
102
|
-
)
|
103
|
-
fixture_vars = [var for var in fixture_vars if var in generator_dict.keys()]
|
104
|
-
|
105
|
-
# order fixture_vars according to fixture_sequence if provided
|
106
|
-
if fixture_sequence is not None:
|
107
|
-
fixture_sequence = check_sequence(
|
108
|
-
fixture_sequence,
|
109
|
-
sequence_type=list,
|
110
|
-
element_type=str,
|
111
|
-
sequence_name="fixture_sequence",
|
112
|
-
)
|
113
|
-
ordered_fixture_vars = []
|
114
|
-
for fixture_var_name in fixture_sequence:
|
115
|
-
if fixture_var_name in fixture_vars:
|
116
|
-
ordered_fixture_vars += [fixture_var_name]
|
117
|
-
fixture_vars = ordered_fixture_vars
|
118
|
-
|
119
|
-
def get_fixtures(fixture_var, **kwargs):
|
120
|
-
"""Call fixture generator from generator_dict, return fixture list.
|
121
|
-
|
122
|
-
Light wrapper around calls to generator_dict[key] functions that generate
|
123
|
-
conditional fixtures. get_fixtures adds default string names to the return
|
124
|
-
if generator_dict[key] does not return them.
|
125
|
-
|
126
|
-
Parameters
|
127
|
-
----------
|
128
|
-
fixture_var : str, name of fixture variable
|
129
|
-
kwargs : key-value pairs, keys = names of previous fixture variables
|
130
|
-
test_name : str, from local scope
|
131
|
-
name of test for which fixtures are generated
|
132
|
-
|
133
|
-
Returns
|
134
|
-
-------
|
135
|
-
fixture_prod : list of objects or one-element list with FixtureGenerationError
|
136
|
-
fixtures for fixture_var for test_name, conditional on fixtures in kwargs
|
137
|
-
if call to generator_dict[fixture_var] fails, returns list with error
|
138
|
-
fixture_names : list of string, same length as fixture_prod
|
139
|
-
i-th element is a string name for i-th element of fixture_prod
|
140
|
-
if 2nd arg is returned by generator_dict, then 1:1 copy of that argument
|
141
|
-
if no 2nd arg is returned by generator_dict, then str(fixture_prod[i])
|
142
|
-
if fixture_prod is list with error, then string is Error:fixture_var
|
143
|
-
"""
|
144
|
-
try:
|
145
|
-
res = generator_dict[fixture_var](test_name, **kwargs)
|
146
|
-
if isinstance(res, tuple) and len(res) == 2:
|
147
|
-
fixture_prod = res[0]
|
148
|
-
fixture_names = res[1]
|
149
|
-
else:
|
150
|
-
fixture_prod = res
|
151
|
-
fixture_names = [str(x) for x in res]
|
152
|
-
except Exception as err:
|
153
|
-
error = FixtureGenerationError(fixture_name=fixture_var, err=err)
|
154
|
-
if raise_exceptions:
|
155
|
-
raise error
|
156
|
-
fixture_prod = [error]
|
157
|
-
fixture_names = [f"Error:{fixture_var}"]
|
158
|
-
|
159
|
-
return fixture_prod, fixture_names
|
160
|
-
|
161
|
-
fixture_prod = [()]
|
162
|
-
fixture_names = [""]
|
163
|
-
|
164
|
-
# we loop over fixture_vars, incrementally going through conditionals
|
165
|
-
for i, fixture_var in enumerate(fixture_vars):
|
166
|
-
old_fixture_vars = fixture_vars[0:i]
|
167
|
-
|
168
|
-
# then take successive left products
|
169
|
-
new_fixture_prod = []
|
170
|
-
new_fixture_names = []
|
171
|
-
|
172
|
-
for j, fixture in enumerate(fixture_prod):
|
173
|
-
# retrieve kwargs corresponding to old fixture values
|
174
|
-
fixture_name = fixture_names[j]
|
175
|
-
if i == 0:
|
176
|
-
kwargs = {}
|
177
|
-
else:
|
178
|
-
kwargs = dict(zip(old_fixture_vars, fixture))
|
179
|
-
# retrieve conditional fixtures, conditional on fixture values in kwargs
|
180
|
-
new_fixtures, new_fixture_names_r = get_fixtures(fixture_var, **kwargs)
|
181
|
-
# new fixture values are concatenation/product of old values plus new
|
182
|
-
new_fixture_prod += [
|
183
|
-
fixture + (new_fixture,) for new_fixture in new_fixtures
|
184
|
-
]
|
185
|
-
# new fixture name is concatenation of name so far and "dash-new name"
|
186
|
-
# if the new name is empty string, don't add a dash
|
187
|
-
if len(new_fixture_names_r) > 0 and new_fixture_names_r[0] != "":
|
188
|
-
new_fixture_names_r = [f"-{x}" for x in new_fixture_names_r]
|
189
|
-
new_fixture_names += [f"{fixture_name}{x}" for x in new_fixture_names_r]
|
190
|
-
|
191
|
-
fixture_prod = new_fixture_prod
|
192
|
-
fixture_names = new_fixture_names
|
193
|
-
|
194
|
-
# due to the concatenation, fixture names all start leading "-" which is removed
|
195
|
-
fixture_names = [x[1:] for x in fixture_names]
|
196
|
-
|
197
|
-
# in pytest convention, variable strings are separated by comma
|
198
|
-
fixture_param_str = ",".join(fixture_vars)
|
199
|
-
|
200
|
-
# we need to remove the tuple bracket from singleton
|
201
|
-
# in pytest convention, only multiple variables (2 or more) are tuples
|
202
|
-
fixture_prod = [_remove_single(x) for x in fixture_prod]
|
203
|
-
|
204
|
-
# if deepcopy_fixtures = True:
|
205
|
-
# we run deepcopy on every element of fixture_prod to make them independent
|
206
|
-
if deepcopy_fixtures:
|
207
|
-
fixture_prod = [deepcopy(x) for x in fixture_prod]
|
208
|
-
|
209
|
-
return fixture_param_str, fixture_prod, fixture_names
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Testing utility for easy generation of conditional fixtures in pytest_generate_tests.
|
3
|
+
|
4
|
+
Exports create_conditional_fixtures_and_names utility
|
5
|
+
"""
|
6
|
+
from copy import deepcopy
|
7
|
+
from typing import Callable, Dict, List
|
8
|
+
|
9
|
+
from skbase._exceptions import FixtureGenerationError
|
10
|
+
from skbase.utils._nested_iter import _remove_single
|
11
|
+
from skbase.validate import check_sequence
|
12
|
+
|
13
|
+
__author__: List[str] = ["fkiraly"]
|
14
|
+
__all__: List[str] = ["create_conditional_fixtures_and_names"]
|
15
|
+
|
16
|
+
|
17
|
+
def create_conditional_fixtures_and_names(
|
18
|
+
test_name: str,
|
19
|
+
fixture_vars: List[str],
|
20
|
+
generator_dict: Dict[str, Callable],
|
21
|
+
fixture_sequence: List[str] = None,
|
22
|
+
raise_exceptions: bool = False,
|
23
|
+
deepcopy_fixtures: bool = False,
|
24
|
+
):
|
25
|
+
"""Create conditional fixtures for pytest_generate_tests.
|
26
|
+
|
27
|
+
Creates arguments for pytest.fixture.parameterize,
|
28
|
+
using conditional fixture generation functions in generator_dict.
|
29
|
+
|
30
|
+
Example: we want to loop over two fixture variables, "number" and "multiples"
|
31
|
+
"number" are integers from 1 to 10,
|
32
|
+
"multiples" are multiples of "number" up to "number"-squared
|
33
|
+
we then write a generator_dict with two entries
|
34
|
+
generator_dict["number"] is a function (test_name, **kwargs) -> list
|
35
|
+
that returns [1, 2, ..., 10]
|
36
|
+
generator_dict["multiples"] is a function (test_name, number, **kwargs) -> list
|
37
|
+
that returns [number, 2* number, ..., number*number]
|
38
|
+
|
39
|
+
This function automatically creates the inputs for pytest.mark.parameterize
|
40
|
+
fixture_param_str = "number,multiples"
|
41
|
+
fixture_prod = [(1, 1), (2, 2), (2, 4), (3, 3), (3, 6), ...]
|
42
|
+
fixture_names = ["1-1", "2-2", "2-4", "3-3", "3-6", ...]
|
43
|
+
|
44
|
+
Parameters
|
45
|
+
----------
|
46
|
+
test_name : str, name of the test, from pytest_generate_tests
|
47
|
+
fixture_vars : list of str
|
48
|
+
fixture variable names used in parameterization of tests
|
49
|
+
generator_dict : dict of generator functions
|
50
|
+
keys are possible str in fixture_vars, expected signature is
|
51
|
+
(test_name: str, **kwargs) -> fixtures: Listof[object], or
|
52
|
+
(returning only fixtures)
|
53
|
+
(test_name: str, **kwargs) -> fixtures, fixture_names: Listof[object]
|
54
|
+
(returning fixture names as well as fixtures)
|
55
|
+
generator_dict[my_variable] can take arguments with names
|
56
|
+
in fixture_sequence to the left of my_variable
|
57
|
+
it should return a list of fixtures for my_variable
|
58
|
+
under the assumption that arguments have given values
|
59
|
+
fixture_sequence : list of str, optional, default = None
|
60
|
+
used in prioritizing conditional generators, sequentially (see above)
|
61
|
+
raise_exceptions : bool, optional, default = False
|
62
|
+
whether fixture generation errors or other Exceptions are raised
|
63
|
+
if False, exceptions are returned instead of fixtures
|
64
|
+
deepcopy_fixtures : bool. optional, default = False
|
65
|
+
whether returned fixture list in fixture_prod are deecopy-independent
|
66
|
+
if False, identical list/tuple elements will be identical by reference
|
67
|
+
if True, identical elements will be identical by value but no by reference
|
68
|
+
"elements" refer to fixture[i] as described below, in fixture_prod
|
69
|
+
|
70
|
+
Returns
|
71
|
+
-------
|
72
|
+
fixture_param_str : str, string to use in pytest.fixture.parameterize
|
73
|
+
this is strings in "fixture_vars" concatenated, separated by ","
|
74
|
+
fixture_prod : list of tuples, fixtures to use in pytest.fixture.parameterize
|
75
|
+
fixture tuples, generated according to the following conditional rule:
|
76
|
+
let fixture_vars = [fixture_var1, fixture_var2, ..., fixture_varN]
|
77
|
+
all fixtures are obtained as following:
|
78
|
+
for i in 1 to N
|
79
|
+
pick fixture[i] any element of generator_dict[fixture_vari](
|
80
|
+
test_name,
|
81
|
+
fixture_var1 = fixture[1], ...,
|
82
|
+
fixture_var(i-1) = fixture[i-1],
|
83
|
+
)
|
84
|
+
return (fixture[1], fixture[2], ..., fixture[N])
|
85
|
+
if deepcopy_fixtures = False, identical fixture[i] are identical by reference
|
86
|
+
if deepcopy_fixtures = True, identical fixture[i] are not identical references
|
87
|
+
fixture_names : list of str, fixture ids to use in pytest.fixture.parameterize
|
88
|
+
fixture names, generated according to the following conditional rule:
|
89
|
+
let fixture_vars = [fixture_var1, fixture_var2, ..., fixture_varN]
|
90
|
+
all fixtures names are obtained as following:
|
91
|
+
for i in 1 to N
|
92
|
+
pick fixture_str_pt[i] any element of generator_dict[fixture_vari](
|
93
|
+
test_name,
|
94
|
+
fixture_var1 = fixture[1], ...,
|
95
|
+
fixture_var(i-1) = fixture[i-1],
|
96
|
+
), second return is exists; otherwise str(first return)
|
97
|
+
return "fixture_str_pt[1]-fixture_str_pt[2]-...-fixture_str_pt[N]"
|
98
|
+
fixture names correspond to fixtures with the same indices at picks (from lists)
|
99
|
+
"""
|
100
|
+
fixture_vars = check_sequence(
|
101
|
+
fixture_vars, sequence_type=list, element_type=str, sequence_name="fixture_vars"
|
102
|
+
)
|
103
|
+
fixture_vars = [var for var in fixture_vars if var in generator_dict.keys()]
|
104
|
+
|
105
|
+
# order fixture_vars according to fixture_sequence if provided
|
106
|
+
if fixture_sequence is not None:
|
107
|
+
fixture_sequence = check_sequence(
|
108
|
+
fixture_sequence,
|
109
|
+
sequence_type=list,
|
110
|
+
element_type=str,
|
111
|
+
sequence_name="fixture_sequence",
|
112
|
+
)
|
113
|
+
ordered_fixture_vars = []
|
114
|
+
for fixture_var_name in fixture_sequence:
|
115
|
+
if fixture_var_name in fixture_vars:
|
116
|
+
ordered_fixture_vars += [fixture_var_name]
|
117
|
+
fixture_vars = ordered_fixture_vars
|
118
|
+
|
119
|
+
def get_fixtures(fixture_var, **kwargs):
|
120
|
+
"""Call fixture generator from generator_dict, return fixture list.
|
121
|
+
|
122
|
+
Light wrapper around calls to generator_dict[key] functions that generate
|
123
|
+
conditional fixtures. get_fixtures adds default string names to the return
|
124
|
+
if generator_dict[key] does not return them.
|
125
|
+
|
126
|
+
Parameters
|
127
|
+
----------
|
128
|
+
fixture_var : str, name of fixture variable
|
129
|
+
kwargs : key-value pairs, keys = names of previous fixture variables
|
130
|
+
test_name : str, from local scope
|
131
|
+
name of test for which fixtures are generated
|
132
|
+
|
133
|
+
Returns
|
134
|
+
-------
|
135
|
+
fixture_prod : list of objects or one-element list with FixtureGenerationError
|
136
|
+
fixtures for fixture_var for test_name, conditional on fixtures in kwargs
|
137
|
+
if call to generator_dict[fixture_var] fails, returns list with error
|
138
|
+
fixture_names : list of string, same length as fixture_prod
|
139
|
+
i-th element is a string name for i-th element of fixture_prod
|
140
|
+
if 2nd arg is returned by generator_dict, then 1:1 copy of that argument
|
141
|
+
if no 2nd arg is returned by generator_dict, then str(fixture_prod[i])
|
142
|
+
if fixture_prod is list with error, then string is Error:fixture_var
|
143
|
+
"""
|
144
|
+
try:
|
145
|
+
res = generator_dict[fixture_var](test_name, **kwargs)
|
146
|
+
if isinstance(res, tuple) and len(res) == 2:
|
147
|
+
fixture_prod = res[0]
|
148
|
+
fixture_names = res[1]
|
149
|
+
else:
|
150
|
+
fixture_prod = res
|
151
|
+
fixture_names = [str(x) for x in res]
|
152
|
+
except Exception as err:
|
153
|
+
error = FixtureGenerationError(fixture_name=fixture_var, err=err)
|
154
|
+
if raise_exceptions:
|
155
|
+
raise error
|
156
|
+
fixture_prod = [error]
|
157
|
+
fixture_names = [f"Error:{fixture_var}"]
|
158
|
+
|
159
|
+
return fixture_prod, fixture_names
|
160
|
+
|
161
|
+
fixture_prod = [()]
|
162
|
+
fixture_names = [""]
|
163
|
+
|
164
|
+
# we loop over fixture_vars, incrementally going through conditionals
|
165
|
+
for i, fixture_var in enumerate(fixture_vars):
|
166
|
+
old_fixture_vars = fixture_vars[0:i]
|
167
|
+
|
168
|
+
# then take successive left products
|
169
|
+
new_fixture_prod = []
|
170
|
+
new_fixture_names = []
|
171
|
+
|
172
|
+
for j, fixture in enumerate(fixture_prod):
|
173
|
+
# retrieve kwargs corresponding to old fixture values
|
174
|
+
fixture_name = fixture_names[j]
|
175
|
+
if i == 0:
|
176
|
+
kwargs = {}
|
177
|
+
else:
|
178
|
+
kwargs = dict(zip(old_fixture_vars, fixture))
|
179
|
+
# retrieve conditional fixtures, conditional on fixture values in kwargs
|
180
|
+
new_fixtures, new_fixture_names_r = get_fixtures(fixture_var, **kwargs)
|
181
|
+
# new fixture values are concatenation/product of old values plus new
|
182
|
+
new_fixture_prod += [
|
183
|
+
fixture + (new_fixture,) for new_fixture in new_fixtures
|
184
|
+
]
|
185
|
+
# new fixture name is concatenation of name so far and "dash-new name"
|
186
|
+
# if the new name is empty string, don't add a dash
|
187
|
+
if len(new_fixture_names_r) > 0 and new_fixture_names_r[0] != "":
|
188
|
+
new_fixture_names_r = [f"-{x}" for x in new_fixture_names_r]
|
189
|
+
new_fixture_names += [f"{fixture_name}{x}" for x in new_fixture_names_r]
|
190
|
+
|
191
|
+
fixture_prod = new_fixture_prod
|
192
|
+
fixture_names = new_fixture_names
|
193
|
+
|
194
|
+
# due to the concatenation, fixture names all start leading "-" which is removed
|
195
|
+
fixture_names = [x[1:] for x in fixture_names]
|
196
|
+
|
197
|
+
# in pytest convention, variable strings are separated by comma
|
198
|
+
fixture_param_str = ",".join(fixture_vars)
|
199
|
+
|
200
|
+
# we need to remove the tuple bracket from singleton
|
201
|
+
# in pytest convention, only multiple variables (2 or more) are tuples
|
202
|
+
fixture_prod = [_remove_single(x) for x in fixture_prod]
|
203
|
+
|
204
|
+
# if deepcopy_fixtures = True:
|
205
|
+
# we run deepcopy on every element of fixture_prod to make them independent
|
206
|
+
if deepcopy_fixtures:
|
207
|
+
fixture_prod = [deepcopy(x) for x in fixture_prod]
|
208
|
+
|
209
|
+
return fixture_param_str, fixture_prod, fixture_names
|
@@ -1,15 +1,15 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""Deprecation forwarding of dependency checker utilities."""
|
3
|
-
|
4
|
-
# todo 0.6.0 - remove this forward
|
5
|
-
|
6
|
-
from warnings import warn
|
7
|
-
|
8
|
-
from skbase.utils.dependencies import _check_python_version, _check_soft_dependencies
|
9
|
-
|
10
|
-
warn(
|
11
|
-
"_check_soft_dependencies, _check_python_versiontesting have moved to "
|
12
|
-
"skbase.utils.dependencies. The old location will be removed in skbase 0.6.0."
|
13
|
-
)
|
14
|
-
|
15
|
-
__all__ = ["_check_python_version", "_check_soft_dependencies"]
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Deprecation forwarding of dependency checker utilities."""
|
3
|
+
|
4
|
+
# todo 0.6.0 - remove this forward
|
5
|
+
|
6
|
+
from warnings import warn
|
7
|
+
|
8
|
+
from skbase.utils.dependencies import _check_python_version, _check_soft_dependencies
|
9
|
+
|
10
|
+
warn(
|
11
|
+
"_check_soft_dependencies, _check_python_versiontesting have moved to "
|
12
|
+
"skbase.utils.dependencies. The old location will be removed in skbase 0.6.0."
|
13
|
+
)
|
14
|
+
|
15
|
+
__all__ = ["_check_python_version", "_check_soft_dependencies"]
|
@@ -1,15 +1,15 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""Deprecation forwarding of equality checker utilities."""
|
3
|
-
|
4
|
-
# todo 0.6.0 - remove this forward
|
5
|
-
|
6
|
-
from warnings import warn
|
7
|
-
|
8
|
-
from skbase.utils import deep_equals
|
9
|
-
|
10
|
-
warn(
|
11
|
-
"deep_equals has moved to "
|
12
|
-
"skbase.utils.deep_equals. The old location will be removed in skbase 0.6.0."
|
13
|
-
)
|
14
|
-
|
15
|
-
__all__ = ["deep_equals"]
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Deprecation forwarding of equality checker utilities."""
|
3
|
+
|
4
|
+
# todo 0.6.0 - remove this forward
|
5
|
+
|
6
|
+
from warnings import warn
|
7
|
+
|
8
|
+
from skbase.utils import deep_equals
|
9
|
+
|
10
|
+
warn(
|
11
|
+
"deep_equals has moved to "
|
12
|
+
"skbase.utils.deep_equals. The old location will be removed in skbase 0.6.0."
|
13
|
+
)
|
14
|
+
|
15
|
+
__all__ = ["deep_equals"]
|
skbase/testing/utils/inspect.py
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""Utilities for inspection of function arguments."""
|
3
|
-
|
4
|
-
|
5
|
-
from inspect import signature
|
6
|
-
|
7
|
-
|
8
|
-
def _get_args(function, varargs=False):
|
9
|
-
"""Get function arguments."""
|
10
|
-
try:
|
11
|
-
params = signature(function).parameters
|
12
|
-
except ValueError:
|
13
|
-
# Error on builtin C function
|
14
|
-
return []
|
15
|
-
args = [
|
16
|
-
key
|
17
|
-
for key, param in params.items()
|
18
|
-
if param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD)
|
19
|
-
]
|
20
|
-
if varargs:
|
21
|
-
varargs = [
|
22
|
-
param.name
|
23
|
-
for param in params.values()
|
24
|
-
if param.kind == param.VAR_POSITIONAL
|
25
|
-
]
|
26
|
-
if len(varargs) == 0:
|
27
|
-
varargs = None
|
28
|
-
return args, varargs
|
29
|
-
else:
|
30
|
-
return args
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Utilities for inspection of function arguments."""
|
3
|
+
|
4
|
+
|
5
|
+
from inspect import signature
|
6
|
+
|
7
|
+
|
8
|
+
def _get_args(function, varargs=False):
|
9
|
+
"""Get function arguments."""
|
10
|
+
try:
|
11
|
+
params = signature(function).parameters
|
12
|
+
except ValueError:
|
13
|
+
# Error on builtin C function
|
14
|
+
return []
|
15
|
+
args = [
|
16
|
+
key
|
17
|
+
for key, param in params.items()
|
18
|
+
if param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD)
|
19
|
+
]
|
20
|
+
if varargs:
|
21
|
+
varargs = [
|
22
|
+
param.name
|
23
|
+
for param in params.values()
|
24
|
+
if param.kind == param.VAR_POSITIONAL
|
25
|
+
]
|
26
|
+
if len(varargs) == 0:
|
27
|
+
varargs = None
|
28
|
+
return args, varargs
|
29
|
+
else:
|
30
|
+
return args
|
@@ -1,2 +1,2 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""Testing utilities of the test framework."""
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Testing utilities of the test framework."""
|