-
Notifications
You must be signed in to change notification settings - Fork 676
Expand file tree
/
Copy pathtest_abstract_attrs.py
More file actions
41 lines (30 loc) · 1.07 KB
/
test_abstract_attrs.py
File metadata and controls
41 lines (30 loc) · 1.07 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
"""
Ensure that RESTManager subclasses exported to gitlab.v4.objects
are defining the _path and _obj_cls attributes.
Only check using `hasattr` as if incorrect type is assigned the type
checker will raise an error.
"""
from __future__ import annotations
from inspect import getmembers
import gitlab.v4.objects
from gitlab.base import RESTManager
def test_rest_manager_abstract_attrs() -> None:
without_path: list[str] = []
without_obj_cls: list[str] = []
for key, member in getmembers(gitlab.v4.objects):
if not isinstance(member, type):
continue
if not issubclass(member, RESTManager):
continue
if not hasattr(member, "_path"):
without_path.append(key)
if not hasattr(member, "_obj_cls"):
without_obj_cls.append(key)
assert not without_path, (
"RESTManager subclasses missing '_path' attribute: "
f"{', '.join(without_path)}"
)
assert not without_obj_cls, (
"RESTManager subclasses missing '_obj_cls' attribute: "
f"{', '.join(without_obj_cls)}"
)