Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / functional / name_styles.py @ 745

History | View | Annotate | Download (3.05 KB)

1
"""Test for the invalid-name warning."""
2
# pylint: disable=no-absolute-import
3
from __future__ import print_function
4
import abc
5
import collections
6

    
7
GOOD_CONST_NAME = ''
8
bad_const_name = 0  # [invalid-name]
9

    
10

    
11
def BADFUNCTION_name():  # [invalid-name]
12
    """Bad function name."""
13
    BAD_LOCAL_VAR = 1  # [invalid-name]
14
    print(BAD_LOCAL_VAR)
15

    
16

    
17
def func_bad_argname(NOT_GOOD):  # [invalid-name]
18
    """Function with a badly named argument."""
19
    return NOT_GOOD
20

    
21

    
22
def no_nested_args(arg1, arg21, arg22):
23
    """Well-formed function."""
24
    print(arg1, arg21, arg22)
25

    
26

    
27
class bad_class_name(object):  # [invalid-name]
28
    """Class with a bad name."""
29

    
30

    
31
class CorrectClassName(object):
32
    """Class with a good name."""
33

    
34
    def __init__(self):
35
        self._good_private_name = 10
36
        self.__good_real_private_name = 11
37
        self.good_attribute_name = 12
38
        self._Bad_AtTR_name = None  # [invalid-name]
39
        self.Bad_PUBLIC_name = None  # [invalid-name]
40

    
41
    zz = 'Bad Class Attribute'  # [invalid-name]
42
    GOOD_CLASS_ATTR = 'Good Class Attribute'
43

    
44
    def BadMethodName(self):  # [invalid-name]
45
        """A Method with a bad name."""
46

    
47
    def good_method_name(self):
48
        """A method with a good name."""
49

    
50
    def __DunDER_IS_not_free_for_all__(self):  # [invalid-name]
51
        """Another badly named method."""
52

    
53

    
54
class DerivedFromCorrect(CorrectClassName):
55
    """A derived class with an invalid inherited members.
56

57
    Derived attributes and methods with invalid names do not trigger warnings.
58
    """
59
    zz = 'Now a good class attribute'
60

    
61
    def __init__(self):
62
        super(DerivedFromCorrect, self).__init__()
63
        self._Bad_AtTR_name = None  # Ignored
64

    
65
    def BadMethodName(self):
66
        """Ignored since the method is in the interface."""
67

    
68

    
69
V = [WHAT_Ever_inListComp for WHAT_Ever_inListComp in GOOD_CONST_NAME]
70

    
71
def class_builder():
72
    """Function returning a class object."""
73

    
74
    class EmbeddedClass(object):
75
        """Useless class."""
76

    
77
    return EmbeddedClass
78

    
79
# +1:[invalid-name]
80
BAD_NAME_FOR_CLASS = collections.namedtuple('Named', ['tuple'])
81
NEXT_BAD_NAME_FOR_CLASS = class_builder()  # [invalid-name]
82

    
83
GoodName = collections.namedtuple('Named', ['tuple'])
84
ToplevelClass = class_builder()
85

    
86
# Aliases for classes have the same name constraints.
87
AlsoCorrect = CorrectClassName
88
NOT_CORRECT = CorrectClassName  # [invalid-name]
89

    
90

    
91
def test_globals():
92
    """Names in global statements are also checked."""
93
    global NOT_CORRECT
94
    global AlsoCorrect  # [invalid-name]
95
    NOT_CORRECT = 1
96
    AlsoCorrect = 2
97

    
98

    
99
class FooClass(object):
100
    """A test case for property names.
101

102
    Since by default, the regex for attributes is the same as the one
103
    for method names, we check the warning messages to contain the
104
    string 'attribute'.
105
    """
106
    @property
107
    def PROPERTY_NAME(self):  # [invalid-name]
108
        """Ignored."""
109
        pass
110

    
111
    @abc.abstractproperty
112
    def ABSTRACT_PROPERTY_NAME(self):  # [invalid-name]
113
        """Ignored."""
114
        pass
115

    
116
    @PROPERTY_NAME.setter
117
    def PROPERTY_NAME_SETTER(self):  # [invalid-name]
118
        """Ignored."""
119
        pass