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
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/master/LICENSE
import astroid
from pylint.checkers.refactoring import LenChecker
def test_class_tree_detection():
module = astroid.parse(
"""
class ClassWithBool(list):
def __bool__(self):
return True
class ClassWithoutBool(dict):
pass
class ChildClassWithBool(ClassWithBool):
pass
class ChildClassWithoutBool(ClassWithoutBool):
pass
"""
)
with_bool, without_bool, child_with_bool, child_without_bool = module.body
assert LenChecker().base_classes_of_node(with_bool) == [
"ClassWithBool",
"list",
"object",
]
assert LenChecker().base_classes_of_node(without_bool) == [
"ClassWithoutBool",
"dict",
"object",
]
assert LenChecker().base_classes_of_node(child_with_bool) == [
"ChildClassWithBool",
"ClassWithBool",
"list",
"object",
]
assert LenChecker().base_classes_of_node(child_without_bool) == [
"ChildClassWithoutBool",
"ClassWithoutBool",
"dict",
"object",
]
|