File: test_abstract_attrs.py

package info (click to toggle)
python-gitlab 1%3A8.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,884 kB
  • sloc: python: 25,823; makefile: 171; ruby: 27; javascript: 3
file content (41 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download
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)}"
    )