Skip to content

Commit d4e61b9

Browse files
Move PyreverseConfig to pylint.testutil (#5013)
See : #5010 (comment)
1 parent 22e56c0 commit d4e61b9

File tree

4 files changed

+52
-47
lines changed

4 files changed

+52
-47
lines changed

pylint/testutils/pyreverse.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2+
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3+
4+
from typing import List, Optional, Tuple
5+
6+
7+
# This class could and should be replaced with a simple dataclass when support for Python < 3.7 is dropped.
8+
# A NamedTuple is not possible as some tests need to modify attributes during the test.
9+
class PyreverseConfig: # pylint: disable=too-many-instance-attributes, too-many-arguments
10+
"""Holds the configuration options for Pyreverse.
11+
The default values correspond to the defaults of the options parser."""
12+
13+
def __init__(
14+
self,
15+
mode: str = "PUB_ONLY",
16+
classes: Optional[List[str]] = None,
17+
show_ancestors: Optional[int] = None,
18+
all_ancestors: Optional[bool] = None,
19+
show_associated: Optional[int] = None,
20+
all_associated: Optional[bool] = None,
21+
show_builtin: bool = False,
22+
module_names: Optional[bool] = None,
23+
only_classnames: bool = False,
24+
output_format: str = "dot",
25+
colorized: bool = False,
26+
max_color_depth: int = 2,
27+
ignore_list: Tuple = tuple(),
28+
project: str = "",
29+
output_directory: str = "",
30+
):
31+
self.mode = mode
32+
if classes:
33+
self.classes = classes
34+
else:
35+
self.classes = []
36+
self.show_ancestors = show_ancestors
37+
self.all_ancestors = all_ancestors
38+
self.show_associated = show_associated
39+
self.all_associated = all_associated
40+
self.show_builtin = show_builtin
41+
self.module_names = module_names
42+
self.only_classnames = only_classnames
43+
self.output_format = output_format
44+
self.colorized = colorized
45+
self.max_color_depth = max_color_depth
46+
self.ignore_list = ignore_list
47+
self.project = project
48+
self.output_directory = output_directory

tests/pyreverse/conftest.py

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,10 @@
1-
from typing import Callable, List, Optional, Tuple
1+
from typing import Callable, Optional
22

33
import pytest
44
from astroid.nodes.scoped_nodes import Module
55

66
from pylint.pyreverse.inspector import Project, project_from_files
7-
8-
9-
# This class could and should be replaced with a simple dataclass when support for Python < 3.7 is dropped.
10-
# A NamedTuple is not possible as some tests need to modify attributes during the test.
11-
class PyreverseConfig: # pylint: disable=too-many-instance-attributes, too-many-arguments
12-
"""Holds the configuration options for Pyreverse.
13-
The default values correspond to the defaults of the options parser."""
14-
15-
def __init__(
16-
self,
17-
mode: str = "PUB_ONLY",
18-
classes: Optional[List[str]] = None,
19-
show_ancestors: Optional[int] = None,
20-
all_ancestors: Optional[bool] = None,
21-
show_associated: Optional[int] = None,
22-
all_associated: Optional[bool] = None,
23-
show_builtin: bool = False,
24-
module_names: Optional[bool] = None,
25-
only_classnames: bool = False,
26-
output_format: str = "dot",
27-
colorized: bool = False,
28-
max_color_depth: int = 2,
29-
ignore_list: Tuple = tuple(),
30-
project: str = "",
31-
output_directory: str = "",
32-
):
33-
self.mode = mode
34-
if classes:
35-
self.classes = classes
36-
else:
37-
self.classes = []
38-
self.show_ancestors = show_ancestors
39-
self.all_ancestors = all_ancestors
40-
self.show_associated = show_associated
41-
self.all_associated = all_associated
42-
self.show_builtin = show_builtin
43-
self.module_names = module_names
44-
self.only_classnames = only_classnames
45-
self.output_format = output_format
46-
self.colorized = colorized
47-
self.max_color_depth = max_color_depth
48-
self.ignore_list = ignore_list
49-
self.project = project
50-
self.output_directory = output_directory
7+
from pylint.testutils.pyreverse import PyreverseConfig
518

529

5310
@pytest.fixture()

tests/pyreverse/test_diadefs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import pytest
2828
from astroid import nodes
29-
from tests.pyreverse.conftest import PyreverseConfig
3029

3130
from pylint.pyreverse.diadefslib import (
3231
ClassDiadefGenerator,
@@ -36,6 +35,7 @@
3635
)
3736
from pylint.pyreverse.diagrams import DiagramEntity, Relationship
3837
from pylint.pyreverse.inspector import Linker, Project
38+
from pylint.testutils.pyreverse import PyreverseConfig
3939

4040

4141
def _process_classes(classes: List[DiagramEntity]) -> List[Tuple[bool, str]]:

tests/pyreverse/test_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
from unittest.mock import Mock
2929

3030
import pytest
31-
from tests.pyreverse.conftest import PyreverseConfig
3231

3332
from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler
3433
from pylint.pyreverse.inspector import Linker, Project
3534
from pylint.pyreverse.writer import DiagramWriter
35+
from pylint.testutils.pyreverse import PyreverseConfig
3636

3737
_DEFAULTS = {
3838
"all_ancestors": None,

0 commit comments

Comments
 (0)