diff options
| author | Michal Nowikowski <godfryd@gmail.com> | 2014-07-25 18:03:11 +0200 |
|---|---|---|
| committer | Michal Nowikowski <godfryd@gmail.com> | 2014-07-25 18:03:11 +0200 |
| commit | c3f867c4c0a014dd8cd79b05b0f0cd974016a8d1 (patch) | |
| tree | 4863911b60a55aee8d827b671cfb34029243fc13 /test | |
| parent | 9c6402d7787891d749b36accc9bd61cc0ae1afc6 (diff) | |
| parent | 997937528f8a1946f4a528ad040139f6ec384a79 (diff) | |
| download | pylint-c3f867c4c0a014dd8cd79b05b0f0cd974016a8d1.tar.gz | |
merge
Diffstat (limited to 'test')
31 files changed, 263 insertions, 287 deletions
diff --git a/test/input/func_bad_continuation.py b/test/functional/bad_continuation.py index f303915..3d62521 100644 --- a/test/input/func_bad_continuation.py +++ b/test/functional/bad_continuation.py @@ -1,7 +1,5 @@ """Regression test case for bad-continuation.""" -__revision__ = 1 - # Various alignment for brackets LIST0 = [ 1, 2, 3 @@ -39,7 +37,7 @@ W2 = ['some', 'contents' # with a continued comment that may be aligned 'and', 'more', # but this # [bad-continuation] is not accepted - 'contents', # nor this. [bad-continuation] + 'contents', # [bad-continuation] nor this. ] # Values in dictionaries should be indented 4 spaces further if they are on a @@ -108,7 +106,7 @@ def continue3( """A function with misaligned arguments""" print some_arg, some_other_arg -def continue4( +def continue4( # pylint:disable=missing-docstring arg1, arg2): print arg1, arg2 diff --git a/test/functional/bad_continuation.txt b/test/functional/bad_continuation.txt new file mode 100644 index 0000000..732858e --- /dev/null +++ b/test/functional/bad_continuation.txt @@ -0,0 +1,63 @@ +bad-continuation:12::Wrong hanging indentation. + ] # [bad-continuation] +| ^| +bad-continuation:17::Wrong continued indentation. + 7, # [bad-continuation] + | ^ +bad-continuation:25::Wrong hanging indentation. + 'b': 2, # [bad-continuation] + ^| +bad-continuation:31::Wrong hanging indentation. + 'b': 2, # [bad-continuation] + ^| +bad-continuation:39::Wrong continued indentation. + # [bad-continuation] is not accepted + | | ^ +bad-continuation:40::Wrong continued indentation. + 'contents', # [bad-continuation] nor this. + | ^ +bad-continuation:49::Wrong hanging indentation in dict value. + 'value2', # [bad-continuation] + | ^ | +bad-continuation:59::Wrong continued indentation. + 'wrong', # [bad-continuation] + ^ | +bad-continuation:83::Wrong hanging indentation in dict value. +'value1', # [bad-continuation] +^ | | +bad-continuation:87::Wrong hanging indentation in dict value. + 'value1', # [bad-continuation] + ^ | | +bad-continuation:104::Wrong hanging indentation before block. + some_arg, # [bad-continuation] + ^ | +bad-continuation:105::Wrong hanging indentation before block. + some_other_arg): # [bad-continuation] + ^ | +bad-continuation:125::Wrong continued indentation. + "b") # [bad-continuation] + ^ | +bad-continuation:139::Wrong hanging indentation before block. + ): pass # [bad-continuation] +| ^| +bad-continuation:142::Wrong continued indentation before block. + 2): # [bad-continuation] + ^ | +bad-continuation:150::Wrong continued indentation. + 2 and # [bad-continuation] + | ^ +bad-continuation:155::Wrong hanging indentation before block. + 2): pass # [bad-continuation] + ^ | | +bad-continuation:162::Wrong continued indentation before block. + 2 or # [bad-continuation] + |^ | +bad-continuation:166::Wrong continued indentation before block. + 2): pass # [bad-continuation] + ^ | | +bad-continuation:172::Wrong hanging indentation before block. + 2): # [bad-continuation] + ^ | | +bad-continuation:183::Wrong continued indentation. + 2): # [bad-continuation] + ^ | diff --git a/test/input/func_loopvar_in_closure.py b/test/functional/cellvar_escaping_loop.py index 3a791d3..316bc47 100644 --- a/test/input/func_loopvar_in_closure.py +++ b/test/functional/cellvar_escaping_loop.py @@ -1,8 +1,5 @@ """Tests for loopvar-in-closure.""" -__revision__ = 0 - - def good_case(): """No problems here.""" lst = [] @@ -18,7 +15,7 @@ def good_case2(): def good_case3(): """No problems here.""" lst = [] - for i in range(10): + for i in range(10): # [unused-variable] lst.append(lambda i=i: i) @@ -42,7 +39,7 @@ def good_case6(): the value will not change any more.""" for i in range(10): print i - return lambda: i + return lambda: i # [undefined-loop-variable] def good_case7(): @@ -75,12 +72,12 @@ def bad_case(): lst = [] for i in range(10): print i - lst.append(lambda: i) + lst.append(lambda: i) # [cell-var-from-loop] def bad_case2(): """Closing over a loop variable.""" - return [lambda: i for i in range(10)] + return [lambda: i for i in range(10)] # [cell-var-from-loop] def bad_case3(): @@ -88,7 +85,7 @@ def bad_case3(): lst = [] for i in range(10): j = i * i - lst.append(lambda: j) + lst.append(lambda: j) # [cell-var-from-loop] return lst @@ -98,7 +95,7 @@ def bad_case4(): for i in range(10): def nested(): """Nested function.""" - return i**2 + return i**2 # [cell-var-from-loop] lst.append(nested) return lst @@ -119,7 +116,7 @@ def bad_case5(): the result is [9] * 10 again. """ - return (lambda: i for i in range(10)) + return (lambda: i for i in range(10)) # [cell-var-from-loop] def bad_case6(): @@ -127,6 +124,5 @@ def bad_case6(): lst = [] for i, j in zip(range(10), range(10, 20)): print j - lst.append(lambda: i) + lst.append(lambda: i) # [cell-var-from-loop] return lst - diff --git a/test/functional/cellvar_escaping_loop.txt b/test/functional/cellvar_escaping_loop.txt new file mode 100644 index 0000000..4448d44 --- /dev/null +++ b/test/functional/cellvar_escaping_loop.txt @@ -0,0 +1,8 @@ +unused-variable:18:good_case3:Unused variable 'i' +undefined-loop-variable:42:good_case6.<lambda>:Using possibly undefined loop variable 'i' +cell-var-from-loop:75:bad_case.<lambda>:Cell variable i defined in loop +cell-var-from-loop:80:bad_case2.<lambda>:Cell variable i defined in loop +cell-var-from-loop:88:bad_case3.<lambda>:Cell variable j defined in loop +cell-var-from-loop:98:bad_case4.nested:Cell variable i defined in loop +cell-var-from-loop:119:bad_case5.<lambda>:Cell variable i defined in loop +cell-var-from-loop:127:bad_case6.<lambda>:Cell variable i defined in loop diff --git a/test/input/func_ctor_arguments.py b/test/functional/ctor_arguments.py index f9a3430..7dc0a09 100644 --- a/test/input/func_ctor_arguments.py +++ b/test/functional/ctor_arguments.py @@ -1,9 +1,9 @@ """Test function argument checker on __init__ -Based on test/input/func_arguments.py +Based on test/functional/arguments.py """ # pylint: disable=C0111,R0903,W0231 -__revision__ = '' + class Class1Arg(object): def __init__(self, first_argument): @@ -32,35 +32,36 @@ class ClassNew(object): return first_argument, kwarg Class1Arg(420) -Class1Arg() -Class1Arg(1337, 347) +Class1Arg() # [no-value-for-parameter] +Class1Arg(1337, 347) # [too-many-function-args] -Class3Arg(420, 789) +Class3Arg(420, 789) # [no-value-for-parameter] +# +1:[no-value-for-parameter,no-value-for-parameter,no-value-for-parameter] Class3Arg() Class3Arg(1337, 347, 456) -Class3Arg('bab', 'bebe', None, 5.6) +Class3Arg('bab', 'bebe', None, 5.6) # [too-many-function-args] ClassDefaultArg(1, two=5) ClassDefaultArg(two=5) -Class1Arg(bob=4) -ClassDefaultArg(1, 4, coin="hello") +Class1Arg(bob=4) # [no-value-for-parameter,unexpected-keyword-arg] +ClassDefaultArg(1, 4, coin="hello") # [unexpected-keyword-arg] -ClassDefaultArg(1, one=5) +ClassDefaultArg(1, one=5) # [redundant-keyword-arg] Subclass1Arg(420) -Subclass1Arg() -Subclass1Arg(1337, 347) +Subclass1Arg() # [no-value-for-parameter] +Subclass1Arg(1337, 347) # [too-many-function-args] ClassAllArgs() ClassAllArgs(1, 2, 3, even=4, more=5) ClassMultiInheritance(1) -ClassMultiInheritance(1, 2, 3) +ClassMultiInheritance(1, 2, 3) # [too-many-function-args] ClassNew(1, kwarg=1) -ClassNew(1, 2, 3) -ClassNew(one=2) +ClassNew(1, 2, 3) # [too-many-function-args] +ClassNew(one=2) # [no-value-for-parameter,unexpected-keyword-arg] class Metaclass(type): diff --git a/test/functional/ctor_arguments.txt b/test/functional/ctor_arguments.txt new file mode 100644 index 0000000..85cf139 --- /dev/null +++ b/test/functional/ctor_arguments.txt @@ -0,0 +1,17 @@ +no-value-for-parameter:35::No value for argument 'first_argument' in constructor call +too-many-function-args:36::Too many positional arguments for constructor call +no-value-for-parameter:38::No value for argument 'third_argument' in constructor call +no-value-for-parameter:40::No value for argument 'first_argument' in constructor call +no-value-for-parameter:40::No value for argument 'second_argument' in constructor call +no-value-for-parameter:40::No value for argument 'third_argument' in constructor call +too-many-function-args:42::Too many positional arguments for constructor call +no-value-for-parameter:47::No value for argument 'first_argument' in constructor call +unexpected-keyword-arg:47::Unexpected keyword argument 'bob' in constructor call +unexpected-keyword-arg:48::Unexpected keyword argument 'coin' in constructor call +redundant-keyword-arg:50::Argument 'one' passed by position and keyword in constructor call +no-value-for-parameter:53::No value for argument 'first_argument' in constructor call +too-many-function-args:54::Too many positional arguments for constructor call +too-many-function-args:60::Too many positional arguments for constructor call +too-many-function-args:63::Too many positional arguments for constructor call +no-value-for-parameter:64::No value for argument 'first_argument' in constructor call +unexpected-keyword-arg:64::Unexpected keyword argument 'one' in constructor call diff --git a/test/functional/exception_is_binary_op.py b/test/functional/exception_is_binary_op.py new file mode 100644 index 0000000..443a478 --- /dev/null +++ b/test/functional/exception_is_binary_op.py @@ -0,0 +1,12 @@ +"""Warn about binary operations used as exceptions.""" + +try: + pass +except Exception or StandardError: # [binary-op-exception] + print "caught1" +except Exception and StandardError: # [binary-op-exception] + print "caught2" +except Exception or StandardError: # [binary-op-exception] + print "caught3" +except (Exception or StandardError), exc: # [binary-op-exception] + print "caught4" diff --git a/test/functional/exception_is_binary_op.txt b/test/functional/exception_is_binary_op.txt new file mode 100644 index 0000000..039bc3f --- /dev/null +++ b/test/functional/exception_is_binary_op.txt @@ -0,0 +1,4 @@ +binary-op-exception:5::Exception to catch is the result of a binary "or" operation +binary-op-exception:7::Exception to catch is the result of a binary "and" operation +binary-op-exception:9::Exception to catch is the result of a binary "or" operation +binary-op-exception:11::Exception to catch is the result of a binary "or" operation diff --git a/test/input/func_e0205.py b/test/functional/method_hidden.py index 34208f9..0510f55 100644 --- a/test/input/func_e0205.py +++ b/test/functional/method_hidden.py @@ -1,9 +1,7 @@ -# pylint: disable=R0903 +# pylint: disable=too-few-public-methods """check method hidding ancestor attribute """ -__revision__ = '' - class Abcd(object): """dummy""" def __init__(self): @@ -11,7 +9,7 @@ class Abcd(object): class Cdef(Abcd): """dummy""" - def abcd(self): + def abcd(self): # [method-hidden] """test """ print self diff --git a/test/functional/method_hidden.txt b/test/functional/method_hidden.txt new file mode 100644 index 0000000..c15f3bc --- /dev/null +++ b/test/functional/method_hidden.txt @@ -0,0 +1 @@ +method-hidden:12:Cdef.abcd:An attribute defined in functional.method_hidden line 8 hides this method diff --git a/test/functional/redefined_builtin.py b/test/functional/redefined_builtin.py new file mode 100644 index 0000000..ace2ea6 --- /dev/null +++ b/test/functional/redefined_builtin.py @@ -0,0 +1,9 @@ +"""Tests for redefining builtins.""" + +def function(): + """Redefined local.""" + type = 1 # [redefined-builtin] + print type + +# pylint:disable=invalid-name +map = {} # [redefined-builtin] diff --git a/test/functional/redefined_builtin.txt b/test/functional/redefined_builtin.txt new file mode 100644 index 0000000..71518ce --- /dev/null +++ b/test/functional/redefined_builtin.txt @@ -0,0 +1,2 @@ +redefined-builtin:5:function:Redefining built-in 'type' +redefined-builtin:9::Redefining built-in 'map' diff --git a/test/input/func_undefined_var.py b/test/functional/undefined_variable.py index fb5fc30..25f0145 100644 --- a/test/input/func_undefined_var.py +++ b/test/functional/undefined_variable.py @@ -1,38 +1,33 @@ -"""test access to undefined variables""" +"""Test warnings about access to undefined variables.""" # pylint: disable=too-few-public-methods, no-init, no-self-use -__revision__ = '$Id:' DEFINED = 1 if DEFINED != 1: - if DEFINED in (unknown, DEFINED): + if DEFINED in (unknown, DEFINED): # [undefined-variable] DEFINED += 1 def in_method(var): """method doc""" - var = nomoreknown + var = nomoreknown # [undefined-variable] assert var -DEFINED = {DEFINED:__revision__} +DEFINED = {DEFINED:__revision__} # [undefined-variable] +# +1:[undefined-variable] DEFINED[__revision__] = OTHER = 'move this is astroid test' OTHER += '$' -def bad_default(var, default=unknown2): +def bad_default(var, default=unknown2): # [undefined-variable] """function with defaut arg's value set to an unexistant name""" print var, default - print xxxx - print xxxx #see story #1000 - augvar += 1 - del vardel - -# Warning for Attribute access to undefinde attributes ? -#class Attrs(object): - #"""dummy class for wrong attribute access""" -#AOU = Attrs() -#AOU.number *= 1.3 -#del AOU.badattr + print xxxx # [undefined-variable] + augvar += 1 # [undefined-variable,unused-variable] + del vardel # [undefined-variable] + +LMBD = lambda x, y=doesnotexist: x+y # [undefined-variable] +LMBD2 = lambda x, y: x+z # [undefined-variable] try: POUET # don't catch me @@ -41,19 +36,19 @@ except NameError: try: POUETT # don't catch me -except Exception: # pylint:disable = W0703 +except Exception: # pylint:disable = broad-except POUETT = 'something' try: POUETTT # don't catch me -except: # pylint:disable = W0702 +except: # pylint:disable = bare-except POUETTT = 'something' print POUET, POUETT, POUETTT try: - PLOUF # catch me + PLOUF # [used-before-assignment] except ValueError: PLOUF = 'something' @@ -62,7 +57,7 @@ print PLOUF def if_branch_test(something): """hop""" if something == 0: - if xxx == 1: + if xxx == 1: # [used-before-assignment] pass else: print xxx @@ -77,30 +72,32 @@ def decorator(arg): @decorator(arg=[i * 2 for i in range(15)]) def func1(): """A function with a decorator that contains a listcomp.""" - pass @decorator(arg=(i * 2 for i in range(15))) def func2(): """A function with a decorator that contains a genexpr.""" - pass + +@decorator(lambda x: x > 0) +def main(): + """A function with a decorator that contains a lambda.""" # Test shared scope. -def test_arguments(arg=TestClass): +def test_arguments(arg=TestClass): # [used-before-assignment] """ TestClass isn't defined yet. """ return arg -class TestClass(Ancestor): +class TestClass(Ancestor): # [used-before-assignment] """ contains another class, which uses an undefined ancestor. """ - class MissingAncestor(Ancestor1): + class MissingAncestor(Ancestor1): # [used-before-assignment] """ no op """ def test1(self): """ It should trigger here, because the two classes have the same scope. """ - class UsingBeforeDefinition(Empty): + class UsingBeforeDefinition(Empty): # [used-before-assignment] """ uses Empty before definition """ class Empty(object): """ no op """ diff --git a/test/functional/undefined_variable.txt b/test/functional/undefined_variable.txt new file mode 100644 index 0000000..5695be1 --- /dev/null +++ b/test/functional/undefined_variable.txt @@ -0,0 +1,17 @@ +undefined-variable:7::Undefined variable 'unknown' +undefined-variable:13:in_method:Undefined variable 'nomoreknown' +undefined-variable:16::Undefined variable '__revision__' +undefined-variable:18::Undefined variable '__revision__' +undefined-variable:22:bad_default:Undefined variable 'unknown2' +undefined-variable:25:bad_default:Undefined variable 'xxxx' +undefined-variable:26:bad_default:Undefined variable 'augvar' +unused-variable:26:bad_default:Unused variable 'augvar' +undefined-variable:27:bad_default:Undefined variable 'vardel' +undefined-variable:29:<lambda>:Undefined variable 'doesnotexist' +undefined-variable:30:<lambda>:Undefined variable 'z' +used-before-assignment:51::Using variable 'PLOUF' before assignment +used-before-assignment:60:if_branch_test:Using variable 'xxx' before assignment +used-before-assignment:86:test_arguments:Using variable 'TestClass' before assignment +used-before-assignment:90:TestClass:Using variable 'Ancestor' before assignment +used-before-assignment:93:TestClass.MissingAncestor:Using variable 'Ancestor1' before assignment +used-before-assignment:100:TestClass.test1.UsingBeforeDefinition:Using variable 'Empty' before assignment diff --git a/test/input/func_w0108.py b/test/functional/unnecessary_lambda.py index 0d4cc62..1c9b424 100644 --- a/test/input/func_w0108.py +++ b/test/functional/unnecessary_lambda.py @@ -1,40 +1,50 @@ -# pylint: disable=W0142 -"""test suspicious lambda expressions -""" - -__revision__ = '' - -# Some simple examples of the most commonly encountered forms. -_ = lambda: list() # replaceable with "list" -_ = lambda x: hash(x) # replaceable with "hash" -_ = lambda x, y: min(x, y) # replaceable with "min" - -# A function that can take any arguments given to it. -_ANYARGS = lambda *args, **kwargs: 'completely arbitrary return value' - -# Some more complex forms of unnecessary lambda expressions. -_ = lambda *args: _ANYARGS(*args) -_ = lambda **kwargs: _ANYARGS(**kwargs) -_ = lambda *args, **kwargs: _ANYARGS(*args, **kwargs) -_ = lambda x, y, z, *args, **kwargs: _ANYARGS(x, y, z, *args, **kwargs) - -# Lambdas that are *not* unnecessary and should *not* trigger warnings. -_ = lambda x: x -_ = lambda x: x() -_ = lambda x=4: hash(x) -_ = lambda x, y: range(y, x) -_ = lambda x: range(5, x) -_ = lambda x, y: range(x, 5) -_ = lambda x, y, z: x.y(z) -_ = lambda: 5 -_ = lambda **kwargs: _ANYARGS() -_ = lambda **kwargs: _ANYARGS(**dict([('three', 3)])) -_ = lambda **kwargs: _ANYARGS(**{'three': 3}) -_ = lambda dict_arg, **kwargs: _ANYARGS(kwargs, **dict_arg) -_ = lambda *args: _ANYARGS() -_ = lambda *args: _ANYARGS(*list([3, 4])) -_ = lambda *args: _ANYARGS(*[3, 4]) -_ = lambda list_arg, *args: _ANYARGS(args, *list_arg) -_ = lambda: _ANYARGS(*[3]) -_ = lambda: _ANYARGS(**{'three': 3}) -_ = lambda: _ANYARGS(*[3], **{'three': 3}) +# pylint: disable=star-args, undefined-variable
+"""test suspicious lambda expressions
+"""
+
+__revision__ = ''
+
+# Some simple examples of the most commonly encountered forms.
+# +1: [unnecessary-lambda]
+_ = lambda: list() # replaceable with "list"
+# +1: [unnecessary-lambda]
+_ = lambda x: hash(x) # replaceable with "hash"
+# +1: [unnecessary-lambda]
+_ = lambda x, y: min(x, y) # replaceable with "min"
+
+# A function that can take any arguments given to it.
+_ANYARGS = lambda *args, **kwargs: 'completely arbitrary return value'
+
+# Some more complex forms of unnecessary lambda expressions.
+# +1: [unnecessary-lambda]
+_ = lambda *args: _ANYARGS(*args)
+# +1: [unnecessary-lambda]
+_ = lambda **kwargs: _ANYARGS(**kwargs)
+# +1: [unnecessary-lambda]
+_ = lambda *args, **kwargs: _ANYARGS(*args, **kwargs)
+# +1: [unnecessary-lambda]
+_ = lambda x, y, z, *args, **kwargs: _ANYARGS(x, y, z, *args, **kwargs)
+
+# Lambdas that are *not* unnecessary and should *not* trigger warnings.
+_ = lambda x: x
+_ = lambda x: x()
+_ = lambda x=4: hash(x)
+_ = lambda x, y: list(range(y, x))
+_ = lambda x: list(range(5, x))
+_ = lambda x, y: list(range(x, 5))
+_ = lambda x, y, z: x.y(z)
+_ = lambda: 5
+_ = lambda **kwargs: _ANYARGS()
+_ = lambda **kwargs: _ANYARGS(**dict([('three', 3)]))
+_ = lambda **kwargs: _ANYARGS(**{'three': 3})
+_ = lambda dict_arg, **kwargs: _ANYARGS(kwargs, **dict_arg)
+_ = lambda *args: _ANYARGS()
+_ = lambda *args: _ANYARGS(*list([3, 4]))
+_ = lambda *args: _ANYARGS(*[3, 4])
+_ = lambda list_arg, *args: _ANYARGS(args, *list_arg)
+_ = lambda: _ANYARGS(*[3])
+_ = lambda: _ANYARGS(**{'three': 3})
+_ = lambda: _ANYARGS(*[3], **{'three': 3})
+
+# Don't warn about this.
+_ = lambda: code().analysis()
diff --git a/test/functional/unnecessary_lambda.txt b/test/functional/unnecessary_lambda.txt new file mode 100644 index 0000000..de13882 --- /dev/null +++ b/test/functional/unnecessary_lambda.txt @@ -0,0 +1,7 @@ +unnecessary-lambda:9:<lambda>:Lambda may not be necessary +unnecessary-lambda:11:<lambda>:Lambda may not be necessary +unnecessary-lambda:13:<lambda>:Lambda may not be necessary +unnecessary-lambda:20:<lambda>:Lambda may not be necessary +unnecessary-lambda:22:<lambda>:Lambda may not be necessary +unnecessary-lambda:24:<lambda>:Lambda may not be necessary +unnecessary-lambda:26:<lambda>:Lambda may not be necessary diff --git a/test/input/func_useless_else_on_loop.py b/test/functional/useless_else_on_loop.py index 289366a..4f27cf7 100644 --- a/test/input/func_useless_else_on_loop.py +++ b/test/functional/useless_else_on_loop.py @@ -7,14 +7,14 @@ def test_return_for(): for i in range(10): if i % 2: return i - else: + else: # [useless-else-on-loop] print 'math is broken' def test_return_while(): """else + return is not accetable.""" while True: return 1 - else: + else: # [useless-else-on-loop] print 'math is broken' @@ -23,19 +23,19 @@ while True: """A function with a loop.""" for _ in range(10): break -else: +else: # [useless-else-on-loop] print 'or else!' while True: while False: break -else: +else: # [useless-else-on-loop] print 'or else!' for j in range(10): pass -else: +else: # [useless-else-on-loop] print 'fat chance' for j in range(10): break diff --git a/test/functional/useless_else_on_loop.txt b/test/functional/useless_else_on_loop.txt new file mode 100644 index 0000000..93309b6 --- /dev/null +++ b/test/functional/useless_else_on_loop.txt @@ -0,0 +1,5 @@ +useless-else-on-loop:10:test_return_for:Else clause on loop without a break statement +useless-else-on-loop:17:test_return_while:Else clause on loop without a break statement +useless-else-on-loop:26::Else clause on loop without a break statement +useless-else-on-loop:33::Else clause on loop without a break statement +useless-else-on-loop:38::Else clause on loop without a break statement diff --git a/test/input/func_noerror_9215_lambda_arg_as_decorator.py b/test/input/func_noerror_9215_lambda_arg_as_decorator.py deleted file mode 100644 index cbbc747..0000000 --- a/test/input/func_noerror_9215_lambda_arg_as_decorator.py +++ /dev/null @@ -1,29 +0,0 @@ -"""Demonstrate false undefined variable for lambda functions. - -http://www.logilab.org/ticket/9215 -""" - -__revision__ = None - -def decorator(expr): - """Function returning decorator.""" - def func(function): - """Pass-thru decorator.""" - return function - # use expr - expr(0) - return func - -# this lambda is flagged -# E0602: 16:main.<lambda>: Undefined variable 'x' -@decorator(lambda x: x > 0) -def main(): - """Dummy function.""" - # this one is not flagged - decorator(lambda y: y > 0) - -if __name__ == "__main__": - main() - - - diff --git a/test/input/func_w0622.py b/test/input/func_w0622.py deleted file mode 100644 index 5769841..0000000 --- a/test/input/func_w0622.py +++ /dev/null @@ -1,11 +0,0 @@ -# pylint: disable=C0103 -"""test built-in redefinition -""" -__revision__ = 0 - -def function(): - """yo""" - type = 1 - print type - -map = {} diff --git a/test/input/func_w0711.py b/test/input/func_w0711.py deleted file mode 100644 index 97c3697..0000000 --- a/test/input/func_w0711.py +++ /dev/null @@ -1,15 +0,0 @@ -"""find binary operations used as exceptions -""" - -__revision__ = 1 - -try: - __revision__ += 1 -except Exception or StandardError: - print "caught1" -except Exception and StandardError: - print "caught2" -except Exception or StandardError: - print "caught3" -except (Exception or StandardError), exc: - print "caught4" diff --git a/test/messages/func_bad_continuation.txt b/test/messages/func_bad_continuation.txt deleted file mode 100644 index 42087e5..0000000 --- a/test/messages/func_bad_continuation.txt +++ /dev/null @@ -1,64 +0,0 @@ -C: 14: Wrong hanging indentation. - ] # [bad-continuation] -| ^| -C: 19: Wrong continued indentation. - 7, # [bad-continuation] - | ^ -C: 27: Wrong hanging indentation. - 'b': 2, # [bad-continuation] - ^| -C: 33: Wrong hanging indentation. - 'b': 2, # [bad-continuation] - ^| -C: 41: Wrong continued indentation. - # [bad-continuation] is not accepted - | | ^ -C: 42: Wrong continued indentation. - 'contents', # nor this. [bad-continuation] - | ^ -C: 51: Wrong hanging indentation in dict value. - 'value2', # [bad-continuation] - | ^ | -C: 61: Wrong continued indentation. - 'wrong', # [bad-continuation] - ^ | -C: 85: Wrong hanging indentation in dict value. -'value1', # [bad-continuation] -^ | | -C: 89: Wrong hanging indentation in dict value. - 'value1', # [bad-continuation] - ^ | | -C:106: Wrong hanging indentation before block. - some_arg, # [bad-continuation] - ^ | -C:107: Wrong hanging indentation before block. - some_other_arg): # [bad-continuation] - ^ | -C:111:continue4: Missing function docstring -C:127: Wrong continued indentation. - "b") # [bad-continuation] - ^ | -C:141: Wrong hanging indentation before block. - ): pass # [bad-continuation] -| ^| -C:144: Wrong continued indentation before block. - 2): # [bad-continuation] - ^ | -C:152: Wrong continued indentation. - 2 and # [bad-continuation] - | ^ -C:157: Wrong hanging indentation before block. - 2): pass # [bad-continuation] - ^ | | -C:164: Wrong continued indentation before block. - 2 or # [bad-continuation] - |^ | -C:168: Wrong continued indentation before block. - 2): pass # [bad-continuation] - ^ | | -C:174: Wrong hanging indentation before block. - 2): # [bad-continuation] - ^ | | -C:185: Wrong continued indentation. - 2): # [bad-continuation] - ^ | diff --git a/test/messages/func_ctor_arguments.txt b/test/messages/func_ctor_arguments.txt deleted file mode 100644 index b8d62b1..0000000 --- a/test/messages/func_ctor_arguments.txt +++ /dev/null @@ -1,17 +0,0 @@ -E: 35: No value for argument 'first_argument' in constructor call -E: 36: Too many positional arguments for constructor call -E: 38: No value for argument 'third_argument' in constructor call -E: 39: No value for argument 'first_argument' in constructor call -E: 39: No value for argument 'second_argument' in constructor call -E: 39: No value for argument 'third_argument' in constructor call -E: 41: Too many positional arguments for constructor call -E: 46: No value for argument 'first_argument' in constructor call -E: 46: Unexpected keyword argument 'bob' in constructor call -E: 47: Unexpected keyword argument 'coin' in constructor call -E: 49: Argument 'one' passed by position and keyword in constructor call -E: 52: No value for argument 'first_argument' in constructor call -E: 53: Too many positional arguments for constructor call -E: 59: Too many positional arguments for constructor call -E: 62: Too many positional arguments for constructor call -E: 63: No value for argument 'first_argument' in constructor call -E: 63: Unexpected keyword argument 'one' in constructor call diff --git a/test/messages/func_e0205.txt b/test/messages/func_e0205.txt deleted file mode 100644 index c7402ce..0000000 --- a/test/messages/func_e0205.txt +++ /dev/null @@ -1,2 +0,0 @@ -E: 14:Cdef.abcd: An attribute defined in input.func_e0205 line 10 hides this method - diff --git a/test/messages/func_loopvar_in_closure.txt b/test/messages/func_loopvar_in_closure.txt deleted file mode 100644 index 5b068f4..0000000 --- a/test/messages/func_loopvar_in_closure.txt +++ /dev/null @@ -1,8 +0,0 @@ -W: 21:good_case3: Unused variable 'i' -W: 45:good_case6.<lambda>: Using possibly undefined loop variable 'i' -W: 78:bad_case.<lambda>: Cell variable i defined in loop -W: 83:bad_case2.<lambda>: Cell variable i defined in loop -W: 91:bad_case3.<lambda>: Cell variable j defined in loop -W:101:bad_case4.nested: Cell variable i defined in loop -W:122:bad_case5.<lambda>: Cell variable i defined in loop -W:130:bad_case6.<lambda>: Cell variable i defined in loop diff --git a/test/messages/func_undefined_var.txt b/test/messages/func_undefined_var.txt deleted file mode 100644 index 5505156..0000000 --- a/test/messages/func_undefined_var.txt +++ /dev/null @@ -1,14 +0,0 @@ -E: 8: Undefined variable 'unknown' -E: 14:in_method: Undefined variable 'nomoreknown' -E: 22:bad_default: Undefined variable 'unknown2' -E: 25:bad_default: Undefined variable 'xxxx' -E: 26:bad_default: Undefined variable 'xxxx' -E: 27:bad_default: Undefined variable 'augvar' -E: 28:bad_default: Undefined variable 'vardel' -E: 56: Using variable 'PLOUF' before assignment -E: 65:if_branch_test: Using variable 'xxx' before assignment -E: 89:test_arguments: Using variable 'TestClass' before assignment -E: 93:TestClass: Using variable 'Ancestor' before assignment -E: 96:TestClass.MissingAncestor: Using variable 'Ancestor1' before assignment -E:103:TestClass.test1.UsingBeforeDefinition: Using variable 'Empty' before assignment -W: 27:bad_default: Unused variable 'augvar' diff --git a/test/messages/func_useless_else_on_loop.txt b/test/messages/func_useless_else_on_loop.txt deleted file mode 100644 index 6c2c60c..0000000 --- a/test/messages/func_useless_else_on_loop.txt +++ /dev/null @@ -1,5 +0,0 @@ -W: 10:test_return_for: Else clause on loop without a break statement -W: 17:test_return_while: Else clause on loop without a break statement -W: 26: Else clause on loop without a break statement -W: 33: Else clause on loop without a break statement -W: 38: Else clause on loop without a break statement diff --git a/test/messages/func_w0108.txt b/test/messages/func_w0108.txt deleted file mode 100644 index 70e0925..0000000 --- a/test/messages/func_w0108.txt +++ /dev/null @@ -1,8 +0,0 @@ -W: 8:<lambda>: Lambda may not be necessary -W: 9:<lambda>: Lambda may not be necessary -W: 10:<lambda>: Lambda may not be necessary -W: 16:<lambda>: Lambda may not be necessary -W: 17:<lambda>: Lambda may not be necessary -W: 18:<lambda>: Lambda may not be necessary -W: 19:<lambda>: Lambda may not be necessary - diff --git a/test/messages/func_w0711.txt b/test/messages/func_w0711.txt deleted file mode 100644 index a158818..0000000 --- a/test/messages/func_w0711.txt +++ /dev/null @@ -1,4 +0,0 @@ -W: 8: Exception to catch is the result of a binary "or" operation -W: 10: Exception to catch is the result of a binary "and" operation -W: 12: Exception to catch is the result of a binary "or" operation -W: 14: Exception to catch is the result of a binary "or" operation diff --git a/test/test_func.py b/test/test_func.py index 2d573c2..51b6ba3 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -44,7 +44,8 @@ class LintTestNonExistentModuleTC(LintTestUsingModule): class TestTests(testlib.TestCase): """check that all testable messages have been checked""" - PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310']) + PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310', 'E0202', + 'W0711', 'W0108']) @testlib.tag('coverage') def test_exhaustivity(self): diff --git a/test/test_functional.py b/test/test_functional.py index bd65ce3..449c933 100644 --- a/test/test_functional.py +++ b/test/test_functional.py @@ -193,11 +193,18 @@ class LintModuleTest(testlib.TestCase): lines = [] if self._produces_output() and expected: with open(self._test_file.expected_output, 'U') as fobj: + used = True for line in fobj: - parts = line.split(':') - linenum = int(parts[1]) - if (linenum, parts[0]) in expected: + parts = line.split(':', 2) + if len(parts) != 3 and used: lines.append(line) + else: + linenum = int(parts[1]) + if (linenum, parts[0]) in expected: + used = True + lines.append(line) + else: + used = False return expected, ''.join(lines) def _get_received(self): |
