summaryrefslogtreecommitdiff
path: root/tests/pyreverse
diff options
context:
space:
mode:
authorAvram Lubkin <avylove@rockhopper.net>2023-03-10 13:23:03 -0500
committerGitHub <noreply@github.com>2023-03-10 19:23:03 +0100
commit958ff856a25c1b6152c6f0a03d7488a6278adebf (patch)
tree15bc188a818f68b1f7239fac922aa52099d96eeb /tests/pyreverse
parented8b840c5439ead350ba815c7fc02157d58166b1 (diff)
downloadpylint-git-958ff856a25c1b6152c6f0a03d7488a6278adebf.tar.gz
pyreverse: Add show-stdlib option (#8190)
* pyreverse: Add show-stdlib option * Switch to astroid.modutils.is_standard_module * Add tests * Fix quotes in whatsnew fragment * Update for astroid 2.15.0 * Recategorize news fragment
Diffstat (limited to 'tests/pyreverse')
-rw-r--r--tests/pyreverse/test_diadefs.py46
-rw-r--r--tests/pyreverse/test_main.py1
-rw-r--r--tests/pyreverse/test_writer.py1
3 files changed, 47 insertions, 1 deletions
diff --git a/tests/pyreverse/test_diadefs.py b/tests/pyreverse/test_diadefs.py
index 5dba9466d..73d8adfcc 100644
--- a/tests/pyreverse/test_diadefs.py
+++ b/tests/pyreverse/test_diadefs.py
@@ -13,7 +13,7 @@ from collections.abc import Iterator
from pathlib import Path
import pytest
-from astroid import nodes
+from astroid import extract_node, nodes
from pylint.pyreverse.diadefslib import (
ClassDiadefGenerator,
@@ -97,6 +97,50 @@ def test_default_values() -> None:
# TODO : should test difference between default values for package or class diagrams
+class TestShowOptions:
+ def test_show_stdlib(self) -> None:
+ example = extract_node(
+ '''
+ import collections
+
+ class CustomDict(collections.OrderedDict):
+ """docstring"""
+ '''
+ )
+
+ config = PyreverseConfig()
+ dd_gen = DiaDefGenerator(Linker(PROJECT), DiadefsHandler(config))
+
+ # Default behavior
+ assert not list(dd_gen.get_ancestors(example, 1))
+
+ # Show standard library enabled
+ config.show_stdlib = True
+ ancestors = list(dd_gen.get_ancestors(example, 1))
+ assert len(ancestors) == 1
+ assert ancestors[0].name == "OrderedDict"
+
+ def test_show_builtin(self) -> None:
+ example = extract_node(
+ '''
+ class CustomError(Exception):
+ """docstring"""
+ '''
+ )
+
+ config = PyreverseConfig()
+ dd_gen = DiaDefGenerator(Linker(PROJECT), DiadefsHandler(config))
+
+ # Default behavior
+ assert not list(dd_gen.get_ancestors(example, 1))
+
+ # Show builtin enabled
+ config.show_builtin = True
+ ancestors = list(dd_gen.get_ancestors(example, 1))
+ assert len(ancestors) == 1
+ assert ancestors[0].name == "Exception"
+
+
class TestDefaultDiadefGenerator:
_should_rels = [
("aggregation", "DoNothing2", "Specialization"),
diff --git a/tests/pyreverse/test_main.py b/tests/pyreverse/test_main.py
index 86401e05b..564394abb 100644
--- a/tests/pyreverse/test_main.py
+++ b/tests/pyreverse/test_main.py
@@ -138,6 +138,7 @@ def test_graphviz_unsupported_image_format(capsys: CaptureFixture) -> None:
("show_associated", None),
("all_associated", None),
("show_builtin", 0),
+ ("show_stdlib", 0),
("module_names", None),
("output_format", "dot"),
("colorized", 0),
diff --git a/tests/pyreverse/test_writer.py b/tests/pyreverse/test_writer.py
index 805f8fab5..c5a78d383 100644
--- a/tests/pyreverse/test_writer.py
+++ b/tests/pyreverse/test_writer.py
@@ -32,6 +32,7 @@ _DEFAULTS = {
"all_associated": None,
"mode": "PUB_ONLY",
"show_builtin": False,
+ "show_stdlib": False,
"only_classnames": False,
"output_directory": "",
}