summaryrefslogtreecommitdiff
path: root/tests/pyreverse/conftest.py
blob: 9e1741f0a868c9e60254a6a68510d99ecb1b77c6 (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
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt

from __future__ import annotations

from collections.abc import Callable

import pytest
from astroid.nodes.scoped_nodes import Module

from pylint.lint import augmented_sys_path, discover_package_path
from pylint.pyreverse.inspector import Project, project_from_files
from pylint.testutils.pyreverse import PyreverseConfig
from pylint.typing import GetProjectCallable


@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 no_standalone_dot_config() -> PyreverseConfig:
    return PyreverseConfig(
        output_format="dot",
        no_standalone=True,
    )


@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()
def mmd_config() -> PyreverseConfig:
    return PyreverseConfig(
        output_format="mmd",
        colorized=False,
    )


@pytest.fixture()
def html_config() -> PyreverseConfig:
    return PyreverseConfig(
        output_format="html",
        colorized=False,
    )


@pytest.fixture(scope="session")
def get_project() -> GetProjectCallable:
    def _get_project(module: str, name: str | None = "No Name") -> Project:
        """Return an astroid project representation."""

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

        with augmented_sys_path([discover_package_path(module, [])]):
            project = project_from_files([module], _astroid_wrapper, project_name=name)
        return project

    return _get_project