blob: 441793a2ed882e3e5017d0a79798ff4aca5eb1ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# Copyright (c) 2021 Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
# Copyright (c) 2021 Ashley Whetter <ashley@awhetter.co.uk>
# Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
# Copyright (c) 2021 Rebecca Turner <rbt@sent.as>
# 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
import astroid
from pylint.checkers import design_analysis
from pylint.testutils import CheckerTestCase, set_config
from pylint.utils.utils import get_global_option
class TestDesignChecker(CheckerTestCase):
CHECKER_CLASS = design_analysis.MisdesignChecker
@set_config(
ignored_parents=(".Dddd",),
max_parents=1,
)
def test_too_many_ancestors_ignored_parents_are_skipped(self) -> None:
"""Make sure that classes listed in ``ignored-parents`` aren't counted
by the too-many-ancestors message.
"""
node = astroid.extract_node(
"""
class Aaaa(object):
pass
class Bbbb(Aaaa):
pass
class Cccc(Bbbb):
pass
class Dddd(Cccc):
pass
class Eeee(Dddd):
pass
"""
)
with self.assertNoMessages():
self.checker.visit_classdef(node)
@set_config(exclude_too_few_public_methods="toml.*")
def test_exclude_too_few_methods_with_value(self) -> None:
"""Test exclude-too-few-public-methods option with value"""
options = get_global_option(self.checker, "exclude-too-few-public-methods")
assert any(i.match("toml") for i in options)
assert any(i.match("toml.*") for i in options)
assert any(i.match("toml.TomlEncoder") for i in options)
def test_ignore_paths_with_no_value(self) -> None:
"""Test exclude-too-few-public-methods option with no value.
Compare against actual list to see if validator works."""
options = get_global_option(self.checker, "exclude-too-few-public-methods")
# pylint: disable-next=use-implicit-booleaness-not-comparison
assert options == []
|