scikit-base 0.8.2__tar.gz → 0.9.0__tar.gz
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.
- {scikit_base-0.8.2/scikit_base.egg-info → scikit_base-0.9.0}/PKG-INFO +2 -2
- {scikit_base-0.8.2 → scikit_base-0.9.0}/README.md +1 -1
- {scikit_base-0.8.2 → scikit_base-0.9.0}/pyproject.toml +1 -1
- {scikit_base-0.8.2 → scikit_base-0.9.0/scikit_base.egg-info}/PKG-INFO +2 -2
- {scikit_base-0.8.2 → scikit_base-0.9.0}/scikit_base.egg-info/SOURCES.txt +2 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/__init__.py +1 -1
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_base.py +41 -4
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/lookup/_lookup.py +5 -35
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/lookup/tests/test_lookup.py +5 -4
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/conftest.py +19 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/dependencies/_dependencies.py +12 -3
- scikit_base-0.9.0/skbase/utils/stderr_mute.py +64 -0
- scikit_base-0.9.0/skbase/utils/tests/test_std_mute.py +31 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/LICENSE +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/docs/source/conf.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/scikit_base.egg-info/dependency_links.txt +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/scikit_base.egg-info/requires.txt +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/scikit_base.egg-info/top_level.txt +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/scikit_base.egg-info/zip-safe +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/setup.cfg +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/_exceptions.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/_nopytest_tests.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_meta.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_pretty_printing/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_pretty_printing/_object_html_repr.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_pretty_printing/_pprint.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_pretty_printing/tests/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_pretty_printing/tests/test_pprint.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/base/_tagmanager.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/lookup/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/lookup/tests/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/testing/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/testing/test_all_objects.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/testing/utils/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/testing/utils/_conditional_fixtures.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/testing/utils/inspect.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/mock_package/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/mock_package/test_mock_package.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/test_base.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/test_baseestimator.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/test_exceptions.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/tests/test_meta.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/_check.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/_iter.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/_nested_iter.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/_utils.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/deep_equals/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/deep_equals/_common.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/deep_equals/_deep_equals.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/dependencies/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/dependencies/tests/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/dependencies/tests/test_check_dependencies.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/random_state.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/stdout_mute.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/tests/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/tests/test_check.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/tests/test_deep_equals.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/tests/test_iter.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/tests/test_nested_iter.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/tests/test_random_state.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/tests/test_utils.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/validate/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/validate/_named_objects.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/validate/_types.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/validate/tests/__init__.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/validate/tests/test_iterable_named_objects.py +0 -0
- {scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/validate/tests/test_type_validations.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: scikit-base
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.9.0
|
4
4
|
Summary: Base classes for sklearn-like parametric objects
|
5
5
|
Author-email: sktime developers <sktime.toolbox@gmail.com>
|
6
6
|
Maintainer: Franz Király
|
@@ -114,7 +114,7 @@ Requires-Dist: scikit-learn>=0.24.0; extra == "test"
|
|
114
114
|
`skbase` provides base classes for creating scikit-learn-like parametric objects,
|
115
115
|
along with tools to make it easier to build your own packages that follow these design patterns.
|
116
116
|
|
117
|
-
:rocket: Version 0.
|
117
|
+
:rocket: Version 0.9.0 is now available. Check out our
|
118
118
|
[release notes](https://skbase.readthedocs.io/en/latest/changelog.html).
|
119
119
|
|
120
120
|
| Overview | |
|
@@ -7,7 +7,7 @@
|
|
7
7
|
`skbase` provides base classes for creating scikit-learn-like parametric objects,
|
8
8
|
along with tools to make it easier to build your own packages that follow these design patterns.
|
9
9
|
|
10
|
-
:rocket: Version 0.
|
10
|
+
:rocket: Version 0.9.0 is now available. Check out our
|
11
11
|
[release notes](https://skbase.readthedocs.io/en/latest/changelog.html).
|
12
12
|
|
13
13
|
| Overview | |
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: scikit-base
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.9.0
|
4
4
|
Summary: Base classes for sklearn-like parametric objects
|
5
5
|
Author-email: sktime developers <sktime.toolbox@gmail.com>
|
6
6
|
Maintainer: Franz Király
|
@@ -114,7 +114,7 @@ Requires-Dist: scikit-learn>=0.24.0; extra == "test"
|
|
114
114
|
`skbase` provides base classes for creating scikit-learn-like parametric objects,
|
115
115
|
along with tools to make it easier to build your own packages that follow these design patterns.
|
116
116
|
|
117
|
-
:rocket: Version 0.
|
117
|
+
:rocket: Version 0.9.0 is now available. Check out our
|
118
118
|
[release notes](https://skbase.readthedocs.io/en/latest/changelog.html).
|
119
119
|
|
120
120
|
| Overview | |
|
@@ -44,6 +44,7 @@ skbase/utils/_iter.py
|
|
44
44
|
skbase/utils/_nested_iter.py
|
45
45
|
skbase/utils/_utils.py
|
46
46
|
skbase/utils/random_state.py
|
47
|
+
skbase/utils/stderr_mute.py
|
47
48
|
skbase/utils/stdout_mute.py
|
48
49
|
skbase/utils/deep_equals/__init__.py
|
49
50
|
skbase/utils/deep_equals/_common.py
|
@@ -58,6 +59,7 @@ skbase/utils/tests/test_deep_equals.py
|
|
58
59
|
skbase/utils/tests/test_iter.py
|
59
60
|
skbase/utils/tests/test_nested_iter.py
|
60
61
|
skbase/utils/tests/test_random_state.py
|
62
|
+
skbase/utils/tests/test_std_mute.py
|
61
63
|
skbase/utils/tests/test_utils.py
|
62
64
|
skbase/validate/__init__.py
|
63
65
|
skbase/validate/_named_objects.py
|
@@ -1292,10 +1292,47 @@ class BaseEstimator(BaseObject):
|
|
1292
1292
|
fitted_params = [
|
1293
1293
|
attr for attr in dir(obj) if attr.endswith("_") and not attr.startswith("_")
|
1294
1294
|
]
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1295
|
+
|
1296
|
+
def getattr_safe(obj, attr):
|
1297
|
+
"""Get attribute of object, safely.
|
1298
|
+
|
1299
|
+
Safe version of getattr, that returns None if attribute does not exist,
|
1300
|
+
or if an exception is raised during getattr.
|
1301
|
+
Also returns a boolean indicating whether the attribute was successfully
|
1302
|
+
retrieved, to distinguish between None value and non-existent attribute,
|
1303
|
+
or exception during getattr.
|
1304
|
+
|
1305
|
+
Parameters
|
1306
|
+
----------
|
1307
|
+
obj : any object
|
1308
|
+
object to get attribute from
|
1309
|
+
attr : str
|
1310
|
+
attribute name to get from obj
|
1311
|
+
|
1312
|
+
Returns
|
1313
|
+
-------
|
1314
|
+
attr : Any
|
1315
|
+
attribute of obj, if it exists and does not raise on getattr;
|
1316
|
+
otherwise None
|
1317
|
+
success : bool
|
1318
|
+
whether the attribute was successfully retrieved
|
1319
|
+
"""
|
1320
|
+
try:
|
1321
|
+
if hasattr(obj, attr):
|
1322
|
+
attr = getattr(obj, attr)
|
1323
|
+
return attr, True
|
1324
|
+
else:
|
1325
|
+
return None, False
|
1326
|
+
except Exception:
|
1327
|
+
return None, False
|
1328
|
+
|
1329
|
+
fitted_param_dict = {}
|
1330
|
+
|
1331
|
+
for p in fitted_params:
|
1332
|
+
attr, success = getattr_safe(obj, p)
|
1333
|
+
if success:
|
1334
|
+
p_name = p[:-1] # remove the "_" at the end to get the parameter name
|
1335
|
+
fitted_param_dict[p_name] = attr
|
1299
1336
|
|
1300
1337
|
return fitted_param_dict
|
1301
1338
|
|
@@ -203,46 +203,16 @@ def _filter_by_tags(obj, tag_filter=None, as_dataframe=True):
|
|
203
203
|
if not hasattr(obj, "get_class_tag"):
|
204
204
|
return False
|
205
205
|
|
206
|
-
klass_tags = obj.get_class_tags().keys()
|
207
|
-
|
208
|
-
# todo 0.9.0: remove the warning message
|
209
|
-
# i.e., this message and all warnings referring to it
|
210
|
-
warn_msg = (
|
211
|
-
"The meaning of filter_tags arguments in all_objects of type str "
|
212
|
-
"and iterable of str will change from scikit-base 0.9.0. "
|
213
|
-
"Currently, str or iterable of str arguments select objects that possess the "
|
214
|
-
"tag(s) with the specified name, of any value. "
|
215
|
-
"From 0.9.0 onwards, str or iterable of str "
|
216
|
-
"will select objects that possess the tag with the specified name, "
|
217
|
-
"with the value True (boolean). See scikit-base issue #326 for the rationale "
|
218
|
-
"behind this change. "
|
219
|
-
"To retain previous behaviour, that is, "
|
220
|
-
"to select objects that possess the tag with the specified name, of any value, "
|
221
|
-
"use a dict with the tag name as key, and re.Pattern('*?') as value. "
|
222
|
-
"That is, from re import Pattern, and pass {tag_name: Pattern('*?')} "
|
223
|
-
"as filter_tags, and similarly with multiple tag names. "
|
224
|
-
)
|
225
|
-
|
226
206
|
# case: tag_filter is string
|
227
207
|
if isinstance(tag_filter, str):
|
228
|
-
|
229
|
-
warnings.warn(warn_msg, DeprecationWarning, stacklevel=2)
|
230
|
-
# todo 0.9.0: replace this line
|
231
|
-
return tag_filter in klass_tags
|
232
|
-
# by this line
|
233
|
-
# tag_filter = {tag_filter: True}
|
208
|
+
tag_filter = {tag_filter: True}
|
234
209
|
|
235
210
|
# case: tag_filter is iterable of str but not dict
|
236
211
|
# If a iterable of strings is provided, check that all are in the returned tag_dict
|
237
212
|
if isinstance(tag_filter, Iterable) and not isinstance(tag_filter, dict):
|
238
213
|
if not all(isinstance(t, str) for t in tag_filter):
|
239
214
|
raise ValueError(f"{type_msg} {tag_filter}")
|
240
|
-
|
241
|
-
warnings.warn(warn_msg, DeprecationWarning, stacklevel=2)
|
242
|
-
# todo 0.9.0: replace this line
|
243
|
-
return all(tag in klass_tags for tag in tag_filter)
|
244
|
-
# by this line
|
245
|
-
# tag_filter = {tag: True for tag in tag_filter}
|
215
|
+
tag_filter = dict.fromkeys(tag_filter, True)
|
246
216
|
|
247
217
|
# case: tag_filter is dict
|
248
218
|
# check that all keys are str
|
@@ -712,8 +682,6 @@ def get_package_metadata(
|
|
712
682
|
return module_info
|
713
683
|
|
714
684
|
|
715
|
-
# todo 0.9.0: change docstring to reflect handling of filter_tags
|
716
|
-
# in case of str or iterable of str
|
717
685
|
def all_objects(
|
718
686
|
object_types=None,
|
719
687
|
filter_tags=None,
|
@@ -760,7 +728,9 @@ def all_objects(
|
|
760
728
|
Filter used to determine if ``klass`` has tag or expected tag values.
|
761
729
|
|
762
730
|
- If a str or list of strings is provided, the return will be filtered
|
763
|
-
to keep classes that have all the tag(s) specified by the strings
|
731
|
+
to keep classes that have all the tag(s) specified by the strings,
|
732
|
+
with the tag value being True.
|
733
|
+
|
764
734
|
- If a dict is provided, the return will be filtered to keep exactly the classes
|
765
735
|
where tags satisfy all the filter conditions specified by ``filter_tags``.
|
766
736
|
Filter conditions are as follows, for ``tag_name: search_value`` pairs in
|
@@ -35,6 +35,7 @@ from skbase.tests.conftest import (
|
|
35
35
|
SKBASE_PUBLIC_CLASSES_BY_MODULE,
|
36
36
|
SKBASE_PUBLIC_FUNCTIONS_BY_MODULE,
|
37
37
|
SKBASE_PUBLIC_MODULES,
|
38
|
+
ClassWithABTrue,
|
38
39
|
Parent,
|
39
40
|
)
|
40
41
|
from skbase.tests.mock_package.test_mock_package import (
|
@@ -374,18 +375,18 @@ def test_filter_by_tags():
|
|
374
375
|
assert _filter_by_tags(NotABaseObject) is True
|
375
376
|
|
376
377
|
# Check when tag_filter is a str and present in the class
|
377
|
-
assert _filter_by_tags(
|
378
|
+
assert _filter_by_tags(ClassWithABTrue, tag_filter="A") is True
|
378
379
|
# Check when tag_filter is str and not present in the class
|
379
|
-
assert _filter_by_tags(
|
380
|
+
assert _filter_by_tags(Parent, tag_filter="A") is False
|
380
381
|
|
381
382
|
# Test functionality when tag present and object doesn't have tag interface
|
382
383
|
assert _filter_by_tags(NotABaseObject, tag_filter="A") is False
|
383
384
|
|
384
385
|
# Test functionality where tag_filter is Iterable of str
|
385
386
|
# all tags in iterable are in the class
|
386
|
-
assert _filter_by_tags(
|
387
|
+
assert _filter_by_tags(ClassWithABTrue, ("A", "B")) is True
|
387
388
|
# Some tags in iterable are in class and others aren't
|
388
|
-
assert _filter_by_tags(
|
389
|
+
assert _filter_by_tags(ClassWithABTrue, ("A", "B", "C", "D", "E")) is False
|
389
390
|
|
390
391
|
# Test functionality where tag_filter is Dict[str, Any]
|
391
392
|
# All keys in dict are in tag_filter and values all match
|
@@ -54,6 +54,7 @@ SKBASE_MODULES = (
|
|
54
54
|
"skbase.utils.dependencies",
|
55
55
|
"skbase.utils.dependencies._dependencies",
|
56
56
|
"skbase.utils.random_state",
|
57
|
+
"skbase.utils.stderr_mute",
|
57
58
|
"skbase.utils.stdout_mute",
|
58
59
|
"skbase.validate",
|
59
60
|
"skbase.validate._named_objects",
|
@@ -80,6 +81,7 @@ SKBASE_PUBLIC_MODULES = (
|
|
80
81
|
"skbase.utils.deep_equals",
|
81
82
|
"skbase.utils.dependencies",
|
82
83
|
"skbase.utils.random_state",
|
84
|
+
"skbase.utils.stderr_mute",
|
83
85
|
"skbase.utils.stdout_mute",
|
84
86
|
"skbase.validate",
|
85
87
|
)
|
@@ -108,6 +110,7 @@ SKBASE_PUBLIC_CLASSES_BY_MODULE = {
|
|
108
110
|
"QuickTester",
|
109
111
|
"TestAllObjects",
|
110
112
|
),
|
113
|
+
"skbase.utils.stderr_mute": ("StderrMute",),
|
111
114
|
"skbase.utils.stdout_mute": ("StdoutMute",),
|
112
115
|
}
|
113
116
|
SKBASE_CLASSES_BY_MODULE = SKBASE_PUBLIC_CLASSES_BY_MODULE.copy()
|
@@ -311,3 +314,19 @@ class Child(Parent):
|
|
311
314
|
def some_other_method(self):
|
312
315
|
"""To be implemented in the child class."""
|
313
316
|
pass
|
317
|
+
|
318
|
+
|
319
|
+
# Fixture class for testing tag system, child overrides tags
|
320
|
+
class ClassWithABTrue(Parent):
|
321
|
+
"""Child class that sets A, B tags to True."""
|
322
|
+
|
323
|
+
_tags = {"A": True, "B": True}
|
324
|
+
__author__ = ["fkiraly", "RNKuhns"]
|
325
|
+
|
326
|
+
def some_method(self):
|
327
|
+
"""Child class' implementation."""
|
328
|
+
pass
|
329
|
+
|
330
|
+
def some_other_method(self):
|
331
|
+
"""To be implemented in the child class."""
|
332
|
+
pass
|
@@ -3,7 +3,6 @@
|
|
3
3
|
import sys
|
4
4
|
import warnings
|
5
5
|
from functools import lru_cache
|
6
|
-
from importlib.metadata import distributions
|
7
6
|
from inspect import isclass
|
8
7
|
|
9
8
|
from packaging.markers import InvalidMarker, Marker
|
@@ -186,9 +185,19 @@ def _get_installed_packages_private():
|
|
186
185
|
Same as _get_installed_packages, but internal to avoid mutating the lru_cache
|
187
186
|
by accident.
|
188
187
|
"""
|
188
|
+
from importlib.metadata import distributions, version
|
189
|
+
|
189
190
|
dists = distributions()
|
190
|
-
|
191
|
-
|
191
|
+
package_names = {dist.metadata["Name"] for dist in dists}
|
192
|
+
package_versions = {pkg_name: version(pkg_name) for pkg_name in package_names}
|
193
|
+
# developer note:
|
194
|
+
# we cannot just use distributions naively,
|
195
|
+
# because the same top level package name may appear *twice*,
|
196
|
+
# e.g., in a situation where a virtual env overrides a base env,
|
197
|
+
# such as in deployment environments like databricks.
|
198
|
+
# the "version" contract ensures we always get the version that corresponds
|
199
|
+
# to the importable distribution, i.e., the top one in the sys.path.
|
200
|
+
return package_versions
|
192
201
|
|
193
202
|
|
194
203
|
def _get_installed_packages():
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Context manager to suppress stderr."""
|
3
|
+
|
4
|
+
__author__ = ["XinyuWu"]
|
5
|
+
|
6
|
+
import io
|
7
|
+
import sys
|
8
|
+
|
9
|
+
|
10
|
+
class StderrMute:
|
11
|
+
"""A context manager to suppress stderr.
|
12
|
+
|
13
|
+
Exception handling on exit can be customized by overriding
|
14
|
+
the ``_handle_exit_exceptions`` method.
|
15
|
+
|
16
|
+
Parameters
|
17
|
+
----------
|
18
|
+
active : bool, default=True
|
19
|
+
Whether to suppress stderr or not.
|
20
|
+
If True, stderr is suppressed.
|
21
|
+
If False, stderr is not suppressed, and the context manager does nothing
|
22
|
+
except catch and suppress ModuleNotFoundError.
|
23
|
+
"""
|
24
|
+
|
25
|
+
def __init__(self, active=True):
|
26
|
+
self.active = active
|
27
|
+
|
28
|
+
def __enter__(self):
|
29
|
+
"""Context manager entry point."""
|
30
|
+
# capture stderr if active
|
31
|
+
# store the original stderr so it can be restored in __exit__
|
32
|
+
if self.active:
|
33
|
+
self._stderr = sys.stderr
|
34
|
+
sys.stderr = io.StringIO()
|
35
|
+
|
36
|
+
def __exit__(self, type, value, traceback): # noqa: A002
|
37
|
+
"""Context manager exit point."""
|
38
|
+
# restore stderr if active
|
39
|
+
# if not active, nothing needs to be done, since stderr was not replaced
|
40
|
+
if self.active:
|
41
|
+
sys.stderr = self._stderr
|
42
|
+
|
43
|
+
if type is not None:
|
44
|
+
return self._handle_exit_exceptions(type, value, traceback)
|
45
|
+
|
46
|
+
# if no exception was raised, return True to indicate successful exit
|
47
|
+
# return statement not needed as type was None, but included for clarity
|
48
|
+
return True
|
49
|
+
|
50
|
+
def _handle_exit_exceptions(self, type, value, traceback): # noqa: A002
|
51
|
+
"""Handle exceptions raised during __exit__.
|
52
|
+
|
53
|
+
Parameters
|
54
|
+
----------
|
55
|
+
type : type
|
56
|
+
The type of the exception raised.
|
57
|
+
Known to be not-None and Exception subtype when this method is called.
|
58
|
+
value : Exception
|
59
|
+
The exception instance raised.
|
60
|
+
traceback : traceback
|
61
|
+
The traceback object associated with the exception.
|
62
|
+
"""
|
63
|
+
# by default, all exceptions are raised
|
64
|
+
return False
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# copyright: skbase developers, BSD-3-Clause License (see LICENSE file)
|
3
|
+
"""Tests of stdout_mute and stderr_mute."""
|
4
|
+
import io
|
5
|
+
import sys
|
6
|
+
from contextlib import redirect_stderr, redirect_stdout
|
7
|
+
|
8
|
+
import pytest
|
9
|
+
|
10
|
+
from skbase.utils.stderr_mute import StderrMute
|
11
|
+
from skbase.utils.stdout_mute import StdoutMute
|
12
|
+
|
13
|
+
__author__ = ["XinyuWu"]
|
14
|
+
|
15
|
+
|
16
|
+
@pytest.mark.parametrize(
|
17
|
+
"mute, expected", [(True, ["", ""]), (False, ["test stdout", "test sterr"])]
|
18
|
+
)
|
19
|
+
def test_std_mute(mute, expected):
|
20
|
+
"""Test StderrMute."""
|
21
|
+
stderr_io = io.StringIO()
|
22
|
+
stdout_io = io.StringIO()
|
23
|
+
|
24
|
+
try:
|
25
|
+
with redirect_stderr(stderr_io), redirect_stdout(stdout_io):
|
26
|
+
with StderrMute(mute), StdoutMute(mute):
|
27
|
+
sys.stdout.write("test stdout")
|
28
|
+
sys.stderr.write("test sterr")
|
29
|
+
1 / 0
|
30
|
+
except ZeroDivisionError:
|
31
|
+
assert expected == [stdout_io.getvalue(), stderr_io.getvalue()]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/utils/dependencies/tests/test_check_dependencies.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{scikit_base-0.8.2 → scikit_base-0.9.0}/skbase/validate/tests/test_iterable_named_objects.py
RENAMED
File without changes
|
File without changes
|