From 4e82b39a1e0e2329de4df11cd79740a5455b7b5d Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Mon, 12 Oct 2015 11:49:03 +0300 Subject: Port more old tests to the new style tests and remove obsolete tests. --- pylint/test/functional/mixed_indentation.py | 10 ++ pylint/test/functional/mixed_indentation.txt | 2 + pylint/test/functional/not_callable.py | 112 +++++++++++++++++++ pylint/test/functional/not_callable.txt | 8 ++ pylint/test/functional/return_outside_function.py | 2 + pylint/test/functional/return_outside_function.txt | 1 + pylint/test/functional/too_many_locals.py | 51 +++++++++ pylint/test/functional/too_many_locals.txt | 4 +- .../test/functional/unrecognized_inline_option.py | 3 + .../test/functional/unrecognized_inline_option.txt | 1 + pylint/test/input/func_e0001_py30.py | 12 --- pylint/test/input/func_e0011.py | 5 - pylint/test/input/func_return_outside_func.py | 3 - .../test/input/func_too_many_locals_arguments.py | 52 --------- .../test/input/func_typecheck_non_callable_call.py | 118 --------------------- pylint/test/input/func_w0312.py | 11 -- pylint/test/messages/func_e0001_py30.txt | 2 - pylint/test/messages/func_e0011.txt | 1 - pylint/test/messages/func_return_outside_func.txt | 1 - .../messages/func_too_many_locals_arguments.txt | 2 - 20 files changed, 193 insertions(+), 208 deletions(-) create mode 100644 pylint/test/functional/mixed_indentation.py create mode 100644 pylint/test/functional/mixed_indentation.txt create mode 100644 pylint/test/functional/not_callable.py create mode 100644 pylint/test/functional/not_callable.txt create mode 100644 pylint/test/functional/return_outside_function.py create mode 100644 pylint/test/functional/return_outside_function.txt create mode 100644 pylint/test/functional/unrecognized_inline_option.py create mode 100644 pylint/test/functional/unrecognized_inline_option.txt delete mode 100644 pylint/test/input/func_e0001_py30.py delete mode 100644 pylint/test/input/func_e0011.py delete mode 100644 pylint/test/input/func_return_outside_func.py delete mode 100644 pylint/test/input/func_too_many_locals_arguments.py delete mode 100644 pylint/test/input/func_typecheck_non_callable_call.py delete mode 100644 pylint/test/input/func_w0312.py delete mode 100644 pylint/test/messages/func_e0001_py30.txt delete mode 100644 pylint/test/messages/func_e0011.txt delete mode 100644 pylint/test/messages/func_return_outside_func.txt delete mode 100644 pylint/test/messages/func_too_many_locals_arguments.txt diff --git a/pylint/test/functional/mixed_indentation.py b/pylint/test/functional/mixed_indentation.py new file mode 100644 index 0000000..724ecff --- /dev/null +++ b/pylint/test/functional/mixed_indentation.py @@ -0,0 +1,10 @@ +"""test mixed tabs and spaces""" +from __future__ import print_function + +def spaces_func(): + """yo""" + print("yo") + +def tab_func(): + """yo""" # [mixed-indentation] + print("yo") # [mixed-indentation] diff --git a/pylint/test/functional/mixed_indentation.txt b/pylint/test/functional/mixed_indentation.txt new file mode 100644 index 0000000..d4857e6 --- /dev/null +++ b/pylint/test/functional/mixed_indentation.txt @@ -0,0 +1,2 @@ +mixed-indentation:9::Found indentation with tabs instead of spaces +mixed-indentation:10::Found indentation with tabs instead of spaces diff --git a/pylint/test/functional/not_callable.py b/pylint/test/functional/not_callable.py new file mode 100644 index 0000000..c2a3ab4 --- /dev/null +++ b/pylint/test/functional/not_callable.py @@ -0,0 +1,112 @@ +# pylint: disable=missing-docstring,no-self-use,too-few-public-methods + +REVISION = None + +REVISION() # [not-callable] + +def correct(): + return 1 + +REVISION = correct() + +class Correct(object): + """callable object""" + +class MetaCorrect(object): + """callable object""" + def __call__(self): + return self + +INSTANCE = Correct() +CALLABLE_INSTANCE = MetaCorrect() +CORRECT = CALLABLE_INSTANCE() +INCORRECT = INSTANCE() # [not-callable] +LIST = [] +INCORRECT = LIST() # [not-callable] +DICT = {} +INCORRECT = DICT() # [not-callable] +TUPLE = () +INCORRECT = TUPLE() # [not-callable] +INT = 1 +INCORRECT = INT() # [not-callable] + +# Test calling properties. Pylint can detect when using only the +# getter, but it doesn't infer properly when having a getter +# and a setter. +class MyProperty(property): + """ test subclasses """ + +class PropertyTest(object): + """ class """ + + def __init__(self): + self.attr = 4 + + @property + def test(self): + """ Get the attribute """ + return self.attr + + @test.setter + def test(self, value): + """ Set the attribute """ + self.attr = value + + @MyProperty + def custom(self): + """ Get the attribute """ + return self.attr + + @custom.setter + def custom(self, value): + """ Set the attribute """ + self.attr = value + +PROP = PropertyTest() +PROP.test(40) # [not-callable] +PROP.custom() # [not-callable] + +# Safe from not-callable when using properties. + +class SafeProperty(object): + @property + def static(self): + return staticmethod + + @property + def klass(self): + return classmethod + + @property + def get_lambda(self): + return lambda: None + + @property + def other_function(self): + def function(arg): + return arg + return function + + @property + def dict_builtin(self): + return dict + + @property + def range_builtin(self): + return range + + @property + def instance(self): + class Empty(object): + def __call__(self): + return 42 + return Empty() + +PROP1 = SafeProperty() +PROP1.static(2) +PROP1.klass(2) +PROP1.get_lambda() +PROP1.other_function(4) +PROP1.dict_builtin() +PROP1.range_builtin(4) +PROP1.instance() diff --git a/pylint/test/functional/not_callable.txt b/pylint/test/functional/not_callable.txt new file mode 100644 index 0000000..4928c8c --- /dev/null +++ b/pylint/test/functional/not_callable.txt @@ -0,0 +1,8 @@ +not-callable:5::REVISION is not callable +not-callable:23::INSTANCE is not callable +not-callable:25::LIST is not callable +not-callable:27::DICT is not callable +not-callable:29::TUPLE is not callable +not-callable:31::INT is not callable +not-callable:66::PROP.test is not callable +not-callable:67::PROP.custom is not callable \ No newline at end of file diff --git a/pylint/test/functional/return_outside_function.py b/pylint/test/functional/return_outside_function.py new file mode 100644 index 0000000..449dafd --- /dev/null +++ b/pylint/test/functional/return_outside_function.py @@ -0,0 +1,2 @@ +"""This is gramatically correct, but it's still a SyntaxError""" +return # [return-outside-function] diff --git a/pylint/test/functional/return_outside_function.txt b/pylint/test/functional/return_outside_function.txt new file mode 100644 index 0000000..0c9aa56 --- /dev/null +++ b/pylint/test/functional/return_outside_function.txt @@ -0,0 +1 @@ +return-outside-function:2::Return outside function \ No newline at end of file diff --git a/pylint/test/functional/too_many_locals.py b/pylint/test/functional/too_many_locals.py index 56ed514..ac38a9e 100644 --- a/pylint/test/functional/too_many_locals.py +++ b/pylint/test/functional/too_many_locals.py @@ -7,3 +7,54 @@ def function(arg1, arg2, arg3, arg4, arg5): # [too-many-locals] loc1, loc2, loc3, loc4, loc5, loc6, loc7 = arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 print(loc1, loc2, loc3, loc4, loc5, loc6, loc7) + + +def too_many_locals_function(): # [too-many-locals] + """pylint will complains about too many local variables""" + args0 = 0 + args1 = args0 * 1 + args2 = args1 * 2 + args3 = args2 * 3 + args4 = args3 * 4 + args5 = args4 * 5 + args6 = args5 * 6 + args7 = args6 * 7 + args8 = args7 * 8 + args9 = args8 * 9 + args10 = args9 * 10 + args11 = args10 * 11 + args12 = args11 * 12 + args13 = args12 * 13 + args14 = args13 * 14 + args15 = args14 * 15 + return args15 + +def too_many_arguments_function(arga, argu, argi, arge, argt, args): # [too-many-arguments] + """pylint will complains about too many arguments.""" + arga = argu + arga += argi + arga += arge + arga += argt + arga += args + return arga + +def ignored_arguments_function(arga, argu, argi, + _arge=0, _argt=1, _args=None): + """pylint will ignore _arge, _argt, _args. + + Consequently pylint will only coun 13 arguments. + """ + arg0 = 0 + arg1 = arg0 * 1 + arga + arg2 = arg1 * 2 + argu + arg3 = arg2 * 3 + argi + arg4 = arg3 * 4 + _arge + arg5 = arg4 * 5 + _argt + arg6 = arg5 * 6 + arg7 = arg6 * 7 + arg8 = arg7 * 8 + arg9 = arg8 * 9 + arg9 += arg0 + if _args: + arg9 += sum(_args) + return arg9 diff --git a/pylint/test/functional/too_many_locals.txt b/pylint/test/functional/too_many_locals.txt index b94c307..4a7d19d 100644 --- a/pylint/test/functional/too_many_locals.txt +++ b/pylint/test/functional/too_many_locals.txt @@ -1 +1,3 @@ -too-many-locals:4:function:Too many local variables (16/15) \ No newline at end of file +too-many-locals:4:function:Too many local variables (16/15) +too-many-locals:12:too_many_locals_function:Too many local variables (16/15) +too-many-arguments:32:too_many_arguments_function:Too many arguments (6/5) \ No newline at end of file diff --git a/pylint/test/functional/unrecognized_inline_option.py b/pylint/test/functional/unrecognized_inline_option.py new file mode 100644 index 0000000..3163b1e --- /dev/null +++ b/pylint/test/functional/unrecognized_inline_option.py @@ -0,0 +1,3 @@ +# +1: [unrecognized-inline-option] +# pylint:bouboule=1 +"""Check unknown option""" diff --git a/pylint/test/functional/unrecognized_inline_option.txt b/pylint/test/functional/unrecognized_inline_option.txt new file mode 100644 index 0000000..922cc92 --- /dev/null +++ b/pylint/test/functional/unrecognized_inline_option.txt @@ -0,0 +1 @@ +unrecognized-inline-option:2::"Unrecognized file option 'bouboule'" diff --git a/pylint/test/input/func_e0001_py30.py b/pylint/test/input/func_e0001_py30.py deleted file mode 100644 index 9c1b727..0000000 --- a/pylint/test/input/func_e0001_py30.py +++ /dev/null @@ -1,12 +0,0 @@ -"""test string exception -""" - -__revision__ = '' - -def function1(): - """hehehe""" - raise "String Exception" - -def function2(): - """hehehe""" - raise 'exception', 'message' diff --git a/pylint/test/input/func_e0011.py b/pylint/test/input/func_e0011.py deleted file mode 100644 index f2bb592..0000000 --- a/pylint/test/input/func_e0011.py +++ /dev/null @@ -1,5 +0,0 @@ -# pylint:bouboule=1 -"""check unknown option -""" -__revision__ = 1 - diff --git a/pylint/test/input/func_return_outside_func.py b/pylint/test/input/func_return_outside_func.py deleted file mode 100644 index 440798d..0000000 --- a/pylint/test/input/func_return_outside_func.py +++ /dev/null @@ -1,3 +0,0 @@ -"""This is gramatically correct, but it's still a SyntaxError""" -__revision__ = None -return diff --git a/pylint/test/input/func_too_many_locals_arguments.py b/pylint/test/input/func_too_many_locals_arguments.py deleted file mode 100644 index f63a5ee..0000000 --- a/pylint/test/input/func_too_many_locals_arguments.py +++ /dev/null @@ -1,52 +0,0 @@ -"""tests number of arguments and local variables in functions -""" - -__revision__ = None - -def too_many_locals_function(): - '''pylint will complains about too many local variables''' - args0 = 0 - args1 = args0 * 1 - args2 = args1 * 2 - args3 = args2 * 3 - args4 = args3 * 4 - args5 = args4 * 5 - args6 = args5 * 6 - args7 = args6 * 7 - args8 = args7 * 8 - args9 = args8 * 9 - args10 = args9 * 10 - args11 = args10 * 11 - args12 = args11 * 12 - args13 = args12 * 13 - args14 = args13 * 14 - args15 = args14 * 15 - return args15 - -def too_many_arguments_function(arga, argu, argi, arge, argt, args): - '''pylint will complains about too many arguments.''' - arga = argu - arga += argi - arga += arge - arga += argt - arga += args - return arga - -def ignored_arguments_function(arga, argu, argi, - _arge=0, _argt=1, _args=None): - '''pylint will ignore _arge, _argt, _args. - Consequently pylint will only coun 13 arguments''' - arg0 = 0 - arg1 = arg0 * 1 + arga - arg2 = arg1 * 2 + argu - arg3 = arg2 * 3 + argi - arg4 = arg3 * 4 + _arge - arg5 = arg4 * 5 + _argt - arg6 = arg5 * 6 - arg7 = arg6 * 7 - arg8 = arg7 * 8 - arg9 = arg8 * 9 - arg9 += arg0 - if _args: - arg9 += sum(_args) - return arg9 diff --git a/pylint/test/input/func_typecheck_non_callable_call.py b/pylint/test/input/func_typecheck_non_callable_call.py deleted file mode 100644 index 832657d..0000000 --- a/pylint/test/input/func_typecheck_non_callable_call.py +++ /dev/null @@ -1,118 +0,0 @@ -# pylint: disable=R0903,missing-docstring,no-self-use -""" - 'E1102': ('%s is not callable', - 'Used when an object being called has been infered to a non \ - callable object'), -""" - -__revision__ = None - -__revision__() - -def correct(): - """callable object""" - return 1 - -__revision__ = correct() - -class Correct(object): - """callable object""" - -class MetaCorrect(object): - """callable object""" - def __call__(self): - return self - -INSTANCE = Correct() -CALLABLE_INSTANCE = MetaCorrect() -CORRECT = CALLABLE_INSTANCE() -INCORRECT = INSTANCE() -LIST = [] -INCORRECT = LIST() -DICT = {} -INCORRECT = DICT() -TUPLE = () -INCORRECT = TUPLE() -INT = 1 -INCORRECT = INT() - -# Test calling properties. Pylint can detect when using only the -# getter, but it doesn't infer properly when having a getter -# and a setter. -class MyProperty(property): - """ test subclasses """ - -class PropertyTest(object): - """ class """ - - def __init__(self): - self.attr = 4 - - @property - def test(self): - """ Get the attribute """ - return self.attr - - @test.setter - def test(self, value): - """ Set the attribute """ - self.attr = value - - @MyProperty - def custom(self): - """ Get the attribute """ - return self.attr - - @custom.setter - def custom(self, value): - """ Set the attribute """ - self.attr = value - -PROP = PropertyTest() -PROP.test(40) -PROP.custom() - -# Safe from not-callable when using properties. - -class SafeProperty(object): - @property - def static(self): - return staticmethod - - @property - def klass(self): - return classmethod - - @property - def get_lambda(self): - return lambda: None - - @property - def other_function(self): - def function(arg): - return arg - return function - - @property - def dict_builtin(self): - return dict - - @property - def range_builtin(self): - return range - - @property - def instance(self): - class Empty(object): - def __call__(self): - return 42 - return Empty() - -PROP1 = SafeProperty() -PROP1.static(2) -PROP1.klass(2) -PROP1.get_lambda() -PROP1.other_function(4) -PROP1.dict_builtin() -PROP1.range_builtin(4) -PROP1.instance() diff --git a/pylint/test/input/func_w0312.py b/pylint/test/input/func_w0312.py deleted file mode 100644 index 491f75b..0000000 --- a/pylint/test/input/func_w0312.py +++ /dev/null @@ -1,11 +0,0 @@ -"""test mixed tabs and spaces""" -from __future__ import print_function -__revision__ = 1 - -def spaces_func(): - """yo""" - print("yo") - -def tab_func(): - """yo""" - print("yo") diff --git a/pylint/test/messages/func_e0001_py30.txt b/pylint/test/messages/func_e0001_py30.txt deleted file mode 100644 index 1cf05ca..0000000 --- a/pylint/test/messages/func_e0001_py30.txt +++ /dev/null @@ -1,2 +0,0 @@ -E: 12: invalid syntax - diff --git a/pylint/test/messages/func_e0011.txt b/pylint/test/messages/func_e0011.txt deleted file mode 100644 index 55f07b1..0000000 --- a/pylint/test/messages/func_e0011.txt +++ /dev/null @@ -1 +0,0 @@ -E: 1: Unrecognized file option 'bouboule' diff --git a/pylint/test/messages/func_return_outside_func.txt b/pylint/test/messages/func_return_outside_func.txt deleted file mode 100644 index e61be76..0000000 --- a/pylint/test/messages/func_return_outside_func.txt +++ /dev/null @@ -1 +0,0 @@ -E: 3: Return outside function diff --git a/pylint/test/messages/func_too_many_locals_arguments.txt b/pylint/test/messages/func_too_many_locals_arguments.txt deleted file mode 100644 index 8f236c2..0000000 --- a/pylint/test/messages/func_too_many_locals_arguments.txt +++ /dev/null @@ -1,2 +0,0 @@ -R: 6:too_many_locals_function: Too many local variables (16/15) -R: 26:too_many_arguments_function: Too many arguments (6/5) -- cgit v1.2.1