summaryrefslogtreecommitdiff
path: root/tests/pyreverse/conftest.py
blob: 3a037840f1136a5d00cd36dcd8d967b48b0ef34f (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from typing import Callable, List, Optional, Tuple

import pytest
from astroid.nodes.scoped_nodes import Module

from pylint.pyreverse.inspector import Project, project_from_files


# This class could and should be replaced with a simple dataclass when support for Python < 3.7 is dropped.
# A NamedTuple is not possible as some tests need to modify attributes during the test.
class PyreverseConfig:  # pylint: disable=too-many-instance-attributes, too-many-arguments
    """Holds the configuration options for Pyreverse.
    The default values correspond to the defaults of the options parser."""

    def __init__(
        self,
        mode: str = "PUB_ONLY",
        classes: Optional[List[str]] = None,
        show_ancestors: Optional[int] = None,
        all_ancestors: Optional[bool] = None,
        show_associated: Optional[int] = None,
        all_associated: Optional[bool] = None,
        show_builtin: bool = False,
        module_names: Optional[bool] = None,
        only_classnames: bool = False,
        output_format: str = "dot",
        colorized: bool = False,
        max_color_depth: int = 2,
        ignore_list: Tuple = tuple(),
        project: str = "",
        output_directory: str = "",
    ):
        self.mode = mode
        if classes:
            self.classes = classes
        else:
            self.classes = []
        self.show_ancestors = show_ancestors
        self.all_ancestors = all_ancestors
        self.show_associated = show_associated
        self.all_associated = all_associated
        self.show_builtin = show_builtin
        self.module_names = module_names
        self.only_classnames = only_classnames
        self.output_format = output_format
        self.colorized = colorized
        self.max_color_depth = max_color_depth
        self.ignore_list = ignore_list
        self.project = project
        self.output_directory = output_directory


@pytest.fixture()
def default_config() -> PyreverseConfig:
    return PyreverseConfig()


@pytest.fixture()
def colorized_dot_config() -> PyreverseConfig:
    return PyreverseConfig(
        output_format="dot",
        colorized=True,
    )


@pytest.fixture()
def vcg_config() -> PyreverseConfig:
    return PyreverseConfig(
        output_format="vcg",
    )


@pytest.fixture()
def puml_config() -> PyreverseConfig:
    return PyreverseConfig(
        output_format="puml",
    )


@pytest.fixture()
def colorized_puml_config() -> PyreverseConfig:
    return PyreverseConfig(
        output_format="puml",
        colorized=True,
    )


@pytest.fixture(scope="session")
def get_project() -> Callable:
    def _get_project(module: str, name: Optional[str] = "No Name") -> Project:
        """return an astroid project representation"""

        def _astroid_wrapper(func: Callable, modname: str) -> Module:
            return func(modname)

        return project_from_files([module], _astroid_wrapper, project_name=name)

    return _get_project