From f0156c24770d69662b77810b5ea3250f26fbce03 Mon Sep 17 00:00:00 2001 From: Torsten Marek Date: Sat, 26 Jul 2014 19:09:55 +0200 Subject: Converted more test cases to the new test framework. --- test/functional/access_to__name__.py | 21 +++++ test/functional/access_to__name__.txt | 3 + test/functional/access_to_protected_members.py | 39 ++++++++ test/functional/access_to_protected_members.txt | 5 ++ test/functional/arguments.py | 98 ++++++++++++++++++++ test/functional/arguments.txt | 20 +++++ test/functional/duplicate_dict_literal_key.py | 14 +++ test/functional/duplicate_dict_literal_key.txt | 1 + test/functional/globals.py | 24 +++++ test/functional/globals.txt | 6 ++ test/functional/invalid__all__object.py | 3 + test/functional/invalid__all__object.txt | 1 + test/functional/invalid_exceptions_raised.py | 51 +++++++++++ test/functional/invalid_exceptions_raised.txt | 11 +++ test/functional/names_in__all__.py | 46 ++++++++++ test/functional/names_in__all__.txt | 4 + test/functional/newstyle_properties.py | 53 +++++++++++ test/functional/newstyle_properties.txt | 2 + test/functional/super_checks.py | 46 ++++++++++ test/functional/super_checks.txt | 8 ++ test/functional/uninferable_all_object.py | 9 ++ test/input/func___name___access.py | 21 ----- test/input/func_all.py | 46 ---------- test/input/func_all_undefined.py | 8 -- test/input/func_arguments.py | 100 --------------------- test/input/func_class_access_protected_members.py | 36 -------- test/input/func_dict_keys.py | 15 ---- test/input/func_exceptions_raise_type_error.py | 14 --- test/input/func_globals.py | 40 --------- test/input/func_missing_super_argument_py_30.py | 9 -- test/input/func_newstyle_exceptions.py | 37 -------- test/input/func_newstyle_property.py | 48 ---------- test/input/func_newstyle_super.py | 47 ---------- test/input/func_noerror_all_no_inference.py | 14 --- test/messages/func___name___access.txt | 4 - test/messages/func___name___access_py30.txt | 3 - test/messages/func_all.txt | 4 - test/messages/func_all_undefined.txt | 1 - test/messages/func_arguments.txt | 20 ----- .../func_class_access_protected_members.txt | 5 -- test/messages/func_dict_keys.txt | 1 - test/messages/func_exceptions_raise_type_error.txt | 2 - test/messages/func_globals.txt | 6 -- .../messages/func_missing_super_argument_py_30.txt | 2 - test/messages/func_newstyle_exceptions.txt | 7 -- test/messages/func_newstyle_exceptions_py30.txt | 5 -- test/messages/func_newstyle_property.txt | 2 - test/messages/func_newstyle_property_py30.txt | 0 test/messages/func_newstyle_super.txt | 8 -- test/messages/func_newstyle_super_py30.txt | 4 - test/test_func.py | 4 +- 51 files changed, 468 insertions(+), 510 deletions(-) create mode 100644 test/functional/access_to__name__.py create mode 100644 test/functional/access_to__name__.txt create mode 100644 test/functional/access_to_protected_members.py create mode 100644 test/functional/access_to_protected_members.txt create mode 100644 test/functional/arguments.py create mode 100644 test/functional/arguments.txt create mode 100644 test/functional/duplicate_dict_literal_key.py create mode 100644 test/functional/duplicate_dict_literal_key.txt create mode 100644 test/functional/globals.py create mode 100644 test/functional/globals.txt create mode 100644 test/functional/invalid__all__object.py create mode 100644 test/functional/invalid__all__object.txt create mode 100644 test/functional/invalid_exceptions_raised.py create mode 100644 test/functional/invalid_exceptions_raised.txt create mode 100644 test/functional/names_in__all__.py create mode 100644 test/functional/names_in__all__.txt create mode 100644 test/functional/newstyle_properties.py create mode 100644 test/functional/newstyle_properties.txt create mode 100644 test/functional/super_checks.py create mode 100644 test/functional/super_checks.txt create mode 100644 test/functional/uninferable_all_object.py delete mode 100644 test/input/func___name___access.py delete mode 100644 test/input/func_all.py delete mode 100644 test/input/func_all_undefined.py delete mode 100644 test/input/func_arguments.py delete mode 100644 test/input/func_class_access_protected_members.py delete mode 100644 test/input/func_dict_keys.py delete mode 100644 test/input/func_exceptions_raise_type_error.py delete mode 100644 test/input/func_globals.py delete mode 100644 test/input/func_missing_super_argument_py_30.py delete mode 100644 test/input/func_newstyle_exceptions.py delete mode 100644 test/input/func_newstyle_property.py delete mode 100644 test/input/func_newstyle_super.py delete mode 100644 test/input/func_noerror_all_no_inference.py delete mode 100644 test/messages/func___name___access.txt delete mode 100644 test/messages/func___name___access_py30.txt delete mode 100644 test/messages/func_all.txt delete mode 100644 test/messages/func_all_undefined.txt delete mode 100644 test/messages/func_arguments.txt delete mode 100644 test/messages/func_class_access_protected_members.txt delete mode 100644 test/messages/func_dict_keys.txt delete mode 100644 test/messages/func_exceptions_raise_type_error.txt delete mode 100644 test/messages/func_globals.txt delete mode 100644 test/messages/func_missing_super_argument_py_30.txt delete mode 100644 test/messages/func_newstyle_exceptions.txt delete mode 100644 test/messages/func_newstyle_exceptions_py30.txt delete mode 100644 test/messages/func_newstyle_property.txt delete mode 100644 test/messages/func_newstyle_property_py30.txt delete mode 100644 test/messages/func_newstyle_super.txt delete mode 100644 test/messages/func_newstyle_super_py30.txt diff --git a/test/functional/access_to__name__.py b/test/functional/access_to__name__.py new file mode 100644 index 0000000..21da530 --- /dev/null +++ b/test/functional/access_to__name__.py @@ -0,0 +1,21 @@ +# pylint: disable=too-few-public-methods,star-args +"""test access to __name__ gives undefined member on new/old class instances +but not on new/old class object +""" + + +class Aaaa: # <3.0:[old-style-class] + """old class""" + def __init__(self): + print self.__name__ # [no-member] + print self.__class__.__name__ + +class NewClass(object): + """new class""" + + def __new__(cls, *args, **kwargs): + print 'new', cls.__name__ + return object.__new__(cls, *args, **kwargs) + + def __init__(self): + print 'init', self.__name__ # [no-member] diff --git a/test/functional/access_to__name__.txt b/test/functional/access_to__name__.txt new file mode 100644 index 0000000..2c0a953 --- /dev/null +++ b/test/functional/access_to__name__.txt @@ -0,0 +1,3 @@ +old-style-class:7:Aaaa:Old-style class defined. +no-member:10:Aaaa.__init__:Instance of 'Aaaa' has no '__name__' member +no-member:21:NewClass.__init__:Instance of 'NewClass' has no '__name__' member diff --git a/test/functional/access_to_protected_members.py b/test/functional/access_to_protected_members.py new file mode 100644 index 0000000..8f1c928 --- /dev/null +++ b/test/functional/access_to_protected_members.py @@ -0,0 +1,39 @@ +# pylint: disable=too-few-public-methods, W0231 +"""Test external access to protected class members.""" + + +class MyClass(object): + """Class with protected members.""" + _cls_protected = 5 + + def __init__(self, other): + MyClass._cls_protected = 6 + self._protected = 1 + self.public = other + self.attr = 0 + + def test(self): + """Docstring.""" + self._protected += self._cls_protected + print self.public._haha # [protected-access] + + def clsmeth(cls): + """Docstring.""" + cls._cls_protected += 1 + print cls._cls_protected + clsmeth = classmethod(clsmeth) + +class Subclass(MyClass): + """Subclass with protected members.""" + + def __init__(self): + MyClass._protected = 5 + +INST = Subclass() +INST.attr = 1 +print INST.attr +INST._protected = 2 # [protected-access] +print INST._protected # [protected-access] +INST._cls_protected = 3 # [protected-access] +print INST._cls_protected # [protected-access] + diff --git a/test/functional/access_to_protected_members.txt b/test/functional/access_to_protected_members.txt new file mode 100644 index 0000000..b933c23 --- /dev/null +++ b/test/functional/access_to_protected_members.txt @@ -0,0 +1,5 @@ +protected-access:18:MyClass.test:Access to a protected member _haha of a client class +protected-access:35::Access to a protected member _protected of a client class +protected-access:36::Access to a protected member _protected of a client class +protected-access:37::Access to a protected member _cls_protected of a client class +protected-access:38::Access to a protected member _cls_protected of a client class diff --git a/test/functional/arguments.py b/test/functional/arguments.py new file mode 100644 index 0000000..46dae22 --- /dev/null +++ b/test/functional/arguments.py @@ -0,0 +1,98 @@ +# pylint: disable=too-few-public-methods +"""Test function argument checker""" + +def decorator(fun): + """Decorator""" + return fun + + +class DemoClass(object): + """Test class for method invocations.""" + + @staticmethod + def static_method(arg): + """static method.""" + return arg + arg + + @classmethod + def class_method(cls, arg): + """class method""" + return arg + arg + + def method(self, arg): + """method.""" + return (self, arg) + + @decorator + def decorated_method(self, arg): + """decorated method.""" + return (self, arg) + + +def function_1_arg(first_argument): + """one argument function""" + return first_argument + +def function_3_args(first_argument, second_argument, third_argument): + """three arguments function""" + return first_argument, second_argument, third_argument + +def function_default_arg(one=1, two=2): + """fonction with default value""" + return two, one + + +function_1_arg(420) +function_1_arg() # [no-value-for-parameter] +function_1_arg(1337, 347) # [too-many-function-args] + +function_3_args(420, 789) # [no-value-for-parameter] +# +1:[no-value-for-parameter,no-value-for-parameter,no-value-for-parameter] +function_3_args() +function_3_args(1337, 347, 456) +function_3_args('bab', 'bebe', None, 5.6) # [too-many-function-args] + +function_default_arg(1, two=5) +function_default_arg(two=5) + +function_1_arg(bob=4) # [unexpected-keyword-arg,no-value-for-parameter] +function_default_arg(1, 4, coin="hello") # [unexpected-keyword-arg] + +function_default_arg(1, one=5) # [redundant-keyword-arg] + +# Remaining tests are for coverage of correct names in messages. +LAMBDA = lambda arg: 1 + +LAMBDA() # [no-value-for-parameter] + +def method_tests(): + """"Method invocations.""" + demo = DemoClass() + demo.static_method() # [no-value-for-parameter] + DemoClass.static_method() # [no-value-for-parameter] + + demo.class_method() # [no-value-for-parameter] + DemoClass.class_method() # [no-value-for-parameter] + + demo.method() # [no-value-for-parameter] + DemoClass.method(demo) # [no-value-for-parameter] + + demo.decorated_method() # [no-value-for-parameter] + DemoClass.decorated_method(demo) # [no-value-for-parameter] + +# Test a regression (issue #234) +import sys + +class Text(object): + """ Regression """ + + if sys.version_info > (3,): + def __new__(cls): + """ empty """ + return object.__new__(cls) + else: + def __new__(cls): + """ empty """ + return object.__new__(cls) + +Text() diff --git a/test/functional/arguments.txt b/test/functional/arguments.txt new file mode 100644 index 0000000..050f2c4 --- /dev/null +++ b/test/functional/arguments.txt @@ -0,0 +1,20 @@ +no-value-for-parameter:46::No value for argument 'first_argument' in function call +too-many-function-args:47::Too many positional arguments for function call +no-value-for-parameter:49::No value for argument 'third_argument' in function call +no-value-for-parameter:51::No value for argument 'first_argument' in function call +no-value-for-parameter:51::No value for argument 'second_argument' in function call +no-value-for-parameter:51::No value for argument 'third_argument' in function call +too-many-function-args:53::Too many positional arguments for function call +no-value-for-parameter:58::No value for argument 'first_argument' in function call +unexpected-keyword-arg:58::Unexpected keyword argument 'bob' in function call +unexpected-keyword-arg:59::Unexpected keyword argument 'coin' in function call +redundant-keyword-arg:61::Argument 'one' passed by position and keyword in function call +no-value-for-parameter:66::No value for argument 'arg' in lambda call +no-value-for-parameter:71:method_tests:No value for argument 'arg' in staticmethod call +no-value-for-parameter:72:method_tests:No value for argument 'arg' in staticmethod call +no-value-for-parameter:74:method_tests:No value for argument 'arg' in classmethod call +no-value-for-parameter:75:method_tests:No value for argument 'arg' in classmethod call +no-value-for-parameter:77:method_tests:No value for argument 'arg' in method call +no-value-for-parameter:78:method_tests:No value for argument 'arg' in unbound method call +no-value-for-parameter:80:method_tests:No value for argument 'arg' in method call +no-value-for-parameter:81:method_tests:No value for argument 'arg' in unbound method call diff --git a/test/functional/duplicate_dict_literal_key.py b/test/functional/duplicate_dict_literal_key.py new file mode 100644 index 0000000..f74e10e --- /dev/null +++ b/test/functional/duplicate_dict_literal_key.py @@ -0,0 +1,14 @@ +"""Check multiple key definition""" +#pylint: disable=C0103 + +correct_dict = { + 'tea': 'for two', + 'two': 'for tea', +} + +wrong_dict = { # [duplicate-key] + 'tea': 'for two', + 'two': 'for tea', + 'tea': 'time', + +} diff --git a/test/functional/duplicate_dict_literal_key.txt b/test/functional/duplicate_dict_literal_key.txt new file mode 100644 index 0000000..9780480 --- /dev/null +++ b/test/functional/duplicate_dict_literal_key.txt @@ -0,0 +1 @@ +duplicate-key:9::Duplicate key 'tea' in dictionary diff --git a/test/functional/globals.py b/test/functional/globals.py new file mode 100644 index 0000000..04bfd95 --- /dev/null +++ b/test/functional/globals.py @@ -0,0 +1,24 @@ +"""Warnings about global statements and usage of global variables.""" + +global CSTE # [global-at-module-level] +print CSTE # [undefined-variable] + +CONSTANT = 1 + +def fix_contant(value): + """all this is ok, but try not using global ;)""" + global CONSTANT # [global-statement] + print CONSTANT + CONSTANT = value + + +def other(): + """global behaviour test""" + global HOP # [global-variable-not-assigned] + print HOP # [undefined-variable] + + +def define_constant(): + """ok but somevar is not defined at the module scope""" + global SOMEVAR # [global-variable-undefined] + SOMEVAR = 2 diff --git a/test/functional/globals.txt b/test/functional/globals.txt new file mode 100644 index 0000000..0f9d13a --- /dev/null +++ b/test/functional/globals.txt @@ -0,0 +1,6 @@ +global-at-module-level:3::Using the global statement at the module level +undefined-variable:4::Undefined variable 'CSTE' +global-statement:10:fix_contant:Using the global statement +global-variable-not-assigned:17:other:Using global for 'HOP' but no assignment is done +undefined-variable:18:other:Undefined variable 'HOP' +global-variable-undefined:23:define_constant:Global variable 'SOMEVAR' undefined at the module level diff --git a/test/functional/invalid__all__object.py b/test/functional/invalid__all__object.py new file mode 100644 index 0000000..2a1a592 --- /dev/null +++ b/test/functional/invalid__all__object.py @@ -0,0 +1,3 @@ +"""Test that non-inferable __all__ variables do not make Pylint crash.""" + +__all__ = [SomeUndefinedName] # [undefined-variable] diff --git a/test/functional/invalid__all__object.txt b/test/functional/invalid__all__object.txt new file mode 100644 index 0000000..03ad496 --- /dev/null +++ b/test/functional/invalid__all__object.txt @@ -0,0 +1 @@ +undefined-variable:3::Undefined variable 'SomeUndefinedName' diff --git a/test/functional/invalid_exceptions_raised.py b/test/functional/invalid_exceptions_raised.py new file mode 100644 index 0000000..fe6223d --- /dev/null +++ b/test/functional/invalid_exceptions_raised.py @@ -0,0 +1,51 @@ +# pylint:disable=too-few-public-methods,old-style-class,no-init +"""test pb with exceptions and old/new style classes""" + + +class ValidException(Exception): + """Valid Exception.""" + +class OldStyleClass: + """Not an exception.""" + +class NewStyleClass(object): + """Not an exception.""" + + +def good_case(): + """raise""" + raise ValidException('hop') + +def bad_case0(): + """raise""" + # +2:<3.0:[nonstandard-exception] + # +1:>=3.0:[raising-non-exception] + raise OldStyleClass('hop') + +def bad_case1(): + """raise""" + raise NewStyleClass() # [raising-non-exception] + +def bad_case2(): + """raise""" + # +2:<3.0:[old-raise-syntax,nonstandard-exception] + # +1:>=3.0:[raising-non-exception] + raise OldStyleClass, 'hop' + +def bad_case3(): + """raise""" + raise NewStyleClass # [raising-non-exception] + +def bad_case4(): + """raise""" + # +1:<3.0:[old-raise-syntax] + raise NotImplemented, 'hop' # [notimplemented-raised] + +def bad_case5(): + """raise""" + raise 1 # [raising-bad-type] + +def base_case6(): + """raise""" + raise None # [raising-bad-type] + diff --git a/test/functional/invalid_exceptions_raised.txt b/test/functional/invalid_exceptions_raised.txt new file mode 100644 index 0000000..756d92c --- /dev/null +++ b/test/functional/invalid_exceptions_raised.txt @@ -0,0 +1,11 @@ +raising-non-exception:23:bad_case0:Raising a new style class which doesn't inherit from BaseException +nonstandard-exception:23:bad_case0:Exception doesn't inherit from standard "Exception" class +raising-non-exception:27:bad_case1:Raising a new style class which doesn't inherit from BaseException +raising-non-exception:33:bad_case2:Raising a new style class which doesn't inherit from BaseException +nonstandard-exception:33:bad_case2:Exception doesn't inherit from standard "Exception" class +old-raise-syntax:33:bad_case2:Use raise ErrorClass(args) instead of raise ErrorClass, args. +raising-non-exception:37:bad_case3:Raising a new style class which doesn't inherit from BaseException +notimplemented-raised:42:bad_case4:NotImplemented raised - should raise NotImplementedError +old-raise-syntax:42:bad_case4:Use raise ErrorClass(args) instead of raise ErrorClass, args. +raising-bad-type:46:bad_case5:Raising int while only classes, instances or string are allowed +raising-bad-type:50:base_case6:Raising NoneType while only classes, instances or string are allowed diff --git a/test/functional/names_in__all__.py b/test/functional/names_in__all__.py new file mode 100644 index 0000000..acd94c3 --- /dev/null +++ b/test/functional/names_in__all__.py @@ -0,0 +1,46 @@ +# pylint: disable=too-few-public-methods,no-self-use +"""Test Pylint's use of __all__. + +* NonExistant is not defined in this module, and it is listed in + __all__. An error is expected. + +* This module imports path and republished it in __all__. No errors + are expected. +""" + + +from os import path +from collections import deque + +__all__ = [ + 'Dummy', + 'NonExistant', # [undefined-all-variable] + 'path', + 'func', # [undefined-all-variable] + 'inner', # [undefined-all-variable] + 'InnerKlass', deque.__name__] # [undefined-all-variable] + + +class Dummy(object): + """A class defined in this module.""" + pass + +DUMMY = Dummy() + +def function(): + """Function docstring + """ + pass + +function() + +class Klass(object): + """A klass which contains a function""" + def func(self): + """A klass method""" + inner = None + print inner + + class InnerKlass(object): + """A inner klass""" + pass diff --git a/test/functional/names_in__all__.txt b/test/functional/names_in__all__.txt new file mode 100644 index 0000000..6cd7ae5 --- /dev/null +++ b/test/functional/names_in__all__.txt @@ -0,0 +1,4 @@ +undefined-all-variable:17::Undefined variable name 'NonExistant' in __all__ +undefined-all-variable:19::Undefined variable name 'func' in __all__ +undefined-all-variable:20::Undefined variable name 'inner' in __all__ +undefined-all-variable:21::Undefined variable name 'InnerKlass' in __all__ diff --git a/test/functional/newstyle_properties.py b/test/functional/newstyle_properties.py new file mode 100644 index 0000000..110fa3b --- /dev/null +++ b/test/functional/newstyle_properties.py @@ -0,0 +1,53 @@ +# pylint: disable=too-few-public-methods +"""Test properties on old style classes and property.setter/deleter usage""" + + +def getter(self): + """interesting""" + return self + +class CorrectClass(object): + """correct usage""" + method = property(getter, doc='hop') + +class OldStyleClass: # <3.0:[old-style-class] + """bad usage""" + method = property(getter, doc='hop') # <3.0:[property-on-old-class] + + def __init__(self): + pass + + +def decorator(func): + """Redefining decorator.""" + def wrapped(self): + """Wrapper function.""" + return func(self) + return wrapped + + +class SomeClass(object): + """another docstring""" + + def __init__(self): + self._prop = None + + @property + def prop(self): + """I'm the 'prop' property.""" + return self._prop + + @prop.setter + def prop(self, value): + """I'm the 'prop' property.""" + self._prop = value + + @prop.deleter + def prop(self): + """I'm the 'prop' property.""" + del self._prop + + @decorator + def noregr(self): + """Just a normal method with a decorator.""" + return self.prop diff --git a/test/functional/newstyle_properties.txt b/test/functional/newstyle_properties.txt new file mode 100644 index 0000000..f3a8dbb --- /dev/null +++ b/test/functional/newstyle_properties.txt @@ -0,0 +1,2 @@ +old-style-class:13:OldStyleClass:Old-style class defined. +property-on-old-class:15:OldStyleClass:Use of "property" on an old style class diff --git a/test/functional/super_checks.py b/test/functional/super_checks.py new file mode 100644 index 0000000..d9acfa3 --- /dev/null +++ b/test/functional/super_checks.py @@ -0,0 +1,46 @@ +# pylint: disable=too-few-public-methods,import-error +"""check use of super""" + +from unknown import Missing + +class Aaaa: # <3.0:[old-style-class] + """old style""" + def hop(self): # <3.0:[super-on-old-class] + """hop""" + super(Aaaa, self).hop() + + def __init__(self): # <3.0:[super-on-old-class] + super(Aaaa, self).__init__() + +class NewAaaa(object): + """old style""" + def hop(self): + """hop""" + super(NewAaaa, self).hop() + + def __init__(self): + super(object, self).__init__() # [bad-super-call] + +class Py3kAaaa(NewAaaa): + """new style""" + def __init__(self): + super().__init__() # <3.0:[missing-super-argument] + +class Py3kWrongSuper(Py3kAaaa): + """new style""" + def __init__(self): + super(NewAaaa, self).__init__() # [bad-super-call] + +class WrongNameRegression(Py3kAaaa): + """ test a regression with the message """ + def __init__(self): + super(Missing, self).__init__() # [bad-super-call] + +class Getattr(object): + """ crash """ + name = NewAaaa + +class CrashSuper(object): + """ test a crash with this checker """ + def __init__(self): + super(Getattr.name, self).__init__() # [bad-super-call] diff --git a/test/functional/super_checks.txt b/test/functional/super_checks.txt new file mode 100644 index 0000000..2d69098 --- /dev/null +++ b/test/functional/super_checks.txt @@ -0,0 +1,8 @@ +old-style-class:6:Aaaa:Old-style class defined. +super-on-old-class:8:Aaaa.hop:Use of super on an old style class +super-on-old-class:12:Aaaa.__init__:Use of super on an old style class +bad-super-call:22:NewAaaa.__init__:Bad first argument 'object' given to super() +missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super() +bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super() +bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super() +bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super() diff --git a/test/functional/uninferable_all_object.py b/test/functional/uninferable_all_object.py new file mode 100644 index 0000000..3e565f9 --- /dev/null +++ b/test/functional/uninferable_all_object.py @@ -0,0 +1,9 @@ +"""Test that non-inferable __all__ variables do not make Pylint crash.""" + +__all__ = sorted([ + 'Dummy', + 'NonExistant', + 'path', + 'func', + 'inner', + 'InnerKlass']) diff --git a/test/input/func___name___access.py b/test/input/func___name___access.py deleted file mode 100644 index def8674..0000000 --- a/test/input/func___name___access.py +++ /dev/null @@ -1,21 +0,0 @@ -# pylint: disable=R0903,W0142 -"""test access to __name__ gives undefined member on new/old class instances -but not on new/old class object -""" - -__revision__ = 1 - -class Aaaa: - """old class""" - def __init__(self): - print self.__name__ - print self.__class__.__name__ -class NewClass(object): - """new class""" - - def __new__(cls, *args, **kwargs): - print 'new', cls.__name__ - return object.__new__(cls, *args, **kwargs) - - def __init__(self): - print 'init', self.__name__ diff --git a/test/input/func_all.py b/test/input/func_all.py deleted file mode 100644 index 0fd75dc..0000000 --- a/test/input/func_all.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Test Pylint's use of __all__. - -* NonExistant is not defined in this module, and it is listed in - __all__. An error is expected. - -* This module imports path and republished it in __all__. No errors - are expected. -""" -# pylint: disable=R0903,R0201,W0612 - -__revision__ = 0 - -from os import path -from collections import deque - -__all__ = [ - 'Dummy', - 'NonExistant', - 'path', - 'func', - 'inner', - 'InnerKlass', deque.__name__] - - -class Dummy(object): - """A class defined in this module.""" - pass - -DUMMY = Dummy() - -def function(): - """Function docstring - """ - pass - -function() - -class Klass(object): - """A klass which contains a function""" - def func(self): - """A klass method""" - inner = None - - class InnerKlass(object): - """A inner klass""" - pass diff --git a/test/input/func_all_undefined.py b/test/input/func_all_undefined.py deleted file mode 100644 index 4d2301d..0000000 --- a/test/input/func_all_undefined.py +++ /dev/null @@ -1,8 +0,0 @@ -"""Test that non-inferable __all__ variables do not make Pylint crash. - -""" -# pylint: disable=R0903,R0201,W0612 - -__revision__ = 0 - -__all__ = [SomeUndefinedName] diff --git a/test/input/func_arguments.py b/test/input/func_arguments.py deleted file mode 100644 index b607699..0000000 --- a/test/input/func_arguments.py +++ /dev/null @@ -1,100 +0,0 @@ -"""Test function argument checker""" -__revision__ = '' - -def decorator(fun): - """Decorator""" - return fun - - -class DemoClass(object): - """Test class for method invocations.""" - - @staticmethod - def static_method(arg): - """static method.""" - return arg + arg - - @classmethod - def class_method(cls, arg): - """class method""" - return arg + arg - - def method(self, arg): - """method.""" - return (self, arg) - - @decorator - def decorated_method(self, arg): - """decorated method.""" - return (self, arg) - - -def function_1_arg(first_argument): - """one argument function""" - return first_argument - -def function_3_args(first_argument, second_argument, third_argument): - """three arguments function""" - return first_argument, second_argument, third_argument - -def function_default_arg(one=1, two=2): - """fonction with default value""" - return two, one - - -function_1_arg(420) -function_1_arg() -function_1_arg(1337, 347) - -function_3_args(420, 789) -function_3_args() -function_3_args(1337, 347, 456) -function_3_args('bab', 'bebe', None, 5.6) - -function_default_arg(1, two=5) -function_default_arg(two=5) -# repeated keyword is syntax error in python >= 2.6: -# tests are moved to func_keyword_repeat_py25- / func_keyword_repeat_py26 - -function_1_arg(bob=4) -function_default_arg(1, 4, coin="hello") - -function_default_arg(1, one=5) - -# Remaining tests are for coverage of correct names in messages. -LAMBDA = lambda arg: 1 - -LAMBDA() - -def method_tests(): - """"Method invocations.""" - demo = DemoClass() - demo.static_method() - DemoClass.static_method() - - demo.class_method() - DemoClass.class_method() - - demo.method() - DemoClass.method(demo) - - demo.decorated_method() - DemoClass.decorated_method(demo) - -# Test a regression (issue #234) -import sys - -# pylint: disable=too-few-public-methods -class Text(object): - """ Regression """ - - if sys.version_info > (3,): - def __new__(cls): - """ empty """ - return object.__new__(cls) - else: - def __new__(cls): - """ empty """ - return object.__new__(cls) - -Text() diff --git a/test/input/func_class_access_protected_members.py b/test/input/func_class_access_protected_members.py deleted file mode 100644 index f2ad5b7..0000000 --- a/test/input/func_class_access_protected_members.py +++ /dev/null @@ -1,36 +0,0 @@ -# pylint: disable=R0903, C0111, W0231 -"""test external access to protected class members""" - -__revision__ = '' - -class MyClass(object): - _cls_protected = 5 - - def __init__(self, other): - MyClass._cls_protected = 6 - self._protected = 1 - self.public = other - self.attr = 0 - - def test(self): - self._protected += self._cls_protected - print self.public._haha - - def clsmeth(cls): - cls._cls_protected += 1 - print cls._cls_protected - clsmeth = classmethod(clsmeth) - -class Subclass(MyClass): - - def __init__(self): - MyClass._protected = 5 - -INST = Subclass() -INST.attr = 1 -print INST.attr -INST._protected = 2 -print INST._protected -INST._cls_protected = 3 -print INST._cls_protected - diff --git a/test/input/func_dict_keys.py b/test/input/func_dict_keys.py deleted file mode 100644 index 24c8b1f..0000000 --- a/test/input/func_dict_keys.py +++ /dev/null @@ -1,15 +0,0 @@ -"""Check multiple key definition""" -#pylint: disable=C0103 -__revision__ = 5 - -correct_dict = { - 'tea': 'for two', - 'two': 'for tea', -} - -wrong_dict = { - 'tea': 'for two', - 'two': 'for tea', - 'tea': 'time', - -} diff --git a/test/input/func_exceptions_raise_type_error.py b/test/input/func_exceptions_raise_type_error.py deleted file mode 100644 index 8c414b6..0000000 --- a/test/input/func_exceptions_raise_type_error.py +++ /dev/null @@ -1,14 +0,0 @@ -""" -'E0702': Raising an %s while only classes, instances or string are allowed - -Used when something which is neither a class, an instance or a string is -raised (i.e. a `TypeError` will be raised). -""" - -__revision__ = 1 - -if __revision__: - raise 1 - -if __revision__: - raise None diff --git a/test/input/func_globals.py b/test/input/func_globals.py deleted file mode 100644 index cf58128..0000000 --- a/test/input/func_globals.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -'W0601': ('global variable %s undefined at the module level', - 'Used when a variable is defined through the "global" statement \ - but the variable is not defined in the module scope.'), -'W0602': ('Using global for %s but no assignment is done', - 'Used when a variable is defined through the "global" statement \ - but no assignment to this variable is done.'), -'W0603': ('Using the global statement', # W0121 - 'Used when you use the "global" statement to update a global \ - variable. Pylint just try to discourage this \ - usage. That doesn\'t mean you can not use it !'), -'W0604': ('Using the global statement at the module level', # W0103 - 'Used when you use the "global" statement at the module level \ - since it has no effect'), -""" - -__revision__ = '' - -CONSTANT = 1 - -def fix_contant(value): - """all this is ok, but try not using global ;)""" - global CONSTANT - print CONSTANT - CONSTANT = value -global CSTE # useless -print CSTE # ko - -def other(): - """global behaviour test""" - global HOP - print HOP # ko - -other() - - -def define_constant(): - """ok but somevar is not defined at the module scope""" - global SOMEVAR - SOMEVAR = 2 diff --git a/test/input/func_missing_super_argument_py_30.py b/test/input/func_missing_super_argument_py_30.py deleted file mode 100644 index ec20857..0000000 --- a/test/input/func_missing_super_argument_py_30.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Check missing super argument for Python 2""" - -__revision__ = 0 - -class MyClass(object): - """ New style class """ - def __init__(self): - super().__init__() - \ No newline at end of file diff --git a/test/input/func_newstyle_exceptions.py b/test/input/func_newstyle_exceptions.py deleted file mode 100644 index ee6e60e..0000000 --- a/test/input/func_newstyle_exceptions.py +++ /dev/null @@ -1,37 +0,0 @@ -# pylint: disable=C0103 -"""test pb with exceptions and old/new style classes""" - -__revision__ = 1 - -class OkException(Exception): - """bien bien bien""" - -class BofException: - """mouais""" - -class NewException(object): - """non si py < 2.5 !""" - -def fonctionOk(): - """raise""" - raise OkException('hop') - -def fonctionBof(): - """raise""" - raise BofException('hop') - -def fonctionNew(): - """raise""" - raise NewException() - -def fonctionBof2(): - """raise""" - raise BofException, 'hop' - -def fonctionNew2(): - """raise""" - raise NewException - -def fonctionNotImplemented(): - """raise""" - raise NotImplemented, 'hop' diff --git a/test/input/func_newstyle_property.py b/test/input/func_newstyle_property.py deleted file mode 100644 index 84a07fc..0000000 --- a/test/input/func_newstyle_property.py +++ /dev/null @@ -1,48 +0,0 @@ -# pylint: disable=R0903 -"""test property on old style class and property.setter/deleter usage""" - -__revision__ = 1 - -def getter(self): - """interesting""" - return self - -class OkOk(object): - """correct usage""" - method = property(getter, doc='hop') - -class HaNonNonNon: - """bad usage""" - method = property(getter, doc='hop') - - def __init__(self): - pass - -import logilab.common.decorators - -class SomeClass(object): - """another docstring""" - - def __init__(self): - self._prop = None - - @property - def prop(self): - """I'm the 'prop' property.""" - return self._prop - - @prop.setter - def prop(self, value): - """I'm the 'prop' property.""" - self._prop = value - - @prop.deleter - def prop(self): - """I'm the 'prop' property.""" - del self._prop - - # test regression - @logilab.common.decorators.cached - def noregr(self): - """used to crash in redefined_by_decorator""" - return self.prop diff --git a/test/input/func_newstyle_super.py b/test/input/func_newstyle_super.py deleted file mode 100644 index 10e9b28..0000000 --- a/test/input/func_newstyle_super.py +++ /dev/null @@ -1,47 +0,0 @@ -# pylint: disable=R0903,import-error -"""check use of super""" - -from unknown import Missing -__revision__ = None - -class Aaaa: - """old style""" - def hop(self): - """hop""" - super(Aaaa, self).hop() - - def __init__(self): - super(Aaaa, self).__init__() - -class NewAaaa(object): - """old style""" - def hop(self): - """hop""" - super(NewAaaa, self).hop() - - def __init__(self): - super(object, self).__init__() - -class Py3kAaaa(NewAaaa): - """new style""" - def __init__(self): - super().__init__() - -class Py3kWrongSuper(Py3kAaaa): - """new style""" - def __init__(self): - super(NewAaaa, self).__init__() - -class WrongNameRegression(Py3kAaaa): - """ test a regression with the message """ - def __init__(self): - super(Missing, self).__init__() - -class Getattr(object): - """ crash """ - name = NewAaaa - -class CrashSuper(object): - """ test a crash with this checker """ - def __init__(self): - super(Getattr.name, self).__init__() diff --git a/test/input/func_noerror_all_no_inference.py b/test/input/func_noerror_all_no_inference.py deleted file mode 100644 index d3af45c..0000000 --- a/test/input/func_noerror_all_no_inference.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Test that non-inferable __all__ variables do not make Pylint crash. - -""" -# pylint: disable=R0903,R0201,W0612 - -__revision__ = 0 - -__all__ = sorted([ - 'Dummy', - 'NonExistant', - 'path', - 'func', - 'inner', - 'InnerKlass']) diff --git a/test/messages/func___name___access.txt b/test/messages/func___name___access.txt deleted file mode 100644 index 4351425..0000000 --- a/test/messages/func___name___access.txt +++ /dev/null @@ -1,4 +0,0 @@ -C: 8:Aaaa: Old-style class defined. -E: 11:Aaaa.__init__: Instance of 'Aaaa' has no '__name__' member -E: 21:NewClass.__init__: Instance of 'NewClass' has no '__name__' member - diff --git a/test/messages/func___name___access_py30.txt b/test/messages/func___name___access_py30.txt deleted file mode 100644 index 51aeeaa..0000000 --- a/test/messages/func___name___access_py30.txt +++ /dev/null @@ -1,3 +0,0 @@ -E: 11:Aaaa.__init__: Instance of 'Aaaa' has no '__name__' member -E: 21:NewClass.__init__: Instance of 'NewClass' has no '__name__' member - diff --git a/test/messages/func_all.txt b/test/messages/func_all.txt deleted file mode 100644 index fb314a7..0000000 --- a/test/messages/func_all.txt +++ /dev/null @@ -1,4 +0,0 @@ -E: 18: Undefined variable name 'NonExistant' in __all__ -E: 20: Undefined variable name 'func' in __all__ -E: 21: Undefined variable name 'inner' in __all__ -E: 22: Undefined variable name 'InnerKlass' in __all__ diff --git a/test/messages/func_all_undefined.txt b/test/messages/func_all_undefined.txt deleted file mode 100644 index f4170f2..0000000 --- a/test/messages/func_all_undefined.txt +++ /dev/null @@ -1 +0,0 @@ -E: 8: Undefined variable 'SomeUndefinedName' diff --git a/test/messages/func_arguments.txt b/test/messages/func_arguments.txt deleted file mode 100644 index e930b20..0000000 --- a/test/messages/func_arguments.txt +++ /dev/null @@ -1,20 +0,0 @@ -E: 46: No value for argument 'first_argument' in function call -E: 47: Too many positional arguments for function call -E: 49: No value for argument 'third_argument' in function call -E: 50: No value for argument 'first_argument' in function call -E: 50: No value for argument 'second_argument' in function call -E: 50: No value for argument 'third_argument' in function call -E: 52: Too many positional arguments for function call -E: 59: No value for argument 'first_argument' in function call -E: 59: Unexpected keyword argument 'bob' in function call -E: 60: Unexpected keyword argument 'coin' in function call -E: 62: Argument 'one' passed by position and keyword in function call -E: 67: No value for argument 'arg' in lambda call -E: 72:method_tests: No value for argument 'arg' in staticmethod call -E: 73:method_tests: No value for argument 'arg' in staticmethod call -E: 75:method_tests: No value for argument 'arg' in classmethod call -E: 76:method_tests: No value for argument 'arg' in classmethod call -E: 78:method_tests: No value for argument 'arg' in method call -E: 79:method_tests: No value for argument 'arg' in unbound method call -E: 81:method_tests: No value for argument 'arg' in method call -E: 82:method_tests: No value for argument 'arg' in unbound method call diff --git a/test/messages/func_class_access_protected_members.txt b/test/messages/func_class_access_protected_members.txt deleted file mode 100644 index 5900960..0000000 --- a/test/messages/func_class_access_protected_members.txt +++ /dev/null @@ -1,5 +0,0 @@ -W: 17:MyClass.test: Access to a protected member _haha of a client class -W: 32: Access to a protected member _protected of a client class -W: 33: Access to a protected member _protected of a client class -W: 34: Access to a protected member _cls_protected of a client class -W: 35: Access to a protected member _cls_protected of a client class \ No newline at end of file diff --git a/test/messages/func_dict_keys.txt b/test/messages/func_dict_keys.txt deleted file mode 100644 index 8773298..0000000 --- a/test/messages/func_dict_keys.txt +++ /dev/null @@ -1 +0,0 @@ -W: 10: Duplicate key 'tea' in dictionary diff --git a/test/messages/func_exceptions_raise_type_error.txt b/test/messages/func_exceptions_raise_type_error.txt deleted file mode 100644 index 349b9f5..0000000 --- a/test/messages/func_exceptions_raise_type_error.txt +++ /dev/null @@ -1,2 +0,0 @@ -E: 11: Raising int while only classes, instances or string are allowed -E: 14: Raising NoneType while only classes, instances or string are allowed diff --git a/test/messages/func_globals.txt b/test/messages/func_globals.txt deleted file mode 100644 index d1bb53d..0000000 --- a/test/messages/func_globals.txt +++ /dev/null @@ -1,6 +0,0 @@ -E: 27: Undefined variable 'CSTE' -E: 32:other: Undefined variable 'HOP' -W: 23:fix_contant: Using the global statement -W: 26: Using the global statement at the module level -W: 31:other: Using global for 'HOP' but no assignment is done -W: 39:define_constant: Global variable 'SOMEVAR' undefined at the module level diff --git a/test/messages/func_missing_super_argument_py_30.txt b/test/messages/func_missing_super_argument_py_30.txt deleted file mode 100644 index 5c97f0d..0000000 --- a/test/messages/func_missing_super_argument_py_30.txt +++ /dev/null @@ -1,2 +0,0 @@ -E: 8:MyClass.__init__: Missing argument to super() -R: 5:MyClass: Too few public methods (0/2) diff --git a/test/messages/func_newstyle_exceptions.txt b/test/messages/func_newstyle_exceptions.txt deleted file mode 100644 index 305326c..0000000 --- a/test/messages/func_newstyle_exceptions.txt +++ /dev/null @@ -1,7 +0,0 @@ -E: 25:fonctionNew: Raising a new style class which doesn't inherit from BaseException -E: 33:fonctionNew2: Raising a new style class which doesn't inherit from BaseException -E: 37:fonctionNotImplemented: NotImplemented raised - should raise NotImplementedError -W: 21:fonctionBof: Exception doesn't inherit from standard "Exception" class -W: 29:fonctionBof2: Exception doesn't inherit from standard "Exception" class -W: 29:fonctionBof2: Use raise ErrorClass(args) instead of raise ErrorClass, args. -W: 37:fonctionNotImplemented: Use raise ErrorClass(args) instead of raise ErrorClass, args. diff --git a/test/messages/func_newstyle_exceptions_py30.txt b/test/messages/func_newstyle_exceptions_py30.txt deleted file mode 100644 index ed4ba4d..0000000 --- a/test/messages/func_newstyle_exceptions_py30.txt +++ /dev/null @@ -1,5 +0,0 @@ -E: 21:fonctionBof: Raising a new style class which doesn't inherit from BaseException -E: 25:fonctionNew: Raising a new style class which doesn't inherit from BaseException -E: 29:fonctionBof2: Raising a new style class which doesn't inherit from BaseException -E: 33:fonctionNew2: Raising a new style class which doesn't inherit from BaseException -E: 37:fonctionNotImplemented: NotImplemented raised - should raise NotImplementedError diff --git a/test/messages/func_newstyle_property.txt b/test/messages/func_newstyle_property.txt deleted file mode 100644 index ba6018f..0000000 --- a/test/messages/func_newstyle_property.txt +++ /dev/null @@ -1,2 +0,0 @@ -C: 14:HaNonNonNon: Old-style class defined. -W: 16:HaNonNonNon: Use of "property" on an old style class diff --git a/test/messages/func_newstyle_property_py30.txt b/test/messages/func_newstyle_property_py30.txt deleted file mode 100644 index e69de29..0000000 diff --git a/test/messages/func_newstyle_super.txt b/test/messages/func_newstyle_super.txt deleted file mode 100644 index ce71293..0000000 --- a/test/messages/func_newstyle_super.txt +++ /dev/null @@ -1,8 +0,0 @@ -C: 7:Aaaa: Old-style class defined. -E: 9:Aaaa.hop: Use of super on an old style class -E: 13:Aaaa.__init__: Use of super on an old style class -E: 23:NewAaaa.__init__: Bad first argument 'object' given to super() -E: 28:Py3kAaaa.__init__: Missing argument to super() -E: 33:Py3kWrongSuper.__init__: Bad first argument 'NewAaaa' given to super() -E: 38:WrongNameRegression.__init__: Bad first argument 'Missing' given to super() -E: 47:CrashSuper.__init__: Bad first argument 'NewAaaa' given to super() \ No newline at end of file diff --git a/test/messages/func_newstyle_super_py30.txt b/test/messages/func_newstyle_super_py30.txt deleted file mode 100644 index ecabca5..0000000 --- a/test/messages/func_newstyle_super_py30.txt +++ /dev/null @@ -1,4 +0,0 @@ -E: 23:NewAaaa.__init__: Bad first argument 'object' given to super() -E: 33:Py3kWrongSuper.__init__: Bad first argument 'NewAaaa' given to super() -E: 38:WrongNameRegression.__init__: Bad first argument 'Missing' given to super() -E: 47:CrashSuper.__init__: Bad first argument 'NewAaaa' given to super() \ No newline at end of file diff --git a/test/test_func.py b/test/test_func.py index 225efc8..887ffe4 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -45,7 +45,9 @@ class LintTestNonExistentModuleTC(LintTestUsingModule): class TestTests(testlib.TestCase): """check that all testable messages have been checked""" PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310', 'E0202', - 'W0711', 'W0108', 'C0112']) + 'W0711', 'W0108', 'E0603', 'W0710', 'E0710', 'E0711', 'W1001', + 'E1124', 'E1120', 'E1121', 'E1123', 'E1003', 'E1002', 'W0212', + 'W0109', 'E1004', 'W0604', 'W0601', 'W0602', 'C0112', 'C0330']) @testlib.tag('coverage') def test_exhaustivity(self): -- cgit v1.2.1