diff options
Diffstat (limited to 'tests/pyreverse/test_diadefs.py')
-rw-r--r-- | tests/pyreverse/test_diadefs.py | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/tests/pyreverse/test_diadefs.py b/tests/pyreverse/test_diadefs.py index 96cafc2ef..cdcdea7c5 100644 --- a/tests/pyreverse/test_diadefs.py +++ b/tests/pyreverse/test_diadefs.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Unit test for the extensions.diadefslib modules.""" @@ -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,19 +97,61 @@ 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"), ("association", "DoNothing", "Ancestor"), ("association", "DoNothing", "Specialization"), - ("implements", "Ancestor", "Interface"), ("specialization", "Specialization", "Ancestor"), ] def test_extract_relations(self, HANDLER: DiadefsHandler, PROJECT: Project) -> None: """Test extract_relations between classes.""" - with pytest.warns(DeprecationWarning): - cd = DefaultDiadefGenerator(Linker(PROJECT), HANDLER).visit(PROJECT)[1] + cd = DefaultDiadefGenerator(Linker(PROJECT), HANDLER).visit(PROJECT)[1] cd.extract_relationships() relations = _process_relations(cd.relationships) assert relations == self._should_rels |