diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-03-07 22:20:00 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-03-07 22:59:36 +0100 |
commit | f84bf0220812a987595f719acad0be6e8cf0f982 (patch) | |
tree | a7c96e0322a8b38af55b34e57e33105528b61fb8 /tests/functional | |
parent | 48d366855759b612cc883409997ba161afe09095 (diff) | |
download | pylint-git-f84bf0220812a987595f719acad0be6e8cf0f982.tar.gz |
Migrate all func_noerror_* to new functional tests
Diffstat (limited to 'tests/functional')
25 files changed, 506 insertions, 0 deletions
diff --git a/tests/functional/a/access/access_attr_before_def_false_positive.py b/tests/functional/a/access/access_attr_before_def_false_positive.py new file mode 100644 index 000000000..3884c9980 --- /dev/null +++ b/tests/functional/a/access/access_attr_before_def_false_positive.py @@ -0,0 +1,98 @@ +#pylint: disable=C0103,R0904,R0903,W0201,no-absolute-import, useless-object-inheritance +""" +This module demonstrates a possible problem of pyLint with calling __init__ s +from inherited classes. +Initializations done there are not considered, which results in Error E0203 for +self.cookedq. +""" + +from __future__ import print_function + +import telnetlib + +class SeeTelnet(telnetlib.Telnet): + """ + Extension of telnetlib. + """ + + def __init__(self, host=None, port=0): + """ + Constructor. + When called without arguments, create an unconnected instance. + With a hostname argument, it connects the instance; a port + number is optional. + Parameter: + - host: IP address of the host + - port: Port number + """ + telnetlib.Telnet.__init__(self, host, port) + + def readUntilArray(self, matches, _=None): + """ + Read until a given string is encountered or until timeout. + ... + """ + self.process_rawq() + maxLength = 0 + for match in matches: + if len(match) > maxLength: + maxLength = len(match) + +class Base(object): + """bla bla""" + dougloup_papa = None + + def __init__(self): + self._var = False + +class Derived(Base): + """derived blabla""" + dougloup_moi = None + def Work(self): + """do something""" + # E0203 - Access to member '_var' before its definition + if self._var: + print("True") + else: + print("False") + self._var = True + + # E0203 - Access to member 'dougloup_papa' before its definition + if self.dougloup_papa: + print('dougloup !') + self.dougloup_papa = True + # E0203 - Access to member 'dougloup_moi' before its definition + if self.dougloup_moi: + print('dougloup !') + self.dougloup_moi = True + + +class QoSALConnection(object): + """blabla""" + + _the_instance = None + + def __new__(cls): + if cls._the_instance is None: + cls._the_instance = object.__new__(cls) + return cls._the_instance + + def __init__(self): + pass + +class DefinedOutsideInit(object): + """use_attr is seen as the method defining attr because its in + first position + """ + def __init__(self): + self.reset() + + def use_attr(self): + """use and set members""" + if self.attr: + print('hop') + self.attr = 10 + + def reset(self): + """reset members""" + self.attr = 4 diff --git a/tests/functional/a/access_member_before_definition.py b/tests/functional/a/access/access_member_before_definition.py index d8a97b4c7..d8a97b4c7 100644 --- a/tests/functional/a/access_member_before_definition.py +++ b/tests/functional/a/access/access_member_before_definition.py diff --git a/tests/functional/a/access_member_before_definition.txt b/tests/functional/a/access/access_member_before_definition.txt index 76ba5de50..76ba5de50 100644 --- a/tests/functional/a/access_member_before_definition.txt +++ b/tests/functional/a/access/access_member_before_definition.txt diff --git a/tests/functional/a/access_to__name__.py b/tests/functional/a/access/access_to__name__.py index 82dcdbe78..82dcdbe78 100644 --- a/tests/functional/a/access_to__name__.py +++ b/tests/functional/a/access/access_to__name__.py diff --git a/tests/functional/a/access_to__name__.txt b/tests/functional/a/access/access_to__name__.txt index 5e1f80e2a..5e1f80e2a 100644 --- a/tests/functional/a/access_to__name__.txt +++ b/tests/functional/a/access/access_to__name__.txt diff --git a/tests/functional/a/access_to_protected_members.py b/tests/functional/a/access/access_to_protected_members.py index 737d8b9d6..737d8b9d6 100644 --- a/tests/functional/a/access_to_protected_members.py +++ b/tests/functional/a/access/access_to_protected_members.py diff --git a/tests/functional/a/access_to_protected_members.txt b/tests/functional/a/access/access_to_protected_members.txt index f1a545b27..f1a545b27 100644 --- a/tests/functional/a/access_to_protected_members.txt +++ b/tests/functional/a/access/access_to_protected_members.txt diff --git a/tests/functional/b/base_init_vars.py b/tests/functional/b/base_init_vars.py new file mode 100644 index 000000000..152cbfd47 --- /dev/null +++ b/tests/functional/b/base_init_vars.py @@ -0,0 +1,35 @@ +# pylint:disable=R0201, print-statement, too-few-public-methods, useless-object-inheritance +"""Checks that class variables are seen as inherited ! +""" +__revision__ = '' + +class BaseClass(object): + """A simple base class + """ + + def __init__(self): + self.base_var = {} + + def met(self): + """yo""" + def meeting(self, with_): + """ye""" + return with_ +class MyClass(BaseClass): + """Inherits from BaseClass + """ + + def __init__(self): + BaseClass.__init__(self) + self.var = {} + + def met(self): + """Checks that base_var is not seen as defined outsite '__init__' + """ + self.var[1] = 'one' + self.base_var[1] = 'one' + return self.base_var, self.var + +if __name__ == '__main__': + OBJ = MyClass() + OBJ.met() diff --git a/tests/functional/b/builtin_module_test.py b/tests/functional/b/builtin_module_test.py new file mode 100644 index 000000000..9b1e7ce8e --- /dev/null +++ b/tests/functional/b/builtin_module_test.py @@ -0,0 +1,11 @@ +"""test import from a builtin module""" + +from __future__ import absolute_import +from math import log10 + +__revision__ = None + + +def log10_2(): + """bla bla bla""" + return log10(2) diff --git a/tests/functional/c/class_attributes.py b/tests/functional/c/class_attributes.py new file mode 100644 index 000000000..b6fd4601e --- /dev/null +++ b/tests/functional/c/class_attributes.py @@ -0,0 +1,18 @@ +"""Test that valid class attribute doesn't trigger errors""" +__revision__ = 'sponge bob' +# pylint: disable=useless-object-inheritance + +class Clazz(object): + "dummy class" + + def __init__(self): + self.topic = 5 + self._data = 45 + + def change_type(self, new_class): + """Change type""" + self.__class__ = new_class + + def do_nothing(self): + "I do nothing useful" + return self.topic + 56 diff --git a/tests/functional/c/classes_meth_could_be_a_function.py b/tests/functional/c/classes_meth_could_be_a_function.py new file mode 100644 index 000000000..05a6c40d7 --- /dev/null +++ b/tests/functional/c/classes_meth_could_be_a_function.py @@ -0,0 +1,33 @@ +# pylint: disable=C0111,R0903,W0232, useless-object-inheritance +""" +#2479 + +R0201 (formely W0212), Method could be a function shouldn't be emitted in case +like factory method pattern +""" +__revision__ = 1 + +class XAsub(object): + pass +class XBsub(XAsub): + pass +class XCsub(XAsub): + pass + +class Aimpl(object): + # disable "method could be a function" on classes which are not overriding + # the factory method because in that case the usage of polymorphism is not + # detected + # pylint: disable=R0201 + def makex(self): + return XAsub() + +class Bimpl(Aimpl): + + def makex(self): + return XBsub() + +class Cimpl(Aimpl): + + def makex(self): + return XCsub() diff --git a/tests/functional/c/classes_protected_member_access.py b/tests/functional/c/classes_protected_member_access.py new file mode 100644 index 000000000..516efd7d4 --- /dev/null +++ b/tests/functional/c/classes_protected_member_access.py @@ -0,0 +1,26 @@ +""" +#3123: W0212 false positive on static method +""" +__revision__ = 1 + +# pylint: disable=no-classmethod-decorator, no-staticmethod-decorator, useless-object-inheritance +class A3123(object): + """oypuee""" + _protected = 1 + def __init__(self): + pass + + + def cmeth(cls, val): + """set protected member""" + cls._protected = +val + + cmeth = classmethod(cmeth) + + def smeth(val): + """set protected member""" + A3123._protected += val + + smeth = staticmethod(smeth) + + prop = property(lambda self: self._protected) diff --git a/tests/functional/d/decorator_scope.py b/tests/functional/d/decorator_scope.py new file mode 100644 index 000000000..8d35159e9 --- /dev/null +++ b/tests/functional/d/decorator_scope.py @@ -0,0 +1,19 @@ +# -*- pylint: disable=W0232,R0903, useless-object-inheritance +"""Test that decorators sees the class namespace - just like +function default values does but function body doesn't. + +https://www.logilab.net/elo/ticket/3711 - bug finding decorator arguments +https://www.logilab.net/elo/ticket/5626 - name resolution bug inside classes +""" + +from __future__ import print_function + +class Test(object): + """test class""" + ident = lambda x: x + + @ident(ident) + def method(self, val=ident(7), func=ident): + """hop""" + print(self) + return func(val) diff --git a/tests/functional/e/e1101_9588_base_attr_aug_assign.py b/tests/functional/e/e1101_9588_base_attr_aug_assign.py new file mode 100644 index 000000000..11472010c --- /dev/null +++ b/tests/functional/e/e1101_9588_base_attr_aug_assign.py @@ -0,0 +1,38 @@ +# pylint: disable=R0903, useless-object-inheritance +""" +False positive case of E1101: + +The error is triggered when the attribute set in the base class is +modified with augmented assignment in a derived class. + +https://www.logilab.org/ticket/9588 +""" +__revision__ = 0 + +class BaseClass(object): + "The base class" + def __init__(self): + "Set an attribute." + self.e1101 = 1 + +class FalsePositiveClass(BaseClass): + "The first derived class which triggers the false positive" + def __init__(self): + "Augmented assignment triggers E1101." + BaseClass.__init__(self) + self.e1101 += 1 + + def countup(self): + "Consequently this also triggers E1101." + self.e1101 += 1 + +class NegativeClass(BaseClass): + "The second derived class, which does not trigger the error E1101" + def __init__(self): + "Ordinary assignment is OK." + BaseClass.__init__(self) + self.e1101 = self.e1101 + 1 + + def countup(self): + "No problem." + self.e1101 += 1 diff --git a/tests/functional/e/external_classmethod_crash.py b/tests/functional/e/external_classmethod_crash.py new file mode 100644 index 000000000..e9842a5e5 --- /dev/null +++ b/tests/functional/e/external_classmethod_crash.py @@ -0,0 +1,21 @@ +# pylint: disable=W0232,R0903,W0613, useless-object-inheritance +"""tagging a function as a class method cause a crash when checking for +signature overriding +""" + +def fetch_config(mainattr=None): + """return a class method""" + + def fetch_order(cls, attr, var): + """a class method""" + if attr == mainattr: + return var + return None + fetch_order = classmethod(fetch_order) + return fetch_order + +class Aaa(object): + """hop""" + fetch_order = fetch_config('A') + +__revision__ = None diff --git a/tests/functional/i/init_return_from_inner_function.py b/tests/functional/i/init_return_from_inner_function.py new file mode 100644 index 000000000..769d5ac96 --- /dev/null +++ b/tests/functional/i/init_return_from_inner_function.py @@ -0,0 +1,12 @@ +# pylint: disable=R0903, useless-object-inheritance +"""#10075""" + +__revision__ = 1 + +class Aaa(object): + """docstring""" + def __init__(self): + def inner_function(arg): + """inner docstring""" + return arg + 4 + self.func = inner_function diff --git a/tests/functional/i/inner_classes.py b/tests/functional/i/inner_classes.py new file mode 100644 index 000000000..24a2edb80 --- /dev/null +++ b/tests/functional/i/inner_classes.py @@ -0,0 +1,33 @@ +# pylint: disable=R0903, useless-object-inheritance, unnecessary-pass +"""Backend Base Classes for the schwelm user DB""" + +__revision__ = "alpha" + +class Aaa(object): + """docstring""" + def __init__(self): + self.__setattr__('a', 'b') + + + def one_public(self): + """docstring""" + pass + + def another_public(self): + """docstring""" + pass + +class Bbb(Aaa): + """docstring""" + pass + +class Ccc(Aaa): + """docstring""" + + class Ddd(Aaa): + """docstring""" + pass + + class Eee(Ddd): + """docstring""" + pass diff --git a/tests/functional/l/lambda_use_before_assign.py b/tests/functional/l/lambda_use_before_assign.py new file mode 100644 index 000000000..af2775cae --- /dev/null +++ b/tests/functional/l/lambda_use_before_assign.py @@ -0,0 +1,8 @@ +"""https://www.logilab.net/elo/ticket/18862""" +from __future__ import print_function +__revision__ = 1 +def function(): + """hop""" + ggg = lambda: xxx + xxx = 1 + print(ggg()) diff --git a/tests/functional/m/metaclass_attr_access.py b/tests/functional/m/metaclass_attr_access.py new file mode 100644 index 000000000..149e07812 --- /dev/null +++ b/tests/functional/m/metaclass_attr_access.py @@ -0,0 +1,20 @@ +# pylint: disable=R0903, metaclass-assignment, useless-object-inheritance +"""test attribute access on metaclass""" + + +from __future__ import print_function + +class Meta(type): + """the meta class""" + def __init__(cls, name, bases, dictionary): + super(Meta, cls).__init__(name, bases, dictionary) + print(cls, cls._meta_args) + delattr(cls, '_meta_args') + +class Test(object): + """metaclassed class""" + __metaclass__ = Meta + _meta_args = ('foo', 'bar') + + def __init__(self): + print('__init__', self) diff --git a/tests/functional/n/no/no_warning_docstring.py b/tests/functional/n/no/no_warning_docstring.py new file mode 100644 index 000000000..315eeeaab --- /dev/null +++ b/tests/functional/n/no/no_warning_docstring.py @@ -0,0 +1,42 @@ +''' Test for inheritance ''' +from __future__ import print_function +__revision__ = 1 +# pylint: disable=too-few-public-methods, using-constant-test, useless-object-inheritance +class AAAA(object): + ''' class AAAA ''' + + def __init__(self): + pass + + def method1(self): + ''' method 1 ''' + print(self) + + def method2(self): + ''' method 2 ''' + print(self) + +class BBBB(AAAA): + ''' class BBBB ''' + + def __init__(self): + AAAA.__init__(self) + + # should ignore docstring calling from class AAAA + def method1(self): + AAAA.method1(self) + +class CCCC(BBBB): + ''' class CCCC ''' + + def __init__(self): + BBBB.__init__(self) + + # should ignore docstring since CCCC is inherited from BBBB which is + # inherited from AAAA containing method2 + if __revision__: + def method2(self): + AAAA.method2(self) + else: + def method2(self): + AAAA.method1(self) diff --git a/tests/functional/o/object_as_class_attribute.py b/tests/functional/o/object_as_class_attribute.py new file mode 100644 index 000000000..71cd027b7 --- /dev/null +++ b/tests/functional/o/object_as_class_attribute.py @@ -0,0 +1,18 @@ +# pylint: disable=R0903, useless-object-inheritance +"""Test case for the problem described below : + - A class extends 'object' + - This class defines its own __init__() + * pylint will therefore check that baseclasses' init() + are called + - If this class defines an 'object' attribute, then pylint + will use this new definition when trying to retrieve + object.__init__() +""" + +__revision__ = None + +class Statement(object): + """ ... """ + def __init__(self): + pass + object = None diff --git a/tests/functional/o/overloaded_operator.py b/tests/functional/o/overloaded_operator.py new file mode 100644 index 000000000..3a158b00b --- /dev/null +++ b/tests/functional/o/overloaded_operator.py @@ -0,0 +1,21 @@ +# pylint: disable=C0111,R0903, useless-object-inheritance +"""#3291""" +from __future__ import print_function + +class Myarray(object): + def __init__(self, array): + self.array = array + + def __mul__(self, val): + return Myarray(val) + + def astype(self): + return "ASTYPE", self + +def randint(maximum): + if maximum is not None: + return Myarray([1, 2, 3]) * 2 + + return int(5) + +print(randint(1).astype()) # we don't wan't an error for astype access diff --git a/tests/functional/p/property_affectation_py26.py b/tests/functional/p/property_affectation_py26.py new file mode 100644 index 000000000..60118bbf6 --- /dev/null +++ b/tests/functional/p/property_affectation_py26.py @@ -0,0 +1,24 @@ +# pylint: disable=R0903, useless-object-inheritance +""" +Simple test case for an annoying behavior in pylint. +""" + +__revision__ = 'pouet' + +class Test(object): + """Smallest test case for reported issue.""" + + def __init__(self): + self._thing = None + + @property + def myattr(self): + """Getter for myattr""" + return self._thing + + @myattr.setter + def myattr(self, value): + """Setter for myattr.""" + self._thing = value + +Test().myattr = 'grou' diff --git a/tests/functional/y/yield_assign_py25.py b/tests/functional/y/yield_assign_py25.py new file mode 100644 index 000000000..6a5ae00b2 --- /dev/null +++ b/tests/functional/y/yield_assign_py25.py @@ -0,0 +1,21 @@ +"""https://www.logilab.org/ticket/8771""" + +from __future__ import print_function + +def generator(): + """yield as assignment""" + yield 45 + xxxx = yield 123 + print(xxxx) + +def generator_fp1(seq): + """W0631 false positive""" + for val in seq: + pass + for val in seq: + yield val + +def generator_fp2(): + """E0601 false positive""" + xxxx = 12 + yield xxxx diff --git a/tests/functional/y/yield_return_mix.py b/tests/functional/y/yield_return_mix.py new file mode 100644 index 000000000..8e050f0f0 --- /dev/null +++ b/tests/functional/y/yield_return_mix.py @@ -0,0 +1,8 @@ +""" module doc """ +# pylint: disable=useless-return +__revision__ = None + +def somegen(): + """this kind of mix is OK""" + yield 1 + return |