summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Marek <shlomme@gmail.com>2014-07-30 22:16:33 +0200
committerTorsten Marek <shlomme@gmail.com>2014-07-30 22:16:33 +0200
commit502e33c6dff3ff93d3bd2f38eff5ad84c1a56c3a (patch)
tree23c6b156afa9fd88f1821112b5c054a458d9456a
parentb38fb7347e07a4c342cdf153939ee5ea56e6ae84 (diff)
downloadpylint-502e33c6dff3ff93d3bd2f38eff5ad84c1a56c3a.tar.gz
Converted more test cases.
-rw-r--r--checkers/base.py2
-rw-r--r--test/functional/genexpr_variable_scope.py (renamed from test/input/func_genexpr_var_scope_py24.py)3
-rw-r--r--test/functional/genexpr_variable_scope.txt1
-rw-r--r--test/functional/invalid_slice_index.py (renamed from test/input/func_invalid_slice_index.py)7
-rw-r--r--test/functional/invalid_slice_index.txt5
-rw-r--r--test/functional/long_lines_with_utf8.py (renamed from test/input/func_utf8_lines.py)3
-rw-r--r--test/functional/long_lines_with_utf8.txt1
-rw-r--r--test/functional/missing_final_newline.py4
-rw-r--r--test/functional/missing_final_newline.txt1
-rw-r--r--test/functional/statement_without_effect.py (renamed from test/input/func_base_stmt_without_effect.py)42
-rw-r--r--test/functional/statement_without_effect.txt28
-rw-r--r--test/input/func_no_final_new_line.py2
-rw-r--r--test/messages/func_base_stmt_without_effect.txt11
-rw-r--r--test/messages/func_genexpr_var_scope_py24.txt1
-rw-r--r--test/messages/func_invalid_slice_index.txt5
-rw-r--r--test/messages/func_no_final_new_line.txt1
-rw-r--r--test/messages/func_utf8_lines.txt1
17 files changed, 64 insertions, 54 deletions
diff --git a/checkers/base.py b/checkers/base.py
index 1b12b87..282344d 100644
--- a/checkers/base.py
+++ b/checkers/base.py
@@ -562,7 +562,7 @@ functions, methods
pass
else:
sibling = expr.previous_sibling()
- if (sibling.scope() is scope and
+ if (sibling is not None and sibling.scope() is scope and
isinstance(sibling, astroid.Assign)):
return
self.add_message('pointless-string-statement', node=node)
diff --git a/test/input/func_genexpr_var_scope_py24.py b/test/functional/genexpr_variable_scope.py
index 2b6faf3..4089439 100644
--- a/test/input/func_genexpr_var_scope_py24.py
+++ b/test/functional/genexpr_variable_scope.py
@@ -2,5 +2,4 @@
outside the genexpr scope
"""
-__revision__ = list(n for n in range(10))
-print n
+print n # [undefined-variable]
diff --git a/test/functional/genexpr_variable_scope.txt b/test/functional/genexpr_variable_scope.txt
new file mode 100644
index 0000000..3cfa6c5
--- /dev/null
+++ b/test/functional/genexpr_variable_scope.txt
@@ -0,0 +1 @@
+undefined-variable:5::Undefined variable 'n'
diff --git a/test/input/func_invalid_slice_index.py b/test/functional/invalid_slice_index.py
index 32f2f2d..63ba252 100644
--- a/test/input/func_invalid_slice_index.py
+++ b/test/functional/invalid_slice_index.py
@@ -1,18 +1,17 @@
"""Errors for invalid slice indices"""
# pylint: disable=too-few-public-methods, no-self-use
-__revision__ = 0
TESTLIST = [1, 2, 3]
# Invalid indices
def function1():
"""functions used as indices"""
- return TESTLIST[id:id:]
+ return TESTLIST[id:id:] # [invalid-slice-index,invalid-slice-index]
def function2():
"""strings used as indices"""
- return TESTLIST['0':'1':]
+ return TESTLIST['0':'1':] # [invalid-slice-index,invalid-slice-index]
def function3():
"""class without __index__ used as index"""
@@ -21,7 +20,7 @@ def function3():
"""Class with no __index__ method"""
pass
- return TESTLIST[NoIndexTest()::]
+ return TESTLIST[NoIndexTest()::] # [invalid-slice-index]
# Valid indices
def function4():
diff --git a/test/functional/invalid_slice_index.txt b/test/functional/invalid_slice_index.txt
new file mode 100644
index 0000000..cd4dc6e
--- /dev/null
+++ b/test/functional/invalid_slice_index.txt
@@ -0,0 +1,5 @@
+invalid-slice-index:10:function1:Slice index is not an int, None, or instance with __index__
+invalid-slice-index:10:function1:Slice index is not an int, None, or instance with __index__
+invalid-slice-index:14:function2:Slice index is not an int, None, or instance with __index__
+invalid-slice-index:14:function2:Slice index is not an int, None, or instance with __index__
+invalid-slice-index:23:function3:Slice index is not an int, None, or instance with __index__
diff --git a/test/input/func_utf8_lines.py b/test/functional/long_lines_with_utf8.py
index ee29db7..a1d90ed 100644
--- a/test/input/func_utf8_lines.py
+++ b/test/functional/long_lines_with_utf8.py
@@ -1,8 +1,7 @@
# coding: utf-8
"""Test data file files with non-ASCII content."""
-__revision__ = 1
THIS_IS_A_LONG_VARIABLE_NAME = 'Существительное Частица' # but the line is okay
-THIS_IS_A_VERY_LONG_VARIABLE_NAME = 'Существительное Частица' # and the line is not okay
+THIS_IS_A_VERY_LONG_VARIABLE_NAME = 'Существительное Частица' # and the line is not okay # [line-too-long]
diff --git a/test/functional/long_lines_with_utf8.txt b/test/functional/long_lines_with_utf8.txt
new file mode 100644
index 0000000..14f6529
--- /dev/null
+++ b/test/functional/long_lines_with_utf8.txt
@@ -0,0 +1 @@
+line-too-long:7::Line too long (108/80)
diff --git a/test/functional/missing_final_newline.py b/test/functional/missing_final_newline.py
new file mode 100644
index 0000000..b2a9e0c
--- /dev/null
+++ b/test/functional/missing_final_newline.py
@@ -0,0 +1,4 @@
+"""This file does not have a final newline."""
+
+# +1:[missing-final-newline]
+print 1 \ No newline at end of file
diff --git a/test/functional/missing_final_newline.txt b/test/functional/missing_final_newline.txt
new file mode 100644
index 0000000..b53c980
--- /dev/null
+++ b/test/functional/missing_final_newline.txt
@@ -0,0 +1 @@
+missing-final-newline:4::Final newline missing
diff --git a/test/input/func_base_stmt_without_effect.py b/test/functional/statement_without_effect.py
index 4844971..b1aaadf 100644
--- a/test/input/func_base_stmt_without_effect.py
+++ b/test/functional/statement_without_effect.py
@@ -1,43 +1,36 @@
-"""
- 'W0104': ('Statement seems to have no effect',
- 'Used when a statement doesn\'t have (or at least seems to) \
- any effect.'),
- 'W0105': ('String statement has no effect',
- 'Used when a string is used as a statement (which of course \
- has no effect). This is a particular case of W0104 with its \
- own message so you can easily disable it if you\'re using \
- those strings as documentation, instead of comments.'),
- 'W0106': ('Expression "%s" is assigned to nothing',
- 'Used when an expression that is not a function call is assigned\
- to nothing. Probably something else was intended.'),
-"""
+"""Test for statements without effects."""
# pylint: disable=too-few-public-methods
-__revision__ = ''
-__revision__
+# +1:[pointless-string-statement]
+"""inline doc string should use a separated message"""
-__revision__ <= 1
+__revision__ = ''
-__revision__.lower() # ok
+__revision__ # [pointless-statement]
-[i for i in __revision__] # ko
+__revision__ <= 1 # [pointless-statement]
+__revision__.lower()
+[i for i in __revision__] # [pointless-statement]
+
+# +1:[pointless-string-statement]
"""inline doc string should use a separated message"""
-__revision__.lower(); # unnecessary ;
-list() and tuple() # W0106
+__revision__.lower(); # [unnecessary-semicolon]
+
+list() and tuple() # [expression-not-assigned]
def to_be():
"""return 42"""
return "42"
ANSWER = to_be() # ok
-ANSWER == to_be() # W0106, typical typo
+ANSWER == to_be() # [expression-not-assigned]
-to_be() or not to_be() # W0106, strange conditional function call (or nonsens)
-to_be().title # W0106, very strange, maybe typo
+to_be() or not to_be() # [expression-not-assigned]
+to_be().title # [expression-not-assigned]
GOOD_ATTRIBUTE_DOCSTRING = 42
"""Module level attribute docstring is fine. """
@@ -61,11 +54,12 @@ class ClassLevelAttributeTest(object):
val = 0
for val in range(42):
val += attr
+ # +1:[pointless-string-statement]
""" Invalid attribute docstring """
self.val = val
def test(self):
""" invalid attribute docstrings here. """
self.val = 42
+ # +1:[pointless-string-statement]
""" this is an invalid attribute docstring. """
- \ No newline at end of file
diff --git a/test/functional/statement_without_effect.txt b/test/functional/statement_without_effect.txt
new file mode 100644
index 0000000..636a441
--- /dev/null
+++ b/test/functional/statement_without_effect.txt
@@ -0,0 +1,28 @@
+pointless-string-statement:5::String statement has no effect
+pointless-statement:6::Statement seems to have no effect
+pointless-statement:8::Statement seems to have no effect
+pointless-statement:9::Statement seems to have no effect
+pointless-statement:11::Statement seems to have no effect
+pointless-statement:12::Statement seems to have no effect
+pointless-statement:15::Statement seems to have no effect
+pointless-string-statement:15::String statement has no effect
+unnecessary-semicolon:17::Unnecessary semicolon
+pointless-string-statement:18::String statement has no effect
+unnecessary-semicolon:18::Unnecessary semicolon
+expression-not-assigned:19::Expression "(list()) and (tuple())" is assigned to nothing
+expression-not-assigned:20::Expression "(list()) and (tuple())" is assigned to nothing
+unnecessary-semicolon:21::Unnecessary semicolon
+expression-not-assigned:23::Expression "(list()) and (tuple())" is assigned to nothing
+expression-not-assigned:26::Expression "ANSWER == to_be()" is assigned to nothing
+expression-not-assigned:27::Expression "ANSWER == to_be()" is assigned to nothing
+expression-not-assigned:28::Expression "(to_be()) or (not to_be())" is assigned to nothing
+expression-not-assigned:29::Expression "(to_be()) or (not to_be())" is assigned to nothing
+expression-not-assigned:30::Expression "ANSWER == to_be()" is assigned to nothing
+expression-not-assigned:32::Expression "(to_be()) or (not to_be())" is assigned to nothing
+expression-not-assigned:33::Expression "to_be().title" is assigned to nothing
+pointless-string-statement:54:ClassLevelAttributeTest.__init__:String statement has no effect
+pointless-string-statement:55:ClassLevelAttributeTest.__init__:String statement has no effect
+pointless-string-statement:58:ClassLevelAttributeTest.__init__:String statement has no effect
+pointless-string-statement:61:ClassLevelAttributeTest.test:String statement has no effect
+pointless-string-statement:62:ClassLevelAttributeTest.test:String statement has no effect
+pointless-string-statement:65:ClassLevelAttributeTest.test:String statement has no effect
diff --git a/test/input/func_no_final_new_line.py b/test/input/func_no_final_new_line.py
deleted file mode 100644
index a9c728d..0000000
--- a/test/input/func_no_final_new_line.py
+++ /dev/null
@@ -1,2 +0,0 @@
-'''hop'''
-__revision__ = 0 \ No newline at end of file
diff --git a/test/messages/func_base_stmt_without_effect.txt b/test/messages/func_base_stmt_without_effect.txt
deleted file mode 100644
index d440d02..0000000
--- a/test/messages/func_base_stmt_without_effect.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-W: 17: Statement seems to have no effect
-W: 19: Statement seems to have no effect
-W: 23: Statement seems to have no effect
-W: 26: String statement has no effect
-W: 28: Unnecessary semicolon
-W: 30: Expression "(list()) and (tuple())" is assigned to nothing
-W: 37: Expression "ANSWER == to_be()" is assigned to nothing
-W: 39: Expression "(to_be()) or (not to_be())" is assigned to nothing
-W: 40: Expression "to_be().title" is assigned to nothing
-W: 64:ClassLevelAttributeTest.__init__: String statement has no effect
-W: 70:ClassLevelAttributeTest.test: String statement has no effect
diff --git a/test/messages/func_genexpr_var_scope_py24.txt b/test/messages/func_genexpr_var_scope_py24.txt
deleted file mode 100644
index f599112..0000000
--- a/test/messages/func_genexpr_var_scope_py24.txt
+++ /dev/null
@@ -1 +0,0 @@
-E: 6: Undefined variable 'n'
diff --git a/test/messages/func_invalid_slice_index.txt b/test/messages/func_invalid_slice_index.txt
deleted file mode 100644
index d5b9e86..0000000
--- a/test/messages/func_invalid_slice_index.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-E: 11:function1: Slice index is not an int, None, or instance with __index__
-E: 11:function1: Slice index is not an int, None, or instance with __index__
-E: 15:function2: Slice index is not an int, None, or instance with __index__
-E: 15:function2: Slice index is not an int, None, or instance with __index__
-E: 24:function3: Slice index is not an int, None, or instance with __index__
diff --git a/test/messages/func_no_final_new_line.txt b/test/messages/func_no_final_new_line.txt
deleted file mode 100644
index 5040aa7..0000000
--- a/test/messages/func_no_final_new_line.txt
+++ /dev/null
@@ -1 +0,0 @@
-C: 2: Final newline missing
diff --git a/test/messages/func_utf8_lines.txt b/test/messages/func_utf8_lines.txt
deleted file mode 100644
index 9706781..0000000
--- a/test/messages/func_utf8_lines.txt
+++ /dev/null
@@ -1 +0,0 @@
-C: 8: Line too long (89/80)