Skip to content

Commit

Permalink
Update optdicts in pyreverse (#6209)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord authored Apr 12, 2022
1 parent a1752c4 commit a6cb836
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pylint/config/options_provider_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def set_option(self, optname, value, action=None, optdict=None):
if action == "store":
setattr(self.config, self.option_attrname(optname, optdict), value)
elif action in {"store_true", "count"}:
setattr(self.config, self.option_attrname(optname, optdict), 0)
setattr(self.config, self.option_attrname(optname, optdict), value)
elif action == "store_false":
setattr(self.config, self.option_attrname(optname, optdict), 1)
setattr(self.config, self.option_attrname(optname, optdict), value)
elif action == "append":
optname = self.option_attrname(optname, optdict)
_list = getattr(self.config, optname, None)
Expand Down
6 changes: 6 additions & 0 deletions pylint/pyreverse/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
short="c",
action="append",
metavar="<class>",
type="csv",
dest="classes",
default=[],
help="create a class diagram with all classes related to <class>;\
Expand All @@ -70,6 +71,7 @@
action="store",
metavar="<ancestor>",
type="int",
default=None,
help="show <ancestor> generations of ancestor classes not in <projects>",
),
),
Expand All @@ -78,6 +80,7 @@
dict(
short="A",
default=None,
action="store_true",
help="show all ancestors off all classes in <projects>",
),
),
Expand All @@ -88,6 +91,7 @@
action="store",
metavar="<association_level>",
type="int",
default=None,
help="show <association_level> levels of associated classes not in <projects>",
),
),
Expand All @@ -96,6 +100,7 @@
dict(
short="S",
default=None,
action="store_true",
help="show recursively all associated off all associated classes",
),
),
Expand Down Expand Up @@ -135,6 +140,7 @@
action="store",
default="dot",
metavar="<format>",
type="string",
help=(
f"create a *.<format> output file if format is available. Available formats are: {', '.join(DIRECTLY_SUPPORTED_FORMATS)}. "
f"Any other format will be tried to create by means of the 'dot' command line tool, which requires a graphviz installation."
Expand Down
43 changes: 42 additions & 1 deletion tests/pyreverse/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""Unittest for the main module."""
import os
import sys
from typing import Iterator
from typing import Any, Iterator
from unittest import mock

import pytest
Expand Down Expand Up @@ -118,3 +118,44 @@ def test_graphviz_unsupported_image_format(capsys):
assert "Format somethingElse is not supported by Graphviz. It supports:" in stdout
# Check that we exited with the expected error code
assert wrapped_sysexit.value.code == 32


@pytest.mark.parametrize(
("arg", "expected_default"),
[
("mode", "PUB_ONLY"),
("classes", []),
("show_ancestors", None),
("all_ancestors", None),
("show_associated", None),
("all_associated", None),
("show_builtin", 0),
("module_names", None),
("output_format", "dot"),
("colorized", 0),
("max_color_depth", 2),
("ignore_list", ("CVS",)),
("project", ""),
("output_directory", ""),
],
)
@mock.patch("pylint.pyreverse.main.Run.run", new=mock.MagicMock())
@mock.patch("pylint.pyreverse.main.sys.exit", new=mock.MagicMock())
def test_command_line_arguments_defaults(arg: str, expected_default: Any) -> None:
"""Test that the default arguments of all options are correct."""
run = main.Run([TEST_DATA_DIR])
assert getattr(run.config, arg) == expected_default


@mock.patch("pylint.pyreverse.main.writer")
def test_command_line_arguments_yes_no(
mock_writer: mock.MagicMock, # pylint: disable=unused-argument
) -> None:
"""Regression test for the --module-names option.
Make sure that we supprot --module-names=yes syntax instead
of using it as a flag.
"""
with pytest.raises(SystemExit) as wrapped_sysexit:
main.Run(["--module-names=yes", TEST_DATA_DIR])
assert wrapped_sysexit.value.code == 0

0 comments on commit a6cb836

Please sign in to comment.