-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathtest_lookup.py
More file actions
52 lines (39 loc) · 1.47 KB
/
test_lookup.py
File metadata and controls
52 lines (39 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# copyright: hyperactive developers, BSD-3-Clause License (see LICENSE file)
"""Testing of registry lookup functionality."""
# based on the sktime module of same name
__author__ = ["fkiraly"]
import pytest
from hyperactive.registry import all_objects
object_types = ["optimizer", "experiment"]
def _to_list(obj):
"""Put obj in list if it is not a list."""
if not isinstance(obj, list):
return [obj]
else:
return obj.copy()
@pytest.mark.parametrize("return_names", [True, False])
@pytest.mark.parametrize("object_type", object_types)
def test_all_objects_by_scitype(object_type, return_names):
"""Check that all_objects return argument has correct type."""
objects = all_objects(
object_types=object_type,
return_names=return_names,
)
assert isinstance(objects, list)
# there should be at least one object returned
assert len(objects) > 0
# checks return type specification (see docstring)
for obj in objects:
if return_names:
assert isinstance(obj, tuple) and len(obj) == 2
name = obj[0]
obj_cls = obj[1]
assert isinstance(name, str)
assert hasattr(obj_cls, "__name__")
assert name == obj_cls.__name__
else:
obj_cls = obj
assert hasattr(obj_cls, "get_tags")
type_from_obj = obj_cls.get_class_tag("object_type")
type_from_obj = _to_list(type_from_obj)
assert object_type in type_from_obj