Skip to content

Commit

Permalink
Move PyreverseConfig to pylint.testutil (#5013)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Sep 15, 2021
1 parent 22e56c0 commit d4e61b9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 47 deletions.
48 changes: 48 additions & 0 deletions pylint/testutils/pyreverse.py
@@ -0,0 +1,48 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE

from typing import List, Optional, Tuple


# 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
47 changes: 2 additions & 45 deletions tests/pyreverse/conftest.py
@@ -1,53 +1,10 @@
from typing import Callable, List, Optional, Tuple
from typing import Callable, Optional

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
from pylint.testutils.pyreverse import PyreverseConfig


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion tests/pyreverse/test_diadefs.py
Expand Up @@ -26,7 +26,6 @@

import pytest
from astroid import nodes
from tests.pyreverse.conftest import PyreverseConfig

from pylint.pyreverse.diadefslib import (
ClassDiadefGenerator,
Expand All @@ -36,6 +35,7 @@
)
from pylint.pyreverse.diagrams import DiagramEntity, Relationship
from pylint.pyreverse.inspector import Linker, Project
from pylint.testutils.pyreverse import PyreverseConfig


def _process_classes(classes: List[DiagramEntity]) -> List[Tuple[bool, str]]:
Expand Down
2 changes: 1 addition & 1 deletion tests/pyreverse/test_writer.py
Expand Up @@ -28,11 +28,11 @@
from unittest.mock import Mock

import pytest
from tests.pyreverse.conftest import PyreverseConfig

from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler
from pylint.pyreverse.inspector import Linker, Project
from pylint.pyreverse.writer import DiagramWriter
from pylint.testutils.pyreverse import PyreverseConfig

_DEFAULTS = {
"all_ancestors": None,
Expand Down

3 comments on commit d4e61b9

@DanielNoord
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pierre-Sassoulas btw, my local test environment is still broken. Is yours working? I remove all .pytest and .tox and didn't get fixed. Not sure what's up here..

@Pierre-Sassoulas
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try to launch with tox --recreate ? pytest . works for me.

@DanielNoord
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, figured it out. My local typing-filestream does not have this commit yet. 😅

Please sign in to comment.