summaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/bad_continuation.py189
-rw-r--r--test/functional/bad_continuation.txt63
-rw-r--r--test/functional/exception_is_binary_op.py12
-rw-r--r--test/functional/exception_is_binary_op.txt4
-rw-r--r--test/functional/redefined_builtin.py9
-rw-r--r--test/functional/redefined_builtin.txt2
-rw-r--r--test/functional/useless_else_on_loop.py55
-rw-r--r--test/functional/useless_else_on_loop.txt5
8 files changed, 339 insertions, 0 deletions
diff --git a/test/functional/bad_continuation.py b/test/functional/bad_continuation.py
new file mode 100644
index 0000000..3d62521
--- /dev/null
+++ b/test/functional/bad_continuation.py
@@ -0,0 +1,189 @@
+"""Regression test case for bad-continuation."""
+
+# Various alignment for brackets
+LIST0 = [
+ 1, 2, 3
+]
+LIST1 = [
+ 1, 2, 3
+ ]
+LIST2 = [
+ 1, 2, 3
+ ] # [bad-continuation]
+
+# Alignment inside literals
+W0 = [1, 2, 3,
+ 4, 5, 6,
+ 7, # [bad-continuation]
+ 8, 9, 10,
+ 11, 12, 13,
+ # and a comment
+ 14, 15, 16]
+
+W1 = {
+ 'a': 1,
+ 'b': 2, # [bad-continuation]
+ 'c': 3,
+ }
+
+W2 = {
+ 'a': 1,
+ 'b': 2, # [bad-continuation]
+ 'c': 3,
+ }
+
+W2 = ['some', 'contents' # with a continued comment that may be aligned
+ # under the previous comment (optionally)
+ 'and',
+ 'more', # but this
+ # [bad-continuation] is not accepted
+ 'contents', # [bad-continuation] nor this.
+ ]
+
+# Values in dictionaries should be indented 4 spaces further if they are on a
+# different line than their key
+W4 = {
+ 'key1':
+ 'value1', # Grandfather in the old style
+ 'key2':
+ 'value2', # [bad-continuation]
+ 'key3':
+ 'value3', # Comma here
+ }
+
+# And should follow the same rules as continuations within parens
+W5 = {
+ 'key1': 'long value'
+ 'long continuation',
+ 'key2': 'breaking'
+ 'wrong', # [bad-continuation]
+ 'key3': 2*(
+ 2+2),
+ 'key4': ('parenthesis',
+ 'continuation') # No comma here
+ }
+
+# Allow values to line up with their keys when the key is next to the brace
+W6 = {'key1':
+ 'value1',
+ 'key2':
+ 'value2',
+ }
+
+# Or allow them to be indented
+W7 = {'key1':
+ 'value1',
+ 'key2':
+ 'value2'
+ }
+
+# Bug that caused a warning on the previous two cases permitted these odd
+# incorrect indentations
+W8 = {'key1':
+'value1', # [bad-continuation]
+ }
+
+W9 = {'key1':
+ 'value1', # [bad-continuation]
+ }
+
+# Alignment of arguments in function definitions
+def continue1(some_arg,
+ some_other_arg):
+ """A function with well-aligned arguments."""
+ print some_arg, some_other_arg
+
+
+def continue2(
+ some_arg,
+ some_other_arg):
+ """A function with well-aligned arguments."""
+ print some_arg, some_other_arg
+
+def continue3(
+ some_arg, # [bad-continuation]
+ some_other_arg): # [bad-continuation]
+ """A function with misaligned arguments"""
+ print some_arg, some_other_arg
+
+def continue4( # pylint:disable=missing-docstring
+ arg1,
+ arg2): print arg1, arg2
+
+
+def callee(*args):
+ """noop"""
+ print args
+
+
+callee(
+ "a",
+ "b"
+ )
+
+callee("a",
+ "b") # [bad-continuation]
+
+callee(5, {'a': 'b',
+ 'c': 'd'})
+
+if (
+ 1
+ ): pass
+
+if (
+ 1
+): pass
+if (
+ 1
+ ): pass # [bad-continuation]
+
+if (1 and
+ 2): # [bad-continuation]
+ pass
+
+while (1 and
+ 2):
+ pass
+
+while (1 and
+ 2 and # [bad-continuation]
+ 3):
+ pass
+
+if (
+ 2): pass # [bad-continuation]
+
+if (1 or
+ 2 or
+ 3): pass
+
+if (1 or
+ 2 or # [bad-continuation]
+ 3): print 1, 2
+
+if (1 and
+ 2): pass # [bad-continuation]
+
+if (
+ 2): pass
+
+if (
+ 2): # [bad-continuation]
+ pass
+
+L1 = (lambda a,
+ b: a + b)
+
+if not (1 and
+ 2):
+ print 3
+
+if not (1 and
+ 2): # [bad-continuation]
+ print 3
+
+continue2("foo",
+ some_other_arg="this "
+ "is "
+ "fine")
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/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/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/functional/useless_else_on_loop.py b/test/functional/useless_else_on_loop.py
new file mode 100644
index 0000000..4f27cf7
--- /dev/null
+++ b/test/functional/useless_else_on_loop.py
@@ -0,0 +1,55 @@
+"""Check for else branches on loops with break an return only."""
+
+__revision__ = 0
+
+def test_return_for():
+ """else + return is not accetable."""
+ for i in range(10):
+ if i % 2:
+ return i
+ else: # [useless-else-on-loop]
+ print 'math is broken'
+
+def test_return_while():
+ """else + return is not accetable."""
+ while True:
+ return 1
+ else: # [useless-else-on-loop]
+ print 'math is broken'
+
+
+while True:
+ def short_fun():
+ """A function with a loop."""
+ for _ in range(10):
+ break
+else: # [useless-else-on-loop]
+ print 'or else!'
+
+
+while True:
+ while False:
+ break
+else: # [useless-else-on-loop]
+ print 'or else!'
+
+for j in range(10):
+ pass
+else: # [useless-else-on-loop]
+ print 'fat chance'
+ for j in range(10):
+ break
+
+def test_return_for2():
+ """no false positive for break in else
+
+ https://bitbucket.org/logilab/pylint/issue/117/useless-else-on-loop-false-positives
+ """
+ for i in range(10):
+ for i in range(i):
+ if i % 2:
+ break
+ else:
+ break
+ else:
+ print 'great math'
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