From 8ef3440e51f4391b106ff84b60d07aed69f9dce3 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 23 Nov 2021 09:16:15 +0100 Subject: Move the functional tests for extension in 'tests/functional/ext' --- tests/functional/b/bad_builtin_extension.py | 4 - tests/functional/b/bad_builtin_extension.rc | 2 - tests/functional/b/bad_builtin_extension.txt | 2 - tests/functional/b/broad_try_clause_extension.py | 49 ----- tests/functional/b/broad_try_clause_extension.rc | 2 - tests/functional/b/broad_try_clause_extension.txt | 4 - tests/functional/c/compare_to_zero_extension.py | 28 --- tests/functional/c/compare_to_zero_extension.rc | 2 - tests/functional/c/compare_to_zero_extension.txt | 4 - tests/functional/d/docstyle_extension.py | 41 ---- tests/functional/d/docstyle_extension.rc | 2 - tests/functional/d/docstyle_extension.txt | 7 - tests/functional/e/elif_checker.py | 27 --- tests/functional/e/elif_checker.rc | 2 - tests/functional/e/elif_checker.txt | 2 - tests/functional/e/empty_comment.py | 13 -- tests/functional/e/empty_comment.rc | 2 - tests/functional/e/empty_comment.txt | 4 - tests/functional/e/empty_string_comparison.py | 16 -- tests/functional/e/empty_string_comparison.rc | 2 - tests/functional/e/empty_string_comparison.txt | 4 - .../ext/bad_builtin/bad_builtin_extension.py | 4 + .../ext/bad_builtin/bad_builtin_extension.rc | 2 + .../ext/bad_builtin/bad_builtin_extension.txt | 2 + tests/functional/ext/bad_builtin/bad_builtins.py | 3 + tests/functional/ext/bad_builtin/bad_builtins.rc | 5 + tests/functional/ext/bad_builtin/bad_builtins.txt | 4 + tests/functional/ext/bad_builtins.py | 3 - tests/functional/ext/bad_builtins.rc | 5 - tests/functional/ext/bad_builtins.txt | 4 - .../broad_try_clause/broad_try_clause_extension.py | 49 +++++ .../broad_try_clause/broad_try_clause_extension.rc | 2 + .../broad_try_clause_extension.txt | 4 + tests/functional/ext/check_elif/elif_checker.py | 27 +++ tests/functional/ext/check_elif/elif_checker.rc | 2 + tests/functional/ext/check_elif/elif_checker.txt | 2 + .../code_style_consider_using_assignment_expr.py | 159 --------------- .../code_style_consider_using_assignment_expr.rc | 6 - .../code_style_consider_using_assignment_expr.txt | 18 -- ...style_consider_using_namedtuple_or_dataclass.py | 74 ------- ...style_consider_using_namedtuple_or_dataclass.rc | 2 - ...tyle_consider_using_namedtuple_or_dataclass.txt | 5 - .../code_style/code_style_consider_using_tuple.py | 31 --- .../code_style/code_style_consider_using_tuple.rc | 2 - .../code_style/code_style_consider_using_tuple.txt | 8 - .../code_style/consider_using_assignment_expr.py | 159 +++++++++++++++ .../code_style/consider_using_assignment_expr.rc | 6 + .../code_style/consider_using_assignment_expr.txt | 18 ++ .../consider_using_namedtuple_or_dataclass.py | 74 +++++++ .../consider_using_namedtuple_or_dataclass.rc | 2 + .../consider_using_namedtuple_or_dataclass.txt | 5 + .../ext/code_style/consider_using_tuple.py | 31 +++ .../ext/code_style/consider_using_tuple.rc | 2 + .../ext/code_style/consider_using_tuple.txt | 8 + tests/functional/ext/code_style/py_version_35.py | 14 ++ tests/functional/ext/code_style/py_version_35.rc | 3 + .../ext/comparetozero/compare_to_zero_extension.py | 28 +++ .../ext/comparetozero/compare_to_zero_extension.rc | 2 + .../comparetozero/compare_to_zero_extension.txt | 4 + .../misplaced_comparison_constant.py | 49 +++++ .../misplaced_comparison_constant.rc | 2 + .../misplaced_comparison_constant.txt | 6 + tests/functional/ext/confusing_elif.py | 41 ---- tests/functional/ext/confusing_elif.rc | 2 - tests/functional/ext/confusing_elif.txt | 1 - .../ext/confusing_elif/confusing_elif.py | 41 ++++ .../ext/confusing_elif/confusing_elif.rc | 2 + .../ext/confusing_elif/confusing_elif.txt | 1 + .../functional/ext/consider_ternary_expression.py | 17 -- .../functional/ext/consider_ternary_expression.rc | 10 - .../functional/ext/consider_ternary_expression.txt | 2 - .../consider_ternary_expression.py | 17 ++ .../consider_ternary_expression.rc | 10 + .../consider_ternary_expression.txt | 2 + tests/functional/ext/docparams.py | 41 ---- tests/functional/ext/docparams.rc | 8 - tests/functional/ext/docparams.txt | 12 -- tests/functional/ext/docparams/docparams.py | 41 ++++ tests/functional/ext/docparams/docparams.rc | 8 + tests/functional/ext/docparams/docparams.txt | 12 ++ .../functional/ext/docparams/missing_param_doc.py | 142 ++++++++++++++ .../functional/ext/docparams/missing_param_doc.rc | 8 + .../functional/ext/docparams/missing_param_doc.txt | 18 ++ tests/functional/ext/docparams/useless_type_doc.py | 73 +++++++ tests/functional/ext/docparams/useless_type_doc.rc | 8 + .../functional/ext/docparams/useless_type_doc.txt | 4 + .../functional/ext/docstyle/docstyle_extension.py | 41 ++++ .../functional/ext/docstyle/docstyle_extension.rc | 2 + .../functional/ext/docstyle/docstyle_extension.txt | 7 + .../functional/ext/empty_comment/empty_comment.py | 13 ++ .../functional/ext/empty_comment/empty_comment.rc | 2 + .../functional/ext/empty_comment/empty_comment.txt | 4 + .../ext/emptystring/empty_string_comparison.py | 16 ++ .../ext/emptystring/empty_string_comparison.rc | 2 + .../ext/emptystring/empty_string_comparison.txt | 4 + tests/functional/ext/for_any_all.py | 61 ------ tests/functional/ext/for_any_all.rc | 2 - tests/functional/ext/for_any_all.txt | 8 - tests/functional/ext/for_any_all/for_any_all.py | 61 ++++++ tests/functional/ext/for_any_all/for_any_all.rc | 2 + tests/functional/ext/for_any_all/for_any_all.txt | 8 + tests/functional/ext/mccabe/mccabe.py | 216 +++++++++++++++++++++ tests/functional/ext/mccabe/mccabe.rc | 4 + tests/functional/ext/mccabe/mccabe.txt | 15 ++ .../overlapping_exceptions.py | 66 +++++++ .../overlapping_exceptions.rc | 2 + .../overlapping_exceptions.txt | 12 ++ tests/functional/ext/plugin_does_not_exists.py | 5 + tests/functional/ext/plugin_does_not_exists.rc | 3 + tests/functional/ext/plugin_does_not_exists.txt | 1 + .../redefined_variable_type.py | 85 ++++++++ .../redefined_variable_type.rc | 2 + .../redefined_variable_type.txt | 10 + tests/functional/ext/while_used.py | 10 - tests/functional/ext/while_used.rc | 2 - tests/functional/ext/while_used.txt | 2 - tests/functional/ext/while_used/while_used.py | 10 + tests/functional/ext/while_used/while_used.rc | 2 + tests/functional/ext/while_used/while_used.txt | 2 + tests/functional/m/mccabe.py | 216 --------------------- tests/functional/m/mccabe.rc | 4 - tests/functional/m/mccabe.txt | 15 -- .../functional/m/misplaced_comparison_constant.py | 49 ----- .../functional/m/misplaced_comparison_constant.rc | 3 - .../functional/m/misplaced_comparison_constant.txt | 6 - tests/functional/m/missing/missing_param_doc.py | 142 -------------- tests/functional/m/missing/missing_param_doc.rc | 8 - tests/functional/m/missing/missing_param_doc.txt | 18 -- tests/functional/o/overlapping_exceptions.py | 66 ------- tests/functional/o/overlapping_exceptions.rc | 2 - tests/functional/o/overlapping_exceptions.txt | 12 -- tests/functional/p/plugin_does_not_exists.py | 5 - tests/functional/p/plugin_does_not_exists.rc | 3 - tests/functional/p/plugin_does_not_exists.txt | 1 - tests/functional/p/py_version/py_version_35.py | 14 -- tests/functional/p/py_version/py_version_35.rc | 3 - tests/functional/r/redefined_variable_type.py | 85 -------- tests/functional/r/redefined_variable_type.rc | 2 - tests/functional/r/redefined_variable_type.txt | 10 - tests/functional/u/useless/useless_type_doc.py | 73 ------- tests/functional/u/useless/useless_type_doc.rc | 8 - tests/functional/u/useless/useless_type_doc.txt | 4 - 142 files changed, 1503 insertions(+), 1504 deletions(-) delete mode 100644 tests/functional/b/bad_builtin_extension.py delete mode 100644 tests/functional/b/bad_builtin_extension.rc delete mode 100644 tests/functional/b/bad_builtin_extension.txt delete mode 100644 tests/functional/b/broad_try_clause_extension.py delete mode 100644 tests/functional/b/broad_try_clause_extension.rc delete mode 100644 tests/functional/b/broad_try_clause_extension.txt delete mode 100644 tests/functional/c/compare_to_zero_extension.py delete mode 100644 tests/functional/c/compare_to_zero_extension.rc delete mode 100644 tests/functional/c/compare_to_zero_extension.txt delete mode 100644 tests/functional/d/docstyle_extension.py delete mode 100644 tests/functional/d/docstyle_extension.rc delete mode 100644 tests/functional/d/docstyle_extension.txt delete mode 100644 tests/functional/e/elif_checker.py delete mode 100644 tests/functional/e/elif_checker.rc delete mode 100644 tests/functional/e/elif_checker.txt delete mode 100644 tests/functional/e/empty_comment.py delete mode 100644 tests/functional/e/empty_comment.rc delete mode 100644 tests/functional/e/empty_comment.txt delete mode 100644 tests/functional/e/empty_string_comparison.py delete mode 100644 tests/functional/e/empty_string_comparison.rc delete mode 100644 tests/functional/e/empty_string_comparison.txt create mode 100644 tests/functional/ext/bad_builtin/bad_builtin_extension.py create mode 100644 tests/functional/ext/bad_builtin/bad_builtin_extension.rc create mode 100644 tests/functional/ext/bad_builtin/bad_builtin_extension.txt create mode 100644 tests/functional/ext/bad_builtin/bad_builtins.py create mode 100644 tests/functional/ext/bad_builtin/bad_builtins.rc create mode 100644 tests/functional/ext/bad_builtin/bad_builtins.txt delete mode 100644 tests/functional/ext/bad_builtins.py delete mode 100644 tests/functional/ext/bad_builtins.rc delete mode 100644 tests/functional/ext/bad_builtins.txt create mode 100644 tests/functional/ext/broad_try_clause/broad_try_clause_extension.py create mode 100644 tests/functional/ext/broad_try_clause/broad_try_clause_extension.rc create mode 100644 tests/functional/ext/broad_try_clause/broad_try_clause_extension.txt create mode 100644 tests/functional/ext/check_elif/elif_checker.py create mode 100644 tests/functional/ext/check_elif/elif_checker.rc create mode 100644 tests/functional/ext/check_elif/elif_checker.txt delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_assignment_expr.py delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_assignment_expr.rc delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_assignment_expr.txt delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.py delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.rc delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.txt delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_tuple.py delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_tuple.rc delete mode 100644 tests/functional/ext/code_style/code_style_consider_using_tuple.txt create mode 100644 tests/functional/ext/code_style/consider_using_assignment_expr.py create mode 100644 tests/functional/ext/code_style/consider_using_assignment_expr.rc create mode 100644 tests/functional/ext/code_style/consider_using_assignment_expr.txt create mode 100644 tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.py create mode 100644 tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.rc create mode 100644 tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.txt create mode 100644 tests/functional/ext/code_style/consider_using_tuple.py create mode 100644 tests/functional/ext/code_style/consider_using_tuple.rc create mode 100644 tests/functional/ext/code_style/consider_using_tuple.txt create mode 100644 tests/functional/ext/code_style/py_version_35.py create mode 100644 tests/functional/ext/code_style/py_version_35.rc create mode 100644 tests/functional/ext/comparetozero/compare_to_zero_extension.py create mode 100644 tests/functional/ext/comparetozero/compare_to_zero_extension.rc create mode 100644 tests/functional/ext/comparetozero/compare_to_zero_extension.txt create mode 100644 tests/functional/ext/comparison_placement/misplaced_comparison_constant.py create mode 100644 tests/functional/ext/comparison_placement/misplaced_comparison_constant.rc create mode 100644 tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt delete mode 100644 tests/functional/ext/confusing_elif.py delete mode 100644 tests/functional/ext/confusing_elif.rc delete mode 100644 tests/functional/ext/confusing_elif.txt create mode 100644 tests/functional/ext/confusing_elif/confusing_elif.py create mode 100644 tests/functional/ext/confusing_elif/confusing_elif.rc create mode 100644 tests/functional/ext/confusing_elif/confusing_elif.txt delete mode 100644 tests/functional/ext/consider_ternary_expression.py delete mode 100644 tests/functional/ext/consider_ternary_expression.rc delete mode 100644 tests/functional/ext/consider_ternary_expression.txt create mode 100644 tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py create mode 100644 tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc create mode 100644 tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt delete mode 100644 tests/functional/ext/docparams.py delete mode 100644 tests/functional/ext/docparams.rc delete mode 100644 tests/functional/ext/docparams.txt create mode 100644 tests/functional/ext/docparams/docparams.py create mode 100644 tests/functional/ext/docparams/docparams.rc create mode 100644 tests/functional/ext/docparams/docparams.txt create mode 100644 tests/functional/ext/docparams/missing_param_doc.py create mode 100644 tests/functional/ext/docparams/missing_param_doc.rc create mode 100644 tests/functional/ext/docparams/missing_param_doc.txt create mode 100644 tests/functional/ext/docparams/useless_type_doc.py create mode 100644 tests/functional/ext/docparams/useless_type_doc.rc create mode 100644 tests/functional/ext/docparams/useless_type_doc.txt create mode 100644 tests/functional/ext/docstyle/docstyle_extension.py create mode 100644 tests/functional/ext/docstyle/docstyle_extension.rc create mode 100644 tests/functional/ext/docstyle/docstyle_extension.txt create mode 100644 tests/functional/ext/empty_comment/empty_comment.py create mode 100644 tests/functional/ext/empty_comment/empty_comment.rc create mode 100644 tests/functional/ext/empty_comment/empty_comment.txt create mode 100644 tests/functional/ext/emptystring/empty_string_comparison.py create mode 100644 tests/functional/ext/emptystring/empty_string_comparison.rc create mode 100644 tests/functional/ext/emptystring/empty_string_comparison.txt delete mode 100644 tests/functional/ext/for_any_all.py delete mode 100644 tests/functional/ext/for_any_all.rc delete mode 100644 tests/functional/ext/for_any_all.txt create mode 100644 tests/functional/ext/for_any_all/for_any_all.py create mode 100644 tests/functional/ext/for_any_all/for_any_all.rc create mode 100644 tests/functional/ext/for_any_all/for_any_all.txt create mode 100644 tests/functional/ext/mccabe/mccabe.py create mode 100644 tests/functional/ext/mccabe/mccabe.rc create mode 100644 tests/functional/ext/mccabe/mccabe.txt create mode 100644 tests/functional/ext/overlapping_exceptions/overlapping_exceptions.py create mode 100644 tests/functional/ext/overlapping_exceptions/overlapping_exceptions.rc create mode 100644 tests/functional/ext/overlapping_exceptions/overlapping_exceptions.txt create mode 100644 tests/functional/ext/plugin_does_not_exists.py create mode 100644 tests/functional/ext/plugin_does_not_exists.rc create mode 100644 tests/functional/ext/plugin_does_not_exists.txt create mode 100644 tests/functional/ext/redefined_variable_type/redefined_variable_type.py create mode 100644 tests/functional/ext/redefined_variable_type/redefined_variable_type.rc create mode 100644 tests/functional/ext/redefined_variable_type/redefined_variable_type.txt delete mode 100644 tests/functional/ext/while_used.py delete mode 100644 tests/functional/ext/while_used.rc delete mode 100644 tests/functional/ext/while_used.txt create mode 100644 tests/functional/ext/while_used/while_used.py create mode 100644 tests/functional/ext/while_used/while_used.rc create mode 100644 tests/functional/ext/while_used/while_used.txt delete mode 100644 tests/functional/m/mccabe.py delete mode 100644 tests/functional/m/mccabe.rc delete mode 100644 tests/functional/m/mccabe.txt delete mode 100644 tests/functional/m/misplaced_comparison_constant.py delete mode 100644 tests/functional/m/misplaced_comparison_constant.rc delete mode 100644 tests/functional/m/misplaced_comparison_constant.txt delete mode 100644 tests/functional/m/missing/missing_param_doc.py delete mode 100644 tests/functional/m/missing/missing_param_doc.rc delete mode 100644 tests/functional/m/missing/missing_param_doc.txt delete mode 100644 tests/functional/o/overlapping_exceptions.py delete mode 100644 tests/functional/o/overlapping_exceptions.rc delete mode 100644 tests/functional/o/overlapping_exceptions.txt delete mode 100644 tests/functional/p/plugin_does_not_exists.py delete mode 100644 tests/functional/p/plugin_does_not_exists.rc delete mode 100644 tests/functional/p/plugin_does_not_exists.txt delete mode 100644 tests/functional/p/py_version/py_version_35.py delete mode 100644 tests/functional/p/py_version/py_version_35.rc delete mode 100644 tests/functional/r/redefined_variable_type.py delete mode 100644 tests/functional/r/redefined_variable_type.rc delete mode 100644 tests/functional/r/redefined_variable_type.txt delete mode 100644 tests/functional/u/useless/useless_type_doc.py delete mode 100644 tests/functional/u/useless/useless_type_doc.rc delete mode 100644 tests/functional/u/useless/useless_type_doc.txt diff --git a/tests/functional/b/bad_builtin_extension.py b/tests/functional/b/bad_builtin_extension.py deleted file mode 100644 index fd3e5c054..000000000 --- a/tests/functional/b/bad_builtin_extension.py +++ /dev/null @@ -1,4 +0,0 @@ -# pylint: disable=missing-docstring - -TEST = map(str, (1, 2, 3)) # [bad-builtin] -TEST1 = filter(str, (1, 2, 3)) # [bad-builtin] diff --git a/tests/functional/b/bad_builtin_extension.rc b/tests/functional/b/bad_builtin_extension.rc deleted file mode 100644 index de9b4244a..000000000 --- a/tests/functional/b/bad_builtin_extension.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.bad_builtin, diff --git a/tests/functional/b/bad_builtin_extension.txt b/tests/functional/b/bad_builtin_extension.txt deleted file mode 100644 index e074657b2..000000000 --- a/tests/functional/b/bad_builtin_extension.txt +++ /dev/null @@ -1,2 +0,0 @@ -bad-builtin:3:7::Used builtin function 'map'. Using a list comprehension can be clearer.:HIGH -bad-builtin:4:8::Used builtin function 'filter'. Using a list comprehension can be clearer.:HIGH diff --git a/tests/functional/b/broad_try_clause_extension.py b/tests/functional/b/broad_try_clause_extension.py deleted file mode 100644 index 6fc85c6b2..000000000 --- a/tests/functional/b/broad_try_clause_extension.py +++ /dev/null @@ -1,49 +0,0 @@ -# pylint: disable=missing-docstring, invalid-name - -MY_DICTIONARY = {"key_one": 1, "key_two": 2, "key_three": 3} - -try: # [too-many-try-statements] - value = MY_DICTIONARY["key_one"] - value += 1 - print("This one has an except clause only.") -except KeyError: - pass - -try: # [too-many-try-statements] - value = MY_DICTIONARY["key_one"] - value += 1 - print("This one has a finally clause only.") -finally: - pass - -try: # [too-many-try-statements] - value = MY_DICTIONARY["key_one"] - value += 1 - print("This one has an except clause...") - print("and also a finally clause!") -except KeyError: - pass -finally: - pass - -try: # [too-many-try-statements] - if "key_one" in MY_DICTIONARY: - entered_if_body = True - print("This verifies that content inside of an if statement is counted too.") - else: - entered_if_body = False - - while False: - print("This verifies that content inside of a while loop is counted too.") - - for item in []: - print("This verifies that content inside of a for loop is counted too.") - - -except KeyError: - pass - -try: - value = MY_DICTIONARY["key_one"] -except KeyError: - value = 0 diff --git a/tests/functional/b/broad_try_clause_extension.rc b/tests/functional/b/broad_try_clause_extension.rc deleted file mode 100644 index 1737783e0..000000000 --- a/tests/functional/b/broad_try_clause_extension.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.broad_try_clause, diff --git a/tests/functional/b/broad_try_clause_extension.txt b/tests/functional/b/broad_try_clause_extension.txt deleted file mode 100644 index 8f97f9b24..000000000 --- a/tests/functional/b/broad_try_clause_extension.txt +++ /dev/null @@ -1,4 +0,0 @@ -too-many-try-statements:5:0::try clause contains 3 statements, expected at most 1:HIGH -too-many-try-statements:12:0::try clause contains 3 statements, expected at most 1:HIGH -too-many-try-statements:19:0::try clause contains 4 statements, expected at most 1:HIGH -too-many-try-statements:29:0::try clause contains 7 statements, expected at most 1:HIGH diff --git a/tests/functional/c/compare_to_zero_extension.py b/tests/functional/c/compare_to_zero_extension.py deleted file mode 100644 index 29fd13994..000000000 --- a/tests/functional/c/compare_to_zero_extension.py +++ /dev/null @@ -1,28 +0,0 @@ -# pylint: disable=literal-comparison,missing-docstring - -X = 123 -Y = len('test') - -if X is 0: # [compare-to-zero] - pass - -if Y is not 0: # [compare-to-zero] - pass - -if X == 0: # [compare-to-zero] - pass - -if Y != 0: # [compare-to-zero] - pass - -if X > 0: - pass - -if X < 0: - pass - -if 0 < X: - pass - -if 0 > X: - pass diff --git a/tests/functional/c/compare_to_zero_extension.rc b/tests/functional/c/compare_to_zero_extension.rc deleted file mode 100644 index e9b836539..000000000 --- a/tests/functional/c/compare_to_zero_extension.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.comparetozero, diff --git a/tests/functional/c/compare_to_zero_extension.txt b/tests/functional/c/compare_to_zero_extension.txt deleted file mode 100644 index c5862e1b7..000000000 --- a/tests/functional/c/compare_to_zero_extension.txt +++ /dev/null @@ -1,4 +0,0 @@ -compare-to-zero:6:3::Avoid comparisons to zero:HIGH -compare-to-zero:9:3::Avoid comparisons to zero:HIGH -compare-to-zero:12:3::Avoid comparisons to zero:HIGH -compare-to-zero:15:3::Avoid comparisons to zero:HIGH diff --git a/tests/functional/d/docstyle_extension.py b/tests/functional/d/docstyle_extension.py deleted file mode 100644 index a5b6161b0..000000000 --- a/tests/functional/d/docstyle_extension.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Checks of Dosctrings 'docstring-first-line-empty' 'bad-docstring-quotes'""" - - -def check_messages(*messages): # [docstring-first-line-empty] - """ - docstring""" - return messages - - -def function2(): - """Test Ok""" - - -class FFFF: # [docstring-first-line-empty] - """ - Test Docstring First Line Empty - """ - - def method1(self): # [docstring-first-line-empty, bad-docstring-quotes] - ''' - Test Triple Single Quotes docstring - ''' - - def method2(self): # [bad-docstring-quotes] - "bad docstring 1" - - def method3(self): # [bad-docstring-quotes] - 'bad docstring 2' - - def method4(self): # [bad-docstring-quotes] - ' """bad docstring 3 ' - - @check_messages("bad-open-mode", "redundant-unittest-assert", "deprecated-module") - def method5(self): - """Test OK 1 with decorators""" - - def method6(self): - r"""Test OK 2 with raw string""" - - def method7(self): - u"""Test OK 3 with unicode string""" diff --git a/tests/functional/d/docstyle_extension.rc b/tests/functional/d/docstyle_extension.rc deleted file mode 100644 index 5128289ff..000000000 --- a/tests/functional/d/docstyle_extension.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.docstyle, diff --git a/tests/functional/d/docstyle_extension.txt b/tests/functional/d/docstyle_extension.txt deleted file mode 100644 index 8a30eedee..000000000 --- a/tests/functional/d/docstyle_extension.txt +++ /dev/null @@ -1,7 +0,0 @@ -docstring-first-line-empty:4:0:check_messages:First line empty in function docstring:HIGH -docstring-first-line-empty:14:0:FFFF:First line empty in class docstring:HIGH -bad-docstring-quotes:19:4:FFFF.method1:"Bad docstring quotes in method, expected """""", given '''":HIGH -docstring-first-line-empty:19:4:FFFF.method1:First line empty in method docstring:HIGH -bad-docstring-quotes:24:4:FFFF.method2:"Bad docstring quotes in method, expected """""", given """:HIGH -bad-docstring-quotes:27:4:FFFF.method3:"Bad docstring quotes in method, expected """""", given '":HIGH -bad-docstring-quotes:30:4:FFFF.method4:"Bad docstring quotes in method, expected """""", given '":HIGH diff --git a/tests/functional/e/elif_checker.py b/tests/functional/e/elif_checker.py deleted file mode 100644 index b9722f349..000000000 --- a/tests/functional/e/elif_checker.py +++ /dev/null @@ -1,27 +0,0 @@ -"""Checks use of "else if" triggers a refactor message""" - - -def my_function(): - """docstring""" - myint = 2 - if myint > 5: - pass - else: - if myint <= 5: # [else-if-used] - pass - else: - myint = 3 - if myint > 2: - if myint > 3: - pass - elif myint == 3: - pass - elif myint < 3: - pass - else: - if myint: # [else-if-used] - pass - else: - if myint: - pass - myint = 4 diff --git a/tests/functional/e/elif_checker.rc b/tests/functional/e/elif_checker.rc deleted file mode 100644 index b9b1de49d..000000000 --- a/tests/functional/e/elif_checker.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.check_elif, diff --git a/tests/functional/e/elif_checker.txt b/tests/functional/e/elif_checker.txt deleted file mode 100644 index 43d1e3b1e..000000000 --- a/tests/functional/e/elif_checker.txt +++ /dev/null @@ -1,2 +0,0 @@ -else-if-used:10:8:my_function:"Consider using ""elif"" instead of ""else if""":HIGH -else-if-used:22:20:my_function:"Consider using ""elif"" instead of ""else if""":HIGH diff --git a/tests/functional/e/empty_comment.py b/tests/functional/e/empty_comment.py deleted file mode 100644 index 6adaa4fc1..000000000 --- a/tests/functional/e/empty_comment.py +++ /dev/null @@ -1,13 +0,0 @@ -"""empty-comment test-case""" -# +1:[empty-comment] -A = 5 # -# +1:[empty-comment] -# -A = '#' + '1' -# +1:[empty-comment] -print(A) # -print("A=", A) # should not be an error# -# +1:[empty-comment] -A = "#pe\0ace#love#" # -A = "peace#love" # \0 peace'#'''' love#peace'''-'#love'-"peace#love"# -####### diff --git a/tests/functional/e/empty_comment.rc b/tests/functional/e/empty_comment.rc deleted file mode 100644 index 1bbd021e7..000000000 --- a/tests/functional/e/empty_comment.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.empty_comment, diff --git a/tests/functional/e/empty_comment.txt b/tests/functional/e/empty_comment.txt deleted file mode 100644 index ae4eee33e..000000000 --- a/tests/functional/e/empty_comment.txt +++ /dev/null @@ -1,4 +0,0 @@ -empty-comment:3:0::Line with empty comment:HIGH -empty-comment:5:0::Line with empty comment:HIGH -empty-comment:8:0::Line with empty comment:HIGH -empty-comment:11:0::Line with empty comment:HIGH diff --git a/tests/functional/e/empty_string_comparison.py b/tests/functional/e/empty_string_comparison.py deleted file mode 100644 index c6dcf8ea8..000000000 --- a/tests/functional/e/empty_string_comparison.py +++ /dev/null @@ -1,16 +0,0 @@ -# pylint: disable=literal-comparison,missing-docstring - -X = '' -Y = 'test' - -if X is '': # [compare-to-empty-string] - pass - -if Y is not "": # [compare-to-empty-string] - pass - -if X == "": # [compare-to-empty-string] - pass - -if Y != '': # [compare-to-empty-string] - pass diff --git a/tests/functional/e/empty_string_comparison.rc b/tests/functional/e/empty_string_comparison.rc deleted file mode 100644 index e6e3ded01..000000000 --- a/tests/functional/e/empty_string_comparison.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.emptystring, diff --git a/tests/functional/e/empty_string_comparison.txt b/tests/functional/e/empty_string_comparison.txt deleted file mode 100644 index 7e31c3d25..000000000 --- a/tests/functional/e/empty_string_comparison.txt +++ /dev/null @@ -1,4 +0,0 @@ -compare-to-empty-string:6:3::Avoid comparisons to empty string:HIGH -compare-to-empty-string:9:3::Avoid comparisons to empty string:HIGH -compare-to-empty-string:12:3::Avoid comparisons to empty string:HIGH -compare-to-empty-string:15:3::Avoid comparisons to empty string:HIGH diff --git a/tests/functional/ext/bad_builtin/bad_builtin_extension.py b/tests/functional/ext/bad_builtin/bad_builtin_extension.py new file mode 100644 index 000000000..fd3e5c054 --- /dev/null +++ b/tests/functional/ext/bad_builtin/bad_builtin_extension.py @@ -0,0 +1,4 @@ +# pylint: disable=missing-docstring + +TEST = map(str, (1, 2, 3)) # [bad-builtin] +TEST1 = filter(str, (1, 2, 3)) # [bad-builtin] diff --git a/tests/functional/ext/bad_builtin/bad_builtin_extension.rc b/tests/functional/ext/bad_builtin/bad_builtin_extension.rc new file mode 100644 index 000000000..de9b4244a --- /dev/null +++ b/tests/functional/ext/bad_builtin/bad_builtin_extension.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.bad_builtin, diff --git a/tests/functional/ext/bad_builtin/bad_builtin_extension.txt b/tests/functional/ext/bad_builtin/bad_builtin_extension.txt new file mode 100644 index 000000000..e074657b2 --- /dev/null +++ b/tests/functional/ext/bad_builtin/bad_builtin_extension.txt @@ -0,0 +1,2 @@ +bad-builtin:3:7::Used builtin function 'map'. Using a list comprehension can be clearer.:HIGH +bad-builtin:4:8::Used builtin function 'filter'. Using a list comprehension can be clearer.:HIGH diff --git a/tests/functional/ext/bad_builtin/bad_builtins.py b/tests/functional/ext/bad_builtin/bad_builtins.py new file mode 100644 index 000000000..9737e0ffc --- /dev/null +++ b/tests/functional/ext/bad_builtin/bad_builtins.py @@ -0,0 +1,3 @@ +# pylint: disable=missing-docstring +input("Yes or no ? (Y=1, n=0)") # [bad-builtin] +print(map(str, filter(1, [1, 2, 3]))) # [bad-builtin, bad-builtin, bad-builtin] diff --git a/tests/functional/ext/bad_builtin/bad_builtins.rc b/tests/functional/ext/bad_builtin/bad_builtins.rc new file mode 100644 index 000000000..e32b9f32c --- /dev/null +++ b/tests/functional/ext/bad_builtin/bad_builtins.rc @@ -0,0 +1,5 @@ +[MASTER] +load-plugins = pylint.extensions.bad_builtin + +[pylint.DEPRECATED_BUILTINS] +bad-functions=map,input,filter,print diff --git a/tests/functional/ext/bad_builtin/bad_builtins.txt b/tests/functional/ext/bad_builtin/bad_builtins.txt new file mode 100644 index 000000000..093b1d1e5 --- /dev/null +++ b/tests/functional/ext/bad_builtin/bad_builtins.txt @@ -0,0 +1,4 @@ +bad-builtin:2:0::Used builtin function 'input' +bad-builtin:3:15::Used builtin function 'filter'. Using a list comprehension can be clearer. +bad-builtin:3:6::Used builtin function 'map'. Using a list comprehension can be clearer. +bad-builtin:3:0::Used builtin function 'print' diff --git a/tests/functional/ext/bad_builtins.py b/tests/functional/ext/bad_builtins.py deleted file mode 100644 index 9737e0ffc..000000000 --- a/tests/functional/ext/bad_builtins.py +++ /dev/null @@ -1,3 +0,0 @@ -# pylint: disable=missing-docstring -input("Yes or no ? (Y=1, n=0)") # [bad-builtin] -print(map(str, filter(1, [1, 2, 3]))) # [bad-builtin, bad-builtin, bad-builtin] diff --git a/tests/functional/ext/bad_builtins.rc b/tests/functional/ext/bad_builtins.rc deleted file mode 100644 index e32b9f32c..000000000 --- a/tests/functional/ext/bad_builtins.rc +++ /dev/null @@ -1,5 +0,0 @@ -[MASTER] -load-plugins = pylint.extensions.bad_builtin - -[pylint.DEPRECATED_BUILTINS] -bad-functions=map,input,filter,print diff --git a/tests/functional/ext/bad_builtins.txt b/tests/functional/ext/bad_builtins.txt deleted file mode 100644 index 093b1d1e5..000000000 --- a/tests/functional/ext/bad_builtins.txt +++ /dev/null @@ -1,4 +0,0 @@ -bad-builtin:2:0::Used builtin function 'input' -bad-builtin:3:15::Used builtin function 'filter'. Using a list comprehension can be clearer. -bad-builtin:3:6::Used builtin function 'map'. Using a list comprehension can be clearer. -bad-builtin:3:0::Used builtin function 'print' diff --git a/tests/functional/ext/broad_try_clause/broad_try_clause_extension.py b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.py new file mode 100644 index 000000000..6fc85c6b2 --- /dev/null +++ b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.py @@ -0,0 +1,49 @@ +# pylint: disable=missing-docstring, invalid-name + +MY_DICTIONARY = {"key_one": 1, "key_two": 2, "key_three": 3} + +try: # [too-many-try-statements] + value = MY_DICTIONARY["key_one"] + value += 1 + print("This one has an except clause only.") +except KeyError: + pass + +try: # [too-many-try-statements] + value = MY_DICTIONARY["key_one"] + value += 1 + print("This one has a finally clause only.") +finally: + pass + +try: # [too-many-try-statements] + value = MY_DICTIONARY["key_one"] + value += 1 + print("This one has an except clause...") + print("and also a finally clause!") +except KeyError: + pass +finally: + pass + +try: # [too-many-try-statements] + if "key_one" in MY_DICTIONARY: + entered_if_body = True + print("This verifies that content inside of an if statement is counted too.") + else: + entered_if_body = False + + while False: + print("This verifies that content inside of a while loop is counted too.") + + for item in []: + print("This verifies that content inside of a for loop is counted too.") + + +except KeyError: + pass + +try: + value = MY_DICTIONARY["key_one"] +except KeyError: + value = 0 diff --git a/tests/functional/ext/broad_try_clause/broad_try_clause_extension.rc b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.rc new file mode 100644 index 000000000..1737783e0 --- /dev/null +++ b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.broad_try_clause, diff --git a/tests/functional/ext/broad_try_clause/broad_try_clause_extension.txt b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.txt new file mode 100644 index 000000000..8f97f9b24 --- /dev/null +++ b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.txt @@ -0,0 +1,4 @@ +too-many-try-statements:5:0::try clause contains 3 statements, expected at most 1:HIGH +too-many-try-statements:12:0::try clause contains 3 statements, expected at most 1:HIGH +too-many-try-statements:19:0::try clause contains 4 statements, expected at most 1:HIGH +too-many-try-statements:29:0::try clause contains 7 statements, expected at most 1:HIGH diff --git a/tests/functional/ext/check_elif/elif_checker.py b/tests/functional/ext/check_elif/elif_checker.py new file mode 100644 index 000000000..b9722f349 --- /dev/null +++ b/tests/functional/ext/check_elif/elif_checker.py @@ -0,0 +1,27 @@ +"""Checks use of "else if" triggers a refactor message""" + + +def my_function(): + """docstring""" + myint = 2 + if myint > 5: + pass + else: + if myint <= 5: # [else-if-used] + pass + else: + myint = 3 + if myint > 2: + if myint > 3: + pass + elif myint == 3: + pass + elif myint < 3: + pass + else: + if myint: # [else-if-used] + pass + else: + if myint: + pass + myint = 4 diff --git a/tests/functional/ext/check_elif/elif_checker.rc b/tests/functional/ext/check_elif/elif_checker.rc new file mode 100644 index 000000000..b9b1de49d --- /dev/null +++ b/tests/functional/ext/check_elif/elif_checker.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.check_elif, diff --git a/tests/functional/ext/check_elif/elif_checker.txt b/tests/functional/ext/check_elif/elif_checker.txt new file mode 100644 index 000000000..43d1e3b1e --- /dev/null +++ b/tests/functional/ext/check_elif/elif_checker.txt @@ -0,0 +1,2 @@ +else-if-used:10:8:my_function:"Consider using ""elif"" instead of ""else if""":HIGH +else-if-used:22:20:my_function:"Consider using ""elif"" instead of ""else if""":HIGH diff --git a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.py b/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.py deleted file mode 100644 index 4f9a83700..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.py +++ /dev/null @@ -1,159 +0,0 @@ -# pylint: disable=missing-docstring,invalid-name,undefined-variable,too-few-public-methods - -a1 = 2 -if a1: # [consider-using-assignment-expr] - ... - -# Do not suggest assignment expressions if assignment spans multiple lines -a2 = ( - 1, -) -if a2: - ... - -# Only first name should be replaced -a3 = 2 -if a3 == a3_a: # [consider-using-assignment-expr] - ... - -# Above black line length -a4 = some_loooooooonnnnnngggg_object_name.with_some_really_long_function_name(arg) -if a4: - ... - -def func_a(): - a5 = some___object.function_name_is_just_long_enough_to_fit_in_line() # some comment - if a5 is None: # [consider-using-assignment-expr] - ... - - # Using assignment expression would result in line being 89 chars long - a6 = some_long_object.function_name_is_too_long_enough_to_fit___line() - if a6 is None: - ... - -# Previous unrelate note should not match -print("") -if a7: - ... - - -b1: int = 2 -if b1: # [consider-using-assignment-expr] - ... - -b2 = some_function(2, 3) -if b2: # [consider-using-assignment-expr] - ... - -b3 = some_object.variable -if b3: # [consider-using-assignment-expr] - ... - - -# UnaryOp -c1 = 2 -if not c1: # [consider-using-assignment-expr] - ... - - -# Compare -d1 = 2 -if d1 is True: # [consider-using-assignment-expr] - ... - -d2 = 2 -if d2 is not None: # [consider-using-assignment-expr] - ... - -d3 = 2 -if d3 == 2: # [consider-using-assignment-expr] - ... - - -# ----- -# Don't emit warning if match statement would be a better fit -o1 = 2 -if o1 == 1: - ... -elif o1 == 2: - ... -elif o1 == 3: - ... - -o2 = 2 -if o2 == 1: - ... -elif o2: - ... - -o3 = 2 -if o3 == 1: # [consider-using-assignment-expr] - ... -else: - ... - -o4 = 2 -if o4 == 1: # [consider-using-assignment-expr] - ... -elif o4 and o4_other: - ... - -o5 = 2 -if o5 == 1: # [consider-using-assignment-expr] - ... -elif o5_other == 1: - ... - -o6 = 2 -if o6 == 1: # [consider-using-assignment-expr] - ... -elif o6_other: - ... - -def func_p(): - p1 = 2 - if p1 == 1: - return - if p1 == 2: - return - - p2 = 2 - if p2 == 1: - return - if p2: - return - - p3 = 2 - if p3 == 1: # [consider-using-assignment-expr] - ... - else: - ... - - p4 = 2 - if p4 == 1: # [consider-using-assignment-expr] - ... - elif p4 and p4_other: - ... - - p5 = 2 - if p5 == 1: # [consider-using-assignment-expr] - ... - elif p5_other == 1: - ... - - p6 = 2 - if p6 == 1: # [consider-using-assignment-expr] - ... - elif p6_other: - ... - - -# ----- -# Assignment expression does NOT work for attribute access -# Make sure not to emit message! -class A: - var = 1 - -A.var = 2 -if A.var: - ... diff --git a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.rc b/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.rc deleted file mode 100644 index 2a659c07d..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.rc +++ /dev/null @@ -1,6 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.code_style -py-version=3.8 - -[CODE_STYLE] -max-line-length-suggestions=88 diff --git a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.txt b/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.txt deleted file mode 100644 index 64179ba72..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.txt +++ /dev/null @@ -1,18 +0,0 @@ -consider-using-assignment-expr:4:3::"Use 'if (a1 := 2):' instead":HIGH -consider-using-assignment-expr:16:3::"Use 'if (a3 := 2) == a3_a:' instead":HIGH -consider-using-assignment-expr:26:7:func_a:"Use 'if (a5 := some___object.function_name_is_just_long_enough_to_fit_in_line()) is None:' instead":HIGH -consider-using-assignment-expr:41:3::"Use 'if (b1 := 2):' instead":HIGH -consider-using-assignment-expr:45:3::"Use 'if (b2 := some_function(2, 3)):' instead":HIGH -consider-using-assignment-expr:49:3::"Use 'if (b3 := some_object.variable):' instead":HIGH -consider-using-assignment-expr:55:7::"Use 'if not (c1 := 2):' instead":HIGH -consider-using-assignment-expr:61:3::"Use 'if (d1 := 2) is True:' instead":HIGH -consider-using-assignment-expr:65:3::"Use 'if (d2 := 2) is not None:' instead":HIGH -consider-using-assignment-expr:69:3::"Use 'if (d3 := 2) == 2:' instead":HIGH -consider-using-assignment-expr:90:3::"Use 'if (o3 := 2) == 1:' instead":HIGH -consider-using-assignment-expr:96:3::"Use 'if (o4 := 2) == 1:' instead":HIGH -consider-using-assignment-expr:102:3::"Use 'if (o5 := 2) == 1:' instead":HIGH -consider-using-assignment-expr:108:3::"Use 'if (o6 := 2) == 1:' instead":HIGH -consider-using-assignment-expr:127:7:func_p:"Use 'if (p3 := 2) == 1:' instead":HIGH -consider-using-assignment-expr:133:7:func_p:"Use 'if (p4 := 2) == 1:' instead":HIGH -consider-using-assignment-expr:139:7:func_p:"Use 'if (p5 := 2) == 1:' instead":HIGH -consider-using-assignment-expr:145:7:func_p:"Use 'if (p6 := 2) == 1:' instead":HIGH diff --git a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.py b/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.py deleted file mode 100644 index 627de7684..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.py +++ /dev/null @@ -1,74 +0,0 @@ -# pylint: disable=missing-docstring,too-few-public-methods,unused-variable,no-name-in-module -from typing import Final - -class Foo: - BAR = "bar" - -KEY_3 = "key_3" - - -# Subdicts have at least 1 common key -MAPPING_1 = { # [consider-using-namedtuple-or-dataclass] - "entry_1": {"key_1": 0, "key_2": 1, "key_diff_1": 2}, - "entry_2": {"key_1": 0, "key_2": 1, "key_diff_2": 3}, -} -MAPPING_2 = { # [consider-using-namedtuple-or-dataclass] - "entry_1": {KEY_3: None, Foo.BAR: None}, - "entry_2": {KEY_3: None, Foo.BAR: None}, -} - -# ints are not valid fieldnames for namedtuples -MAPPING_3 = { - "entry_1": {0: None, 1: None}, - "entry_2": {0: None, 1: None}, -} - - -def func(): - # Not in module scope - mapping_4 = { - "entry_1": {"key_1": 0, "key_2": 1}, - "entry_2": {"key_1": 0, "key_2": 1}, - } - - mapping_5: Final = { # [consider-using-namedtuple-or-dataclass] - "entry_1": {"key_1": 0, "key_2": 1}, - "entry_2": {"key_1": 0, "key_2": 1}, - } - - -# lists must have the same length -MAPPING_6 = { # [consider-using-namedtuple-or-dataclass] - "entry_1": [1, "a", set()], - "entry_2": [2, "b", set()], -} -MAPPING_7 = { - "entry_1": [], - "entry_2": [], -} -MAPPING_8 = { - "entry_1": [1], - "entry_2": [2, "b"], -} -MAPPING_9 = { # [consider-using-namedtuple-or-dataclass] - "entry_1": (1, "a"), - "entry_2": (2, "b"), -} - -# No entry can't contain only dicts -MAPPING_10 = { - "entry_1": [ - {"key_1": None, "key_2": None}, - ], - "entry_2": [None] -} - -# No either dict, tuple, or list as dict values -MAPPING_11 = { - "entry_1": 1, - "entry_2": 2, -} -MAPPING_12 = { - "entry_1": "", - "entry_2": "", -} diff --git a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.rc b/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.rc deleted file mode 100644 index 47767a206..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.code_style diff --git a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.txt b/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.txt deleted file mode 100644 index 6c471db96..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.txt +++ /dev/null @@ -1,5 +0,0 @@ -consider-using-namedtuple-or-dataclass:11:12::Consider using namedtuple or dataclass for dictionary values -consider-using-namedtuple-or-dataclass:15:12::Consider using namedtuple or dataclass for dictionary values -consider-using-namedtuple-or-dataclass:34:23:func:Consider using namedtuple or dataclass for dictionary values -consider-using-namedtuple-or-dataclass:41:12::Consider using namedtuple or dataclass for dictionary values -consider-using-namedtuple-or-dataclass:53:12::Consider using namedtuple or dataclass for dictionary values diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.py b/tests/functional/ext/code_style/code_style_consider_using_tuple.py deleted file mode 100644 index d24396079..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.py +++ /dev/null @@ -1,31 +0,0 @@ -# pylint: disable=invalid-name,missing-docstring,pointless-statement,unnecessary-comprehension - -var = (1, 2, 3) - -for x in var: - pass -for x in (1, 2, 3): - pass -for x in [1, 2, 3]: # [consider-using-tuple] - pass - -(x for x in var) -(x for x in (1, 2, 3)) -(x for x in [1, 2, 3]) # [consider-using-tuple] - -[x for x in var] -[x for x in (1, 2, 3)] -[x for x in [1, 2, 3]] # [consider-using-tuple] - - -for x in [*var]: # [consider-using-tuple] - pass -for x in [2, *var]: # [consider-using-tuple] - pass - -[x for x in [*var, 2]] # [consider-using-tuple] - - -# Don't emit warning for sets as this is handled by builtin checker -(x for x in {1, 2, 3}) # [use-sequence-for-iteration] -[x for x in {*var, 2}] # [use-sequence-for-iteration] diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.rc b/tests/functional/ext/code_style/code_style_consider_using_tuple.rc deleted file mode 100644 index 47767a206..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.code_style diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.txt b/tests/functional/ext/code_style/code_style_consider_using_tuple.txt deleted file mode 100644 index 167c8c037..000000000 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.txt +++ /dev/null @@ -1,8 +0,0 @@ -consider-using-tuple:9:9::Consider using an in-place tuple instead of list -consider-using-tuple:14:12::Consider using an in-place tuple instead of list -consider-using-tuple:18:12::Consider using an in-place tuple instead of list -consider-using-tuple:21:9::Consider using an in-place tuple instead of list -consider-using-tuple:23:9::Consider using an in-place tuple instead of list -consider-using-tuple:26:12::Consider using an in-place tuple instead of list -use-sequence-for-iteration:30:12::Use a sequence type when iterating over values -use-sequence-for-iteration:31:12::Use a sequence type when iterating over values diff --git a/tests/functional/ext/code_style/consider_using_assignment_expr.py b/tests/functional/ext/code_style/consider_using_assignment_expr.py new file mode 100644 index 000000000..4f9a83700 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_assignment_expr.py @@ -0,0 +1,159 @@ +# pylint: disable=missing-docstring,invalid-name,undefined-variable,too-few-public-methods + +a1 = 2 +if a1: # [consider-using-assignment-expr] + ... + +# Do not suggest assignment expressions if assignment spans multiple lines +a2 = ( + 1, +) +if a2: + ... + +# Only first name should be replaced +a3 = 2 +if a3 == a3_a: # [consider-using-assignment-expr] + ... + +# Above black line length +a4 = some_loooooooonnnnnngggg_object_name.with_some_really_long_function_name(arg) +if a4: + ... + +def func_a(): + a5 = some___object.function_name_is_just_long_enough_to_fit_in_line() # some comment + if a5 is None: # [consider-using-assignment-expr] + ... + + # Using assignment expression would result in line being 89 chars long + a6 = some_long_object.function_name_is_too_long_enough_to_fit___line() + if a6 is None: + ... + +# Previous unrelate note should not match +print("") +if a7: + ... + + +b1: int = 2 +if b1: # [consider-using-assignment-expr] + ... + +b2 = some_function(2, 3) +if b2: # [consider-using-assignment-expr] + ... + +b3 = some_object.variable +if b3: # [consider-using-assignment-expr] + ... + + +# UnaryOp +c1 = 2 +if not c1: # [consider-using-assignment-expr] + ... + + +# Compare +d1 = 2 +if d1 is True: # [consider-using-assignment-expr] + ... + +d2 = 2 +if d2 is not None: # [consider-using-assignment-expr] + ... + +d3 = 2 +if d3 == 2: # [consider-using-assignment-expr] + ... + + +# ----- +# Don't emit warning if match statement would be a better fit +o1 = 2 +if o1 == 1: + ... +elif o1 == 2: + ... +elif o1 == 3: + ... + +o2 = 2 +if o2 == 1: + ... +elif o2: + ... + +o3 = 2 +if o3 == 1: # [consider-using-assignment-expr] + ... +else: + ... + +o4 = 2 +if o4 == 1: # [consider-using-assignment-expr] + ... +elif o4 and o4_other: + ... + +o5 = 2 +if o5 == 1: # [consider-using-assignment-expr] + ... +elif o5_other == 1: + ... + +o6 = 2 +if o6 == 1: # [consider-using-assignment-expr] + ... +elif o6_other: + ... + +def func_p(): + p1 = 2 + if p1 == 1: + return + if p1 == 2: + return + + p2 = 2 + if p2 == 1: + return + if p2: + return + + p3 = 2 + if p3 == 1: # [consider-using-assignment-expr] + ... + else: + ... + + p4 = 2 + if p4 == 1: # [consider-using-assignment-expr] + ... + elif p4 and p4_other: + ... + + p5 = 2 + if p5 == 1: # [consider-using-assignment-expr] + ... + elif p5_other == 1: + ... + + p6 = 2 + if p6 == 1: # [consider-using-assignment-expr] + ... + elif p6_other: + ... + + +# ----- +# Assignment expression does NOT work for attribute access +# Make sure not to emit message! +class A: + var = 1 + +A.var = 2 +if A.var: + ... diff --git a/tests/functional/ext/code_style/consider_using_assignment_expr.rc b/tests/functional/ext/code_style/consider_using_assignment_expr.rc new file mode 100644 index 000000000..2a659c07d --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_assignment_expr.rc @@ -0,0 +1,6 @@ +[MASTER] +load-plugins=pylint.extensions.code_style +py-version=3.8 + +[CODE_STYLE] +max-line-length-suggestions=88 diff --git a/tests/functional/ext/code_style/consider_using_assignment_expr.txt b/tests/functional/ext/code_style/consider_using_assignment_expr.txt new file mode 100644 index 000000000..64179ba72 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_assignment_expr.txt @@ -0,0 +1,18 @@ +consider-using-assignment-expr:4:3::"Use 'if (a1 := 2):' instead":HIGH +consider-using-assignment-expr:16:3::"Use 'if (a3 := 2) == a3_a:' instead":HIGH +consider-using-assignment-expr:26:7:func_a:"Use 'if (a5 := some___object.function_name_is_just_long_enough_to_fit_in_line()) is None:' instead":HIGH +consider-using-assignment-expr:41:3::"Use 'if (b1 := 2):' instead":HIGH +consider-using-assignment-expr:45:3::"Use 'if (b2 := some_function(2, 3)):' instead":HIGH +consider-using-assignment-expr:49:3::"Use 'if (b3 := some_object.variable):' instead":HIGH +consider-using-assignment-expr:55:7::"Use 'if not (c1 := 2):' instead":HIGH +consider-using-assignment-expr:61:3::"Use 'if (d1 := 2) is True:' instead":HIGH +consider-using-assignment-expr:65:3::"Use 'if (d2 := 2) is not None:' instead":HIGH +consider-using-assignment-expr:69:3::"Use 'if (d3 := 2) == 2:' instead":HIGH +consider-using-assignment-expr:90:3::"Use 'if (o3 := 2) == 1:' instead":HIGH +consider-using-assignment-expr:96:3::"Use 'if (o4 := 2) == 1:' instead":HIGH +consider-using-assignment-expr:102:3::"Use 'if (o5 := 2) == 1:' instead":HIGH +consider-using-assignment-expr:108:3::"Use 'if (o6 := 2) == 1:' instead":HIGH +consider-using-assignment-expr:127:7:func_p:"Use 'if (p3 := 2) == 1:' instead":HIGH +consider-using-assignment-expr:133:7:func_p:"Use 'if (p4 := 2) == 1:' instead":HIGH +consider-using-assignment-expr:139:7:func_p:"Use 'if (p5 := 2) == 1:' instead":HIGH +consider-using-assignment-expr:145:7:func_p:"Use 'if (p6 := 2) == 1:' instead":HIGH diff --git a/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.py b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.py new file mode 100644 index 000000000..627de7684 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.py @@ -0,0 +1,74 @@ +# pylint: disable=missing-docstring,too-few-public-methods,unused-variable,no-name-in-module +from typing import Final + +class Foo: + BAR = "bar" + +KEY_3 = "key_3" + + +# Subdicts have at least 1 common key +MAPPING_1 = { # [consider-using-namedtuple-or-dataclass] + "entry_1": {"key_1": 0, "key_2": 1, "key_diff_1": 2}, + "entry_2": {"key_1": 0, "key_2": 1, "key_diff_2": 3}, +} +MAPPING_2 = { # [consider-using-namedtuple-or-dataclass] + "entry_1": {KEY_3: None, Foo.BAR: None}, + "entry_2": {KEY_3: None, Foo.BAR: None}, +} + +# ints are not valid fieldnames for namedtuples +MAPPING_3 = { + "entry_1": {0: None, 1: None}, + "entry_2": {0: None, 1: None}, +} + + +def func(): + # Not in module scope + mapping_4 = { + "entry_1": {"key_1": 0, "key_2": 1}, + "entry_2": {"key_1": 0, "key_2": 1}, + } + + mapping_5: Final = { # [consider-using-namedtuple-or-dataclass] + "entry_1": {"key_1": 0, "key_2": 1}, + "entry_2": {"key_1": 0, "key_2": 1}, + } + + +# lists must have the same length +MAPPING_6 = { # [consider-using-namedtuple-or-dataclass] + "entry_1": [1, "a", set()], + "entry_2": [2, "b", set()], +} +MAPPING_7 = { + "entry_1": [], + "entry_2": [], +} +MAPPING_8 = { + "entry_1": [1], + "entry_2": [2, "b"], +} +MAPPING_9 = { # [consider-using-namedtuple-or-dataclass] + "entry_1": (1, "a"), + "entry_2": (2, "b"), +} + +# No entry can't contain only dicts +MAPPING_10 = { + "entry_1": [ + {"key_1": None, "key_2": None}, + ], + "entry_2": [None] +} + +# No either dict, tuple, or list as dict values +MAPPING_11 = { + "entry_1": 1, + "entry_2": 2, +} +MAPPING_12 = { + "entry_1": "", + "entry_2": "", +} diff --git a/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.rc b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.rc new file mode 100644 index 000000000..47767a206 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.code_style diff --git a/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.txt b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.txt new file mode 100644 index 000000000..6c471db96 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.txt @@ -0,0 +1,5 @@ +consider-using-namedtuple-or-dataclass:11:12::Consider using namedtuple or dataclass for dictionary values +consider-using-namedtuple-or-dataclass:15:12::Consider using namedtuple or dataclass for dictionary values +consider-using-namedtuple-or-dataclass:34:23:func:Consider using namedtuple or dataclass for dictionary values +consider-using-namedtuple-or-dataclass:41:12::Consider using namedtuple or dataclass for dictionary values +consider-using-namedtuple-or-dataclass:53:12::Consider using namedtuple or dataclass for dictionary values diff --git a/tests/functional/ext/code_style/consider_using_tuple.py b/tests/functional/ext/code_style/consider_using_tuple.py new file mode 100644 index 000000000..d24396079 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_tuple.py @@ -0,0 +1,31 @@ +# pylint: disable=invalid-name,missing-docstring,pointless-statement,unnecessary-comprehension + +var = (1, 2, 3) + +for x in var: + pass +for x in (1, 2, 3): + pass +for x in [1, 2, 3]: # [consider-using-tuple] + pass + +(x for x in var) +(x for x in (1, 2, 3)) +(x for x in [1, 2, 3]) # [consider-using-tuple] + +[x for x in var] +[x for x in (1, 2, 3)] +[x for x in [1, 2, 3]] # [consider-using-tuple] + + +for x in [*var]: # [consider-using-tuple] + pass +for x in [2, *var]: # [consider-using-tuple] + pass + +[x for x in [*var, 2]] # [consider-using-tuple] + + +# Don't emit warning for sets as this is handled by builtin checker +(x for x in {1, 2, 3}) # [use-sequence-for-iteration] +[x for x in {*var, 2}] # [use-sequence-for-iteration] diff --git a/tests/functional/ext/code_style/consider_using_tuple.rc b/tests/functional/ext/code_style/consider_using_tuple.rc new file mode 100644 index 000000000..47767a206 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_tuple.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.code_style diff --git a/tests/functional/ext/code_style/consider_using_tuple.txt b/tests/functional/ext/code_style/consider_using_tuple.txt new file mode 100644 index 000000000..167c8c037 --- /dev/null +++ b/tests/functional/ext/code_style/consider_using_tuple.txt @@ -0,0 +1,8 @@ +consider-using-tuple:9:9::Consider using an in-place tuple instead of list +consider-using-tuple:14:12::Consider using an in-place tuple instead of list +consider-using-tuple:18:12::Consider using an in-place tuple instead of list +consider-using-tuple:21:9::Consider using an in-place tuple instead of list +consider-using-tuple:23:9::Consider using an in-place tuple instead of list +consider-using-tuple:26:12::Consider using an in-place tuple instead of list +use-sequence-for-iteration:30:12::Use a sequence type when iterating over values +use-sequence-for-iteration:31:12::Use a sequence type when iterating over values diff --git a/tests/functional/ext/code_style/py_version_35.py b/tests/functional/ext/code_style/py_version_35.py new file mode 100644 index 000000000..ee880c54a --- /dev/null +++ b/tests/functional/ext/code_style/py_version_35.py @@ -0,0 +1,14 @@ +"""Test warnings aren't emitted for features that require Python > 3.5""" +# pylint: disable=invalid-name + +# consider-using-f-string -> requires Python 3.6 +"Hello {}".format("World") + + +# ------ +# CodeStyle extension + +# consider-using-assignment-expr -> requires Python 3.8 +a1 = 2 +if a1: + ... diff --git a/tests/functional/ext/code_style/py_version_35.rc b/tests/functional/ext/code_style/py_version_35.rc new file mode 100644 index 000000000..6f19ec36a --- /dev/null +++ b/tests/functional/ext/code_style/py_version_35.rc @@ -0,0 +1,3 @@ +[MASTER] +load-plugins=pylint.extensions.code_style +py-version=3.5 diff --git a/tests/functional/ext/comparetozero/compare_to_zero_extension.py b/tests/functional/ext/comparetozero/compare_to_zero_extension.py new file mode 100644 index 000000000..29fd13994 --- /dev/null +++ b/tests/functional/ext/comparetozero/compare_to_zero_extension.py @@ -0,0 +1,28 @@ +# pylint: disable=literal-comparison,missing-docstring + +X = 123 +Y = len('test') + +if X is 0: # [compare-to-zero] + pass + +if Y is not 0: # [compare-to-zero] + pass + +if X == 0: # [compare-to-zero] + pass + +if Y != 0: # [compare-to-zero] + pass + +if X > 0: + pass + +if X < 0: + pass + +if 0 < X: + pass + +if 0 > X: + pass diff --git a/tests/functional/ext/comparetozero/compare_to_zero_extension.rc b/tests/functional/ext/comparetozero/compare_to_zero_extension.rc new file mode 100644 index 000000000..e9b836539 --- /dev/null +++ b/tests/functional/ext/comparetozero/compare_to_zero_extension.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.comparetozero, diff --git a/tests/functional/ext/comparetozero/compare_to_zero_extension.txt b/tests/functional/ext/comparetozero/compare_to_zero_extension.txt new file mode 100644 index 000000000..c5862e1b7 --- /dev/null +++ b/tests/functional/ext/comparetozero/compare_to_zero_extension.txt @@ -0,0 +1,4 @@ +compare-to-zero:6:3::Avoid comparisons to zero:HIGH +compare-to-zero:9:3::Avoid comparisons to zero:HIGH +compare-to-zero:12:3::Avoid comparisons to zero:HIGH +compare-to-zero:15:3::Avoid comparisons to zero:HIGH diff --git a/tests/functional/ext/comparison_placement/misplaced_comparison_constant.py b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.py new file mode 100644 index 000000000..0162187bf --- /dev/null +++ b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.py @@ -0,0 +1,49 @@ +"""Check that the constants are on the right side of the comparisons""" + +# pylint: disable=singleton-comparison, missing-docstring, too-few-public-methods, useless-object-inheritance + +class MyClass(object): + def __init__(self): + self.attr = 1 + + def dummy_return(self): + return self.attr + +def dummy_return(): + return 2 + +def bad_comparisons(): + """this is not ok""" + instance = MyClass() + for i in range(10): + if 5 <= i: # [misplaced-comparison-constant] + pass + if 1 == i: # [misplaced-comparison-constant] + pass + if 3 < dummy_return(): # [misplaced-comparison-constant] + pass + if 4 != instance.dummy_return(): # [misplaced-comparison-constant] + pass + if 1 == instance.attr: # [misplaced-comparison-constant] + pass + if "aaa" == instance.attr: # [misplaced-comparison-constant] + pass + +def good_comparison(): + """this is ok""" + for i in range(10): + if i == 5: + pass + +def double_comparison(): + """Check that we return early for non-binary comparison""" + for i in range(10): + if i == 1 == 2: + pass + if 2 <= i <= 8: + print("Between 2 and 8 inclusive") + +def const_comparison(): + """Check that we return early for comparison of two constants""" + if 1 == 2: + pass diff --git a/tests/functional/ext/comparison_placement/misplaced_comparison_constant.rc b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.rc new file mode 100644 index 000000000..a8df8ab8b --- /dev/null +++ b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.comparison_placement, diff --git a/tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt new file mode 100644 index 000000000..b517b499e --- /dev/null +++ b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt @@ -0,0 +1,6 @@ +misplaced-comparison-constant:19:11:bad_comparisons:Comparison should be i >= 5 +misplaced-comparison-constant:21:11:bad_comparisons:Comparison should be i == 1 +misplaced-comparison-constant:23:11:bad_comparisons:Comparison should be dummy_return() > 3 +misplaced-comparison-constant:25:11:bad_comparisons:Comparison should be instance.dummy_return() != 4 +misplaced-comparison-constant:27:11:bad_comparisons:Comparison should be instance.attr == 1 +misplaced-comparison-constant:29:11:bad_comparisons:Comparison should be instance.attr == 'aaa' diff --git a/tests/functional/ext/confusing_elif.py b/tests/functional/ext/confusing_elif.py deleted file mode 100644 index 9f1d1ffe9..000000000 --- a/tests/functional/ext/confusing_elif.py +++ /dev/null @@ -1,41 +0,0 @@ -# pylint: disable=missing-module-docstring, missing-function-docstring - -def check_config(machine, old_conf, new_conf): - """Example code that will trigger the message""" - if old_conf: - if not new_conf: - machine.disable() - elif old_conf.value != new_conf.value: - machine.disable() - machine.enable(new_conf.value) - elif new_conf: # [confusing-consecutive-elif] - machine.enable(new_conf.value) - - -def check_config_2(machine, old_conf, new_conf): - """Example code must not trigger the message, because the inner block ends with else.""" - if old_conf: - if not new_conf: - machine.disable() - elif old_conf.value != new_conf.value: - machine.disable() - machine.enable(new_conf.value) - else: - pass - elif new_conf: - machine.enable(new_conf.value) - -def check_config_3(machine, old_conf, new_conf): - """ - Example code must not trigger the message, - because the inner if is not the final node of the body. - """ - if old_conf: - if not new_conf: - machine.disable() - elif old_conf.value != new_conf.value: - machine.disable() - machine.enable(new_conf.value) - print("Processed old configuration...") - elif new_conf: - machine.enable(new_conf.value) diff --git a/tests/functional/ext/confusing_elif.rc b/tests/functional/ext/confusing_elif.rc deleted file mode 100644 index 6a11b2c09..000000000 --- a/tests/functional/ext/confusing_elif.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.confusing_elif diff --git a/tests/functional/ext/confusing_elif.txt b/tests/functional/ext/confusing_elif.txt deleted file mode 100644 index 55cc0d13f..000000000 --- a/tests/functional/ext/confusing_elif.txt +++ /dev/null @@ -1 +0,0 @@ -confusing-consecutive-elif:11:4:check_config:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif diff --git a/tests/functional/ext/confusing_elif/confusing_elif.py b/tests/functional/ext/confusing_elif/confusing_elif.py new file mode 100644 index 000000000..9f1d1ffe9 --- /dev/null +++ b/tests/functional/ext/confusing_elif/confusing_elif.py @@ -0,0 +1,41 @@ +# pylint: disable=missing-module-docstring, missing-function-docstring + +def check_config(machine, old_conf, new_conf): + """Example code that will trigger the message""" + if old_conf: + if not new_conf: + machine.disable() + elif old_conf.value != new_conf.value: + machine.disable() + machine.enable(new_conf.value) + elif new_conf: # [confusing-consecutive-elif] + machine.enable(new_conf.value) + + +def check_config_2(machine, old_conf, new_conf): + """Example code must not trigger the message, because the inner block ends with else.""" + if old_conf: + if not new_conf: + machine.disable() + elif old_conf.value != new_conf.value: + machine.disable() + machine.enable(new_conf.value) + else: + pass + elif new_conf: + machine.enable(new_conf.value) + +def check_config_3(machine, old_conf, new_conf): + """ + Example code must not trigger the message, + because the inner if is not the final node of the body. + """ + if old_conf: + if not new_conf: + machine.disable() + elif old_conf.value != new_conf.value: + machine.disable() + machine.enable(new_conf.value) + print("Processed old configuration...") + elif new_conf: + machine.enable(new_conf.value) diff --git a/tests/functional/ext/confusing_elif/confusing_elif.rc b/tests/functional/ext/confusing_elif/confusing_elif.rc new file mode 100644 index 000000000..6a11b2c09 --- /dev/null +++ b/tests/functional/ext/confusing_elif/confusing_elif.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.confusing_elif diff --git a/tests/functional/ext/confusing_elif/confusing_elif.txt b/tests/functional/ext/confusing_elif/confusing_elif.txt new file mode 100644 index 000000000..55cc0d13f --- /dev/null +++ b/tests/functional/ext/confusing_elif/confusing_elif.txt @@ -0,0 +1 @@ +confusing-consecutive-elif:11:4:check_config:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif diff --git a/tests/functional/ext/consider_ternary_expression.py b/tests/functional/ext/consider_ternary_expression.py deleted file mode 100644 index 5ed5eaac4..000000000 --- a/tests/functional/ext/consider_ternary_expression.py +++ /dev/null @@ -1,17 +0,0 @@ -if f(): # [consider-ternary-expression] - x = 4 -else: - x = 5 - -if g(): - y = 3 -elif h(): - y = 4 -else: - y = 5 - -def a(): - if i(): # [consider-ternary-expression] - z = 4 - else: - z = 5 diff --git a/tests/functional/ext/consider_ternary_expression.rc b/tests/functional/ext/consider_ternary_expression.rc deleted file mode 100644 index 39b1d7975..000000000 --- a/tests/functional/ext/consider_ternary_expression.rc +++ /dev/null @@ -1,10 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.consider_ternary_expression, - -[MESSAGES CONTROL] -disable= - invalid-name, - undefined-variable, - unused-variable, - missing-function-docstring, - missing-module-docstring, diff --git a/tests/functional/ext/consider_ternary_expression.txt b/tests/functional/ext/consider_ternary_expression.txt deleted file mode 100644 index 08e51e61d..000000000 --- a/tests/functional/ext/consider_ternary_expression.txt +++ /dev/null @@ -1,2 +0,0 @@ -consider-ternary-expression:1:0::Consider rewriting as a ternary expression -consider-ternary-expression:14:4:a:Consider rewriting as a ternary expression diff --git a/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py new file mode 100644 index 000000000..5ed5eaac4 --- /dev/null +++ b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py @@ -0,0 +1,17 @@ +if f(): # [consider-ternary-expression] + x = 4 +else: + x = 5 + +if g(): + y = 3 +elif h(): + y = 4 +else: + y = 5 + +def a(): + if i(): # [consider-ternary-expression] + z = 4 + else: + z = 5 diff --git a/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc new file mode 100644 index 000000000..39b1d7975 --- /dev/null +++ b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc @@ -0,0 +1,10 @@ +[MASTER] +load-plugins=pylint.extensions.consider_ternary_expression, + +[MESSAGES CONTROL] +disable= + invalid-name, + undefined-variable, + unused-variable, + missing-function-docstring, + missing-module-docstring, diff --git a/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt new file mode 100644 index 000000000..08e51e61d --- /dev/null +++ b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt @@ -0,0 +1,2 @@ +consider-ternary-expression:1:0::Consider rewriting as a ternary expression +consider-ternary-expression:14:4:a:Consider rewriting as a ternary expression diff --git a/tests/functional/ext/docparams.py b/tests/functional/ext/docparams.py deleted file mode 100644 index 8dbb0295a..000000000 --- a/tests/functional/ext/docparams.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Fixture for testing missing documentation in docparams.""" - - -def _private_func1(param1): # [missing-return-doc, missing-return-type-doc] - """This is a test docstring without returns""" - return param1 - - -def _private_func2(param1): # [missing-yield-doc, missing-yield-type-doc] - """This is a test docstring without yields""" - yield param1 - - -def _private_func3(param1): # [missing-raises-doc] - """This is a test docstring without raises""" - raise Exception('Example') - - -def public_func1(param1): # [missing-any-param-doc] - """This is a test docstring without params""" - print(param1) - - -async def _async_private_func1(param1): # [missing-return-doc, missing-return-type-doc] - """This is a test docstring without returns""" - return param1 - - -async def _async_private_func2(param1): # [missing-yield-doc, missing-yield-type-doc] - """This is a test docstring without yields""" - yield param1 - - -async def _async_private_func3(param1): # [missing-raises-doc] - """This is a test docstring without raises""" - raise Exception('Example') - - -async def async_public_func1(param1): # [missing-any-param-doc] - """This is a test docstring without params""" - print(param1) diff --git a/tests/functional/ext/docparams.rc b/tests/functional/ext/docparams.rc deleted file mode 100644 index eda78b640..000000000 --- a/tests/functional/ext/docparams.rc +++ /dev/null @@ -1,8 +0,0 @@ -[MASTER] -load-plugins = pylint.extensions.docparams - -[BASIC] -accept-no-param-doc = no -accept-no-raise-doc = no -accept-no-return-doc = no -accept-no-yields-doc = no diff --git a/tests/functional/ext/docparams.txt b/tests/functional/ext/docparams.txt deleted file mode 100644 index 7aa6631ed..000000000 --- a/tests/functional/ext/docparams.txt +++ /dev/null @@ -1,12 +0,0 @@ -missing-return-doc:4:0:_private_func1:Missing return documentation -missing-return-type-doc:4:0:_private_func1:Missing return type documentation -missing-yield-doc:9:0:_private_func2:Missing yield documentation -missing-yield-type-doc:9:0:_private_func2:Missing yield type documentation -missing-raises-doc:14:0:_private_func3:"""Exception""" not documented as being raised -missing-any-param-doc:19:0:public_func1:"Missing any documentation in ""public_func1""" -missing-return-doc:24:0:_async_private_func1:Missing return documentation -missing-return-type-doc:24:0:_async_private_func1:Missing return type documentation -missing-yield-doc:29:0:_async_private_func2:Missing yield documentation -missing-yield-type-doc:29:0:_async_private_func2:Missing yield type documentation -missing-raises-doc:34:0:_async_private_func3:"""Exception""" not documented as being raised -missing-any-param-doc:39:0:async_public_func1:"Missing any documentation in ""async_public_func1""" diff --git a/tests/functional/ext/docparams/docparams.py b/tests/functional/ext/docparams/docparams.py new file mode 100644 index 000000000..8dbb0295a --- /dev/null +++ b/tests/functional/ext/docparams/docparams.py @@ -0,0 +1,41 @@ +"""Fixture for testing missing documentation in docparams.""" + + +def _private_func1(param1): # [missing-return-doc, missing-return-type-doc] + """This is a test docstring without returns""" + return param1 + + +def _private_func2(param1): # [missing-yield-doc, missing-yield-type-doc] + """This is a test docstring without yields""" + yield param1 + + +def _private_func3(param1): # [missing-raises-doc] + """This is a test docstring without raises""" + raise Exception('Example') + + +def public_func1(param1): # [missing-any-param-doc] + """This is a test docstring without params""" + print(param1) + + +async def _async_private_func1(param1): # [missing-return-doc, missing-return-type-doc] + """This is a test docstring without returns""" + return param1 + + +async def _async_private_func2(param1): # [missing-yield-doc, missing-yield-type-doc] + """This is a test docstring without yields""" + yield param1 + + +async def _async_private_func3(param1): # [missing-raises-doc] + """This is a test docstring without raises""" + raise Exception('Example') + + +async def async_public_func1(param1): # [missing-any-param-doc] + """This is a test docstring without params""" + print(param1) diff --git a/tests/functional/ext/docparams/docparams.rc b/tests/functional/ext/docparams/docparams.rc new file mode 100644 index 000000000..eda78b640 --- /dev/null +++ b/tests/functional/ext/docparams/docparams.rc @@ -0,0 +1,8 @@ +[MASTER] +load-plugins = pylint.extensions.docparams + +[BASIC] +accept-no-param-doc = no +accept-no-raise-doc = no +accept-no-return-doc = no +accept-no-yields-doc = no diff --git a/tests/functional/ext/docparams/docparams.txt b/tests/functional/ext/docparams/docparams.txt new file mode 100644 index 000000000..7aa6631ed --- /dev/null +++ b/tests/functional/ext/docparams/docparams.txt @@ -0,0 +1,12 @@ +missing-return-doc:4:0:_private_func1:Missing return documentation +missing-return-type-doc:4:0:_private_func1:Missing return type documentation +missing-yield-doc:9:0:_private_func2:Missing yield documentation +missing-yield-type-doc:9:0:_private_func2:Missing yield type documentation +missing-raises-doc:14:0:_private_func3:"""Exception""" not documented as being raised +missing-any-param-doc:19:0:public_func1:"Missing any documentation in ""public_func1""" +missing-return-doc:24:0:_async_private_func1:Missing return documentation +missing-return-type-doc:24:0:_async_private_func1:Missing return type documentation +missing-yield-doc:29:0:_async_private_func2:Missing yield documentation +missing-yield-type-doc:29:0:_async_private_func2:Missing yield type documentation +missing-raises-doc:34:0:_async_private_func3:"""Exception""" not documented as being raised +missing-any-param-doc:39:0:async_public_func1:"Missing any documentation in ""async_public_func1""" diff --git a/tests/functional/ext/docparams/missing_param_doc.py b/tests/functional/ext/docparams/missing_param_doc.py new file mode 100644 index 000000000..75f813578 --- /dev/null +++ b/tests/functional/ext/docparams/missing_param_doc.py @@ -0,0 +1,142 @@ +#pylint: disable= missing-module-docstring + +def foobar1(arg1, arg2): #[missing-any-param-doc] + """function foobar ... + """ + print(arg1, arg2) + +def foobar2(arg1, arg2): #[missing-any-param-doc] + """function foobar ... + Parameters + ---------- + """ + print(arg1, arg2) + +def foobar3(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] + """function foobar ... + Parameters + ---------- + arg1: int + arg3: float + """ + print(arg1, arg2, arg3) + +def foobar4(arg1, arg2): #[missing-param-doc, missing-type-doc] + """function foobar ... + Parameters + ---------- + arg1: int + description + """ + print(arg1, arg2) + +def foobar5(arg1, arg2): #[missing-param-doc, missing-type-doc] + """function foobar ... + Parameters + ---------- + arg1: + description + arg2: str + """ + print(arg1, arg2) + +def foobar6(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] + """function foobar ... + Parameters + ---------- + arg1: int + description + arg2: int + """ + print(arg1, arg2, arg3) + +def foobar7(arg1, arg2): #[missing-any-param-doc] + """function foobar ... + Parameters + ---------- + arg1 + """ + print(arg1, arg2) + +def foobar8(arg1): #[missing-any-param-doc] + """function foobar""" + + print(arg1) + +def foobar9(arg1, arg2, arg3): #[missing-param-doc] + """function foobar ... + Parameters + ---------- + arg1: int + arg2: int + arg3: str + """ + print(arg1, arg2, arg3) + +def foobar10(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] + """function foobar ... + Parameters + ---------- + arg1: + desc1 + arg2: int + arg3: + desc3 + """ + print(arg1, arg2, arg3) + +def foobar11(arg1, arg2): #[missing-any-param-doc] + """function foobar ... + Args + ---------- + arg1 + arg2 + """ + print(arg1, arg2) + +def foobar12(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] + """function foobar ... + Args + ---------- + arg1: int + arg2: + does something + arg3 + """ + print(arg1, arg2, arg3) + +def foobar13(arg1, *args, arg3=";"): + """Description of the function + + Parameters + ---------- + arg1 : str + Path to the input. + *args : + Relevant parameters. + arg3 : str, optional + File separator. + """ + print(arg1, args, arg3) + +def foobar14(arg1, *args): + """Description of the function + + Parameters + ---------- + arg1 : str + Path to the input. + *args : + Relevant parameters. + """ + print(arg1, args) + +def foobar15(*args): + """Description of the function + + Parameters + ---------- + *args : + Relevant parameters. + """ + print(args) diff --git a/tests/functional/ext/docparams/missing_param_doc.rc b/tests/functional/ext/docparams/missing_param_doc.rc new file mode 100644 index 000000000..d4a6dc172 --- /dev/null +++ b/tests/functional/ext/docparams/missing_param_doc.rc @@ -0,0 +1,8 @@ +[MASTER] +load-plugins=pylint.extensions.docparams, + +[PARAMETER_DOCUMENTATION] +accept-no-param-doc=no +accept-no-raise-doc=no +accept-no-return-doc=no +accept-no-yields-doc=no diff --git a/tests/functional/ext/docparams/missing_param_doc.txt b/tests/functional/ext/docparams/missing_param_doc.txt new file mode 100644 index 000000000..b03e20072 --- /dev/null +++ b/tests/functional/ext/docparams/missing_param_doc.txt @@ -0,0 +1,18 @@ +missing-any-param-doc:3:0:foobar1:"Missing any documentation in ""foobar1""" +missing-any-param-doc:8:0:foobar2:"Missing any documentation in ""foobar2""" +missing-param-doc:15:0:foobar3:"""arg1, arg2, arg3"" missing in parameter documentation" +missing-type-doc:15:0:foobar3:"""arg2"" missing in parameter type documentation" +missing-param-doc:24:0:foobar4:"""arg2"" missing in parameter documentation" +missing-type-doc:24:0:foobar4:"""arg2"" missing in parameter type documentation" +missing-param-doc:33:0:foobar5:"""arg2"" missing in parameter documentation" +missing-type-doc:33:0:foobar5:"""arg1"" missing in parameter type documentation" +missing-param-doc:43:0:foobar6:"""arg2, arg3"" missing in parameter documentation" +missing-type-doc:43:0:foobar6:"""arg3"" missing in parameter type documentation" +missing-any-param-doc:53:0:foobar7:"Missing any documentation in ""foobar7""" +missing-any-param-doc:61:0:foobar8:"Missing any documentation in ""foobar8""" +missing-param-doc:66:0:foobar9:"""arg1, arg2, arg3"" missing in parameter documentation" +missing-param-doc:76:0:foobar10:"""arg2"" missing in parameter documentation" +missing-type-doc:76:0:foobar10:"""arg1, arg3"" missing in parameter type documentation" +missing-any-param-doc:88:0:foobar11:Missing any documentation in "foobar11" +missing-param-doc:97:0:foobar12:"""arg1, arg3"" missing in parameter documentation" +missing-type-doc:97:0:foobar12:"""arg2, arg3"" missing in parameter type documentation" diff --git a/tests/functional/ext/docparams/useless_type_doc.py b/tests/functional/ext/docparams/useless_type_doc.py new file mode 100644 index 000000000..110a7a5f5 --- /dev/null +++ b/tests/functional/ext/docparams/useless_type_doc.py @@ -0,0 +1,73 @@ +#pylint: disable = missing-any-param-doc +"""demonstrate FP with useless-type-doc""" + + +def function(public_param: int, _some_private_param: bool = False) -> None: + """does things + + Args: + public_param: an ordinary parameter + """ + for _ in range(public_param): + ... + if _some_private_param: + ... + else: + ... + + +def smart_function(public_param: int, _some_private_param: bool = False) -> None: + """We're speaking about _some_private_param without really documenting it. + + Args: + public_param: an ordinary parameter + """ + for _ in range(public_param): + ... + if _some_private_param: + ... + else: + ... + + +# +1: [useless-type-doc,useless-param-doc] +def function_useless_doc(public_param: int, _some_private_param: bool = False) -> None: + """does things + + Args: + public_param: an ordinary parameter + _some_private_param (bool): private param + + """ + for _ in range(public_param): + ... + if _some_private_param: + ... + else: + ... + + +def test(_new: str) -> str: + """foobar + + :return: comment + """ + return "" + + +def smarter_test(_new: str) -> str: + """We're speaking about _new without really documenting it. + + :return: comment + """ + return "" + + +# +1: [useless-type-doc,useless-param-doc] +def test_two(_new: str) -> str: + """foobar + + :param str _new: + :return: comment + """ + return "" diff --git a/tests/functional/ext/docparams/useless_type_doc.rc b/tests/functional/ext/docparams/useless_type_doc.rc new file mode 100644 index 000000000..d4a6dc172 --- /dev/null +++ b/tests/functional/ext/docparams/useless_type_doc.rc @@ -0,0 +1,8 @@ +[MASTER] +load-plugins=pylint.extensions.docparams, + +[PARAMETER_DOCUMENTATION] +accept-no-param-doc=no +accept-no-raise-doc=no +accept-no-return-doc=no +accept-no-yields-doc=no diff --git a/tests/functional/ext/docparams/useless_type_doc.txt b/tests/functional/ext/docparams/useless_type_doc.txt new file mode 100644 index 000000000..9e1963e90 --- /dev/null +++ b/tests/functional/ext/docparams/useless_type_doc.txt @@ -0,0 +1,4 @@ +useless-param-doc:34:0:function_useless_doc:"""_some_private_param"" useless ignored parameter documentation":HIGH +useless-type-doc:34:0:function_useless_doc:"""_some_private_param"" useless ignored parameter type documentation":HIGH +useless-param-doc:67:0:test_two:"""_new"" useless ignored parameter documentation":HIGH +useless-type-doc:67:0:test_two:"""_new"" useless ignored parameter type documentation":HIGH diff --git a/tests/functional/ext/docstyle/docstyle_extension.py b/tests/functional/ext/docstyle/docstyle_extension.py new file mode 100644 index 000000000..a5b6161b0 --- /dev/null +++ b/tests/functional/ext/docstyle/docstyle_extension.py @@ -0,0 +1,41 @@ +"""Checks of Dosctrings 'docstring-first-line-empty' 'bad-docstring-quotes'""" + + +def check_messages(*messages): # [docstring-first-line-empty] + """ + docstring""" + return messages + + +def function2(): + """Test Ok""" + + +class FFFF: # [docstring-first-line-empty] + """ + Test Docstring First Line Empty + """ + + def method1(self): # [docstring-first-line-empty, bad-docstring-quotes] + ''' + Test Triple Single Quotes docstring + ''' + + def method2(self): # [bad-docstring-quotes] + "bad docstring 1" + + def method3(self): # [bad-docstring-quotes] + 'bad docstring 2' + + def method4(self): # [bad-docstring-quotes] + ' """bad docstring 3 ' + + @check_messages("bad-open-mode", "redundant-unittest-assert", "deprecated-module") + def method5(self): + """Test OK 1 with decorators""" + + def method6(self): + r"""Test OK 2 with raw string""" + + def method7(self): + u"""Test OK 3 with unicode string""" diff --git a/tests/functional/ext/docstyle/docstyle_extension.rc b/tests/functional/ext/docstyle/docstyle_extension.rc new file mode 100644 index 000000000..5128289ff --- /dev/null +++ b/tests/functional/ext/docstyle/docstyle_extension.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.docstyle, diff --git a/tests/functional/ext/docstyle/docstyle_extension.txt b/tests/functional/ext/docstyle/docstyle_extension.txt new file mode 100644 index 000000000..8a30eedee --- /dev/null +++ b/tests/functional/ext/docstyle/docstyle_extension.txt @@ -0,0 +1,7 @@ +docstring-first-line-empty:4:0:check_messages:First line empty in function docstring:HIGH +docstring-first-line-empty:14:0:FFFF:First line empty in class docstring:HIGH +bad-docstring-quotes:19:4:FFFF.method1:"Bad docstring quotes in method, expected """""", given '''":HIGH +docstring-first-line-empty:19:4:FFFF.method1:First line empty in method docstring:HIGH +bad-docstring-quotes:24:4:FFFF.method2:"Bad docstring quotes in method, expected """""", given """:HIGH +bad-docstring-quotes:27:4:FFFF.method3:"Bad docstring quotes in method, expected """""", given '":HIGH +bad-docstring-quotes:30:4:FFFF.method4:"Bad docstring quotes in method, expected """""", given '":HIGH diff --git a/tests/functional/ext/empty_comment/empty_comment.py b/tests/functional/ext/empty_comment/empty_comment.py new file mode 100644 index 000000000..6adaa4fc1 --- /dev/null +++ b/tests/functional/ext/empty_comment/empty_comment.py @@ -0,0 +1,13 @@ +"""empty-comment test-case""" +# +1:[empty-comment] +A = 5 # +# +1:[empty-comment] +# +A = '#' + '1' +# +1:[empty-comment] +print(A) # +print("A=", A) # should not be an error# +# +1:[empty-comment] +A = "#pe\0ace#love#" # +A = "peace#love" # \0 peace'#'''' love#peace'''-'#love'-"peace#love"# +####### diff --git a/tests/functional/ext/empty_comment/empty_comment.rc b/tests/functional/ext/empty_comment/empty_comment.rc new file mode 100644 index 000000000..1bbd021e7 --- /dev/null +++ b/tests/functional/ext/empty_comment/empty_comment.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.empty_comment, diff --git a/tests/functional/ext/empty_comment/empty_comment.txt b/tests/functional/ext/empty_comment/empty_comment.txt new file mode 100644 index 000000000..ae4eee33e --- /dev/null +++ b/tests/functional/ext/empty_comment/empty_comment.txt @@ -0,0 +1,4 @@ +empty-comment:3:0::Line with empty comment:HIGH +empty-comment:5:0::Line with empty comment:HIGH +empty-comment:8:0::Line with empty comment:HIGH +empty-comment:11:0::Line with empty comment:HIGH diff --git a/tests/functional/ext/emptystring/empty_string_comparison.py b/tests/functional/ext/emptystring/empty_string_comparison.py new file mode 100644 index 000000000..c6dcf8ea8 --- /dev/null +++ b/tests/functional/ext/emptystring/empty_string_comparison.py @@ -0,0 +1,16 @@ +# pylint: disable=literal-comparison,missing-docstring + +X = '' +Y = 'test' + +if X is '': # [compare-to-empty-string] + pass + +if Y is not "": # [compare-to-empty-string] + pass + +if X == "": # [compare-to-empty-string] + pass + +if Y != '': # [compare-to-empty-string] + pass diff --git a/tests/functional/ext/emptystring/empty_string_comparison.rc b/tests/functional/ext/emptystring/empty_string_comparison.rc new file mode 100644 index 000000000..e6e3ded01 --- /dev/null +++ b/tests/functional/ext/emptystring/empty_string_comparison.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.emptystring, diff --git a/tests/functional/ext/emptystring/empty_string_comparison.txt b/tests/functional/ext/emptystring/empty_string_comparison.txt new file mode 100644 index 000000000..7e31c3d25 --- /dev/null +++ b/tests/functional/ext/emptystring/empty_string_comparison.txt @@ -0,0 +1,4 @@ +compare-to-empty-string:6:3::Avoid comparisons to empty string:HIGH +compare-to-empty-string:9:3::Avoid comparisons to empty string:HIGH +compare-to-empty-string:12:3::Avoid comparisons to empty string:HIGH +compare-to-empty-string:15:3::Avoid comparisons to empty string:HIGH diff --git a/tests/functional/ext/for_any_all.py b/tests/functional/ext/for_any_all.py deleted file mode 100644 index 785cefebd..000000000 --- a/tests/functional/ext/for_any_all.py +++ /dev/null @@ -1,61 +0,0 @@ -"""Functional test""" - -def any_even(items): - """Return True if the list contains any even numbers""" - for item in items: # [consider-using-any-or-all] - if item % 2 == 0: - return True - return False - -def all_even(items): - """Return True if the list contains all even numbers""" - for item in items: # [consider-using-any-or-all] - if not item % 2 == 0: - return False - return True - -def any_uneven(items): - """Return True if the list contains any uneven numbers""" - for item in items: # [consider-using-any-or-all] - if not item % 2 == 0: - return True - return False - -def all_uneven(items): - """Return True if the list contains all uneven numbers""" - for item in items: # [consider-using-any-or-all] - if item % 2 == 0: - return False - return True - -def is_from_string(item): - """Return True if one of parents of item is a string""" - for parent in item.parents(): # [consider-using-any-or-all] - if isinstance(parent, str): - return True - return False - -def is_not_from_string(item): - """Return True if one of parents of item isn't a string""" - for parent in item.parents(): # [consider-using-any-or-all] - if not isinstance(parent, str): - return True - return False - -def nested_check(items): - """Tests that for loops at deeper levels are picked up""" - if items and len(items) > 5: - print(items) - for item in items: # [consider-using-any-or-all] - if item in (1, 2, 3): - return False - return True - print(items) - return items[3] > 5 - -def words_contains_word(words): - """Return whether words contains 'word'""" - for word in words: # [consider-using-any-or-all] - if word == "word": - return True - return False diff --git a/tests/functional/ext/for_any_all.rc b/tests/functional/ext/for_any_all.rc deleted file mode 100644 index 41b0eaa71..000000000 --- a/tests/functional/ext/for_any_all.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.for_any_all diff --git a/tests/functional/ext/for_any_all.txt b/tests/functional/ext/for_any_all.txt deleted file mode 100644 index da01f06fd..000000000 --- a/tests/functional/ext/for_any_all.txt +++ /dev/null @@ -1,8 +0,0 @@ -consider-using-any-or-all:5:4:any_even:`for` loop could be `any(item % 2 == 0 for item in items)` -consider-using-any-or-all:12:4:all_even:`for` loop could be `all(item % 2 == 0 for item in items)` -consider-using-any-or-all:19:4:any_uneven:`for` loop could be `not all(item % 2 == 0 for item in items)` -consider-using-any-or-all:26:4:all_uneven:`for` loop could be `not any(item % 2 == 0 for item in items)` -consider-using-any-or-all:33:4:is_from_string:`for` loop could be `any(isinstance(parent, str) for parent in item.parents())` -consider-using-any-or-all:40:4:is_not_from_string:`for` loop could be `not all(isinstance(parent, str) for parent in item.parents())` -consider-using-any-or-all:49:8:nested_check:`for` loop could be `not any(item in (1, 2, 3) for item in items)` -consider-using-any-or-all:58:4:words_contains_word:`for` loop could be `any(word == 'word' for word in words)` diff --git a/tests/functional/ext/for_any_all/for_any_all.py b/tests/functional/ext/for_any_all/for_any_all.py new file mode 100644 index 000000000..785cefebd --- /dev/null +++ b/tests/functional/ext/for_any_all/for_any_all.py @@ -0,0 +1,61 @@ +"""Functional test""" + +def any_even(items): + """Return True if the list contains any even numbers""" + for item in items: # [consider-using-any-or-all] + if item % 2 == 0: + return True + return False + +def all_even(items): + """Return True if the list contains all even numbers""" + for item in items: # [consider-using-any-or-all] + if not item % 2 == 0: + return False + return True + +def any_uneven(items): + """Return True if the list contains any uneven numbers""" + for item in items: # [consider-using-any-or-all] + if not item % 2 == 0: + return True + return False + +def all_uneven(items): + """Return True if the list contains all uneven numbers""" + for item in items: # [consider-using-any-or-all] + if item % 2 == 0: + return False + return True + +def is_from_string(item): + """Return True if one of parents of item is a string""" + for parent in item.parents(): # [consider-using-any-or-all] + if isinstance(parent, str): + return True + return False + +def is_not_from_string(item): + """Return True if one of parents of item isn't a string""" + for parent in item.parents(): # [consider-using-any-or-all] + if not isinstance(parent, str): + return True + return False + +def nested_check(items): + """Tests that for loops at deeper levels are picked up""" + if items and len(items) > 5: + print(items) + for item in items: # [consider-using-any-or-all] + if item in (1, 2, 3): + return False + return True + print(items) + return items[3] > 5 + +def words_contains_word(words): + """Return whether words contains 'word'""" + for word in words: # [consider-using-any-or-all] + if word == "word": + return True + return False diff --git a/tests/functional/ext/for_any_all/for_any_all.rc b/tests/functional/ext/for_any_all/for_any_all.rc new file mode 100644 index 000000000..41b0eaa71 --- /dev/null +++ b/tests/functional/ext/for_any_all/for_any_all.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.for_any_all diff --git a/tests/functional/ext/for_any_all/for_any_all.txt b/tests/functional/ext/for_any_all/for_any_all.txt new file mode 100644 index 000000000..da01f06fd --- /dev/null +++ b/tests/functional/ext/for_any_all/for_any_all.txt @@ -0,0 +1,8 @@ +consider-using-any-or-all:5:4:any_even:`for` loop could be `any(item % 2 == 0 for item in items)` +consider-using-any-or-all:12:4:all_even:`for` loop could be `all(item % 2 == 0 for item in items)` +consider-using-any-or-all:19:4:any_uneven:`for` loop could be `not all(item % 2 == 0 for item in items)` +consider-using-any-or-all:26:4:all_uneven:`for` loop could be `not any(item % 2 == 0 for item in items)` +consider-using-any-or-all:33:4:is_from_string:`for` loop could be `any(isinstance(parent, str) for parent in item.parents())` +consider-using-any-or-all:40:4:is_not_from_string:`for` loop could be `not all(isinstance(parent, str) for parent in item.parents())` +consider-using-any-or-all:49:8:nested_check:`for` loop could be `not any(item in (1, 2, 3) for item in items)` +consider-using-any-or-all:58:4:words_contains_word:`for` loop could be `any(word == 'word' for word in words)` diff --git a/tests/functional/ext/mccabe/mccabe.py b/tests/functional/ext/mccabe/mccabe.py new file mode 100644 index 000000000..b5a257b1f --- /dev/null +++ b/tests/functional/ext/mccabe/mccabe.py @@ -0,0 +1,216 @@ +# pylint: disable=invalid-name,unnecessary-pass,no-else-return,useless-else-on-loop +# pylint: disable=undefined-variable,consider-using-sys-exit,unused-variable,too-many-return-statements +# pylint: disable=redefined-outer-name,useless-object-inheritance,using-constant-test,unused-argument +# pylint: disable=broad-except, not-context-manager, no-method-argument, no-self-use, unspecified-encoding + +"""Checks use of "too-complex" check""" + + +def f1(): # [too-complex] + """McCabe rating: 1""" + pass + + +def f2(n): # [too-complex] + """McCabe rating: 1""" + k = n + 4 + s = k + n + return s + + +def f3(n): # [too-complex] + """McCabe rating: 3""" + if n > 3: + return "bigger than three" + elif n > 4: + return "is never executed" + else: + return "smaller than or equal to three" + + +def f4(): # [too-complex] + """McCabe rating: 2""" + for i in range(10): + print(i) + + +def f5(mylist): # [too-complex] + """McCabe rating: 2""" + for i in mylist: + print(i) + else: + print(None) + + +def f6(n): # [too-complex] + """McCabe rating: 2""" + if n > 4: + return f(n - 1) + else: + return n + + +def f7(): # [too-complex] + """McCabe rating: 3""" + + def b(): + """McCabe rating: 2""" + + def c(): + """McCabe rating: 1""" + pass + + c() + + b() + + +def f8(): # [too-complex] + """McCabe rating: 4""" + try: + print(1) + except TypeA: + print(2) + except TypeB: + print(3) + else: + print(4) + + +def f9(): # [too-complex] + """McCabe rating: 9""" + myint = 2 + if myint > 5: + pass + else: + if myint <= 5: + pass + else: + myint = 3 + if myint > 2: + if myint > 3: + pass + elif myint == 3: + pass + elif myint < 3: + pass + else: + if myint: + pass + else: + if myint: + pass + myint = 4 + + +def f10(): # [too-complex] + """McCabe rating: 11""" + myint = 2 + if myint == 5: + return myint + elif myint == 6: + return myint + elif myint == 7: + return myint + elif myint == 8: + return myint + elif myint == 9: + return myint + elif myint == 10: + if myint == 8: + while True: + return True + elif myint == 8: + with myint: + return 8 + else: + if myint == 2: + return myint + return myint + return myint + + +class MyClass1(object): + """Class of example to test mccabe""" + + _name = "MyClass" # To force a tail.node=None + + def method1(): # [too-complex] + """McCabe rating: 1""" + pass + + def method2(self, param1): # [too-complex, too-many-branches] + """McCabe rating: 18""" + if not param1: + pass + pass + if param1: + pass + else: + pass + + pass + + if param1: + pass + if param1: + pass + if param1: + pass + if param1: + pass + if param1: + pass + if param1: + pass + if param1: + for value in range(5): + pass + + pass + for count in range(6): + with open("myfile") as fp: + count += 1 + pass + pass + try: + pass + if not param1: + pass + else: + pass + if param1: + raise BaseException("Error") + with open("myfile2") as fp2: + pass + pass + finally: + if param1 is not None: + pass + for count2 in range(8): + try: + pass + except BaseException("Error2"): + pass + return param1 + + +for count in range(10): # [too-complex] + if count == 1: + exit(0) + elif count == 2: + exit(1) + else: + exit(2) + + +def method3(self): # [too-complex] + """McCabe rating: 2""" + try: + if True: + pass + else: + pass + finally: + pass + return True diff --git a/tests/functional/ext/mccabe/mccabe.rc b/tests/functional/ext/mccabe/mccabe.rc new file mode 100644 index 000000000..ac96a1eb5 --- /dev/null +++ b/tests/functional/ext/mccabe/mccabe.rc @@ -0,0 +1,4 @@ +[MASTER] +load-plugins=pylint.extensions.mccabe, + +max-complexity=0 diff --git a/tests/functional/ext/mccabe/mccabe.txt b/tests/functional/ext/mccabe/mccabe.txt new file mode 100644 index 000000000..3e4a8431d --- /dev/null +++ b/tests/functional/ext/mccabe/mccabe.txt @@ -0,0 +1,15 @@ +too-complex:9:0:f1:'f1' is too complex. The McCabe rating is 1:HIGH +too-complex:14:0:f2:'f2' is too complex. The McCabe rating is 1:HIGH +too-complex:21:0:f3:'f3' is too complex. The McCabe rating is 3:HIGH +too-complex:31:0:f4:'f4' is too complex. The McCabe rating is 2:HIGH +too-complex:37:0:f5:'f5' is too complex. The McCabe rating is 2:HIGH +too-complex:45:0:f6:'f6' is too complex. The McCabe rating is 2:HIGH +too-complex:53:0:f7:'f7' is too complex. The McCabe rating is 3:HIGH +too-complex:68:0:f8:'f8' is too complex. The McCabe rating is 4:HIGH +too-complex:80:0:f9:'f9' is too complex. The McCabe rating is 9:HIGH +too-complex:106:0:f10:'f10' is too complex. The McCabe rating is 11:HIGH +too-complex:138:4:MyClass1.method1:'method1' is too complex. The McCabe rating is 1:HIGH +too-complex:142:4:MyClass1.method2:'method2' is too complex. The McCabe rating is 18:HIGH +too-many-branches:142:4:MyClass1.method2:Too many branches (20/12):HIGH +too-complex:198:0::This 'for' is too complex. The McCabe rating is 4:HIGH +too-complex:207:0:method3:'method3' is too complex. The McCabe rating is 2:HIGH diff --git a/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.py b/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.py new file mode 100644 index 000000000..c5eab48cc --- /dev/null +++ b/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.py @@ -0,0 +1,66 @@ +# pylint: disable=missing-docstring + +import socket + + +class SomeException(Exception): + pass + + +class SubclassException(SomeException): + pass + + +AliasException = SomeException + +try: + pass +except (SomeException, SomeException): # [overlapping-except] + pass + +try: + pass +except (SomeException, SubclassException): # [overlapping-except] + pass + +try: + pass +except (SomeException, AliasException): # [overlapping-except] + pass + +try: + pass +except (AliasException, SubclassException): # [overlapping-except] + pass + +try: + pass +# +1:[overlapping-except, overlapping-except, overlapping-except] +except (SomeException, AliasException, SubclassException): + pass + +try: + pass +except (ArithmeticError, FloatingPointError): # [overlapping-except] + pass + +try: + pass +except (ValueError, UnicodeDecodeError): # [overlapping-except] + pass + + +try: + pass +except (IOError, OSError): # [overlapping-except] + pass + +try: + pass +except (socket.error, OSError): # [overlapping-except] + pass + +try: + pass +except (ConnectionError, socket.error): # [overlapping-except] + pass diff --git a/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.rc b/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.rc new file mode 100644 index 000000000..ad49162c0 --- /dev/null +++ b/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.overlapping_exceptions, diff --git a/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.txt b/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.txt new file mode 100644 index 000000000..6669ae0f8 --- /dev/null +++ b/tests/functional/ext/overlapping_exceptions/overlapping_exceptions.txt @@ -0,0 +1,12 @@ +overlapping-except:18:7::Overlapping exceptions (SomeException and SomeException are the same):HIGH +overlapping-except:23:7::Overlapping exceptions (SomeException is an ancestor class of SubclassException):HIGH +overlapping-except:28:7::Overlapping exceptions (SomeException and AliasException are the same):HIGH +overlapping-except:33:7::Overlapping exceptions (AliasException is an ancestor class of SubclassException):HIGH +overlapping-except:39:7::Overlapping exceptions (AliasException is an ancestor class of SubclassException):HIGH +overlapping-except:39:7::Overlapping exceptions (SomeException and AliasException are the same):HIGH +overlapping-except:39:7::Overlapping exceptions (SomeException is an ancestor class of SubclassException):HIGH +overlapping-except:44:7::Overlapping exceptions (ArithmeticError is an ancestor class of FloatingPointError):HIGH +overlapping-except:49:7::Overlapping exceptions (ValueError is an ancestor class of UnicodeDecodeError):HIGH +overlapping-except:55:7::Overlapping exceptions (IOError and OSError are the same):HIGH +overlapping-except:60:7::Overlapping exceptions (socket.error and OSError are the same):HIGH +overlapping-except:65:7::Overlapping exceptions (socket.error is an ancestor class of ConnectionError):HIGH diff --git a/tests/functional/ext/plugin_does_not_exists.py b/tests/functional/ext/plugin_does_not_exists.py new file mode 100644 index 000000000..8b31d2348 --- /dev/null +++ b/tests/functional/ext/plugin_does_not_exists.py @@ -0,0 +1,5 @@ +# pylint: disable=missing-docstring + +from shadok import ShadokInteger # [import-error] + +ShadokInteger("Buga ZoMeu") diff --git a/tests/functional/ext/plugin_does_not_exists.rc b/tests/functional/ext/plugin_does_not_exists.rc new file mode 100644 index 000000000..72e7c1af7 --- /dev/null +++ b/tests/functional/ext/plugin_does_not_exists.rc @@ -0,0 +1,3 @@ +[master] +load-plugins= + pylint.extensions.check_does_not_exists_in_venv, diff --git a/tests/functional/ext/plugin_does_not_exists.txt b/tests/functional/ext/plugin_does_not_exists.txt new file mode 100644 index 000000000..8d5a79f24 --- /dev/null +++ b/tests/functional/ext/plugin_does_not_exists.txt @@ -0,0 +1 @@ +import-error:3:0::Unable to import 'shadok':HIGH diff --git a/tests/functional/ext/redefined_variable_type/redefined_variable_type.py b/tests/functional/ext/redefined_variable_type/redefined_variable_type.py new file mode 100644 index 000000000..aa89383d9 --- /dev/null +++ b/tests/functional/ext/redefined_variable_type/redefined_variable_type.py @@ -0,0 +1,85 @@ +"""Checks variable types aren't redefined within a method or a function""" + +# pylint: disable=too-few-public-methods,missing-docstring,unused-variable,invalid-name, useless-object-inheritance + +_OK = True + +class MyClass(object): + + class Klass(object): + def __init__(self): + self.var2 = 'var' + + def __init__(self): + self.var = True + self.var1 = 2 + self.var2 = 1. + self.var1 = 2. # [redefined-variable-type] + self.a_str = "hello" + a_str = False + (a_str, b_str) = (1, 2) # no support for inference on tuple assignment + a_str = 2.0 if self.var else 1.0 # [redefined-variable-type] + + def _getter(self): + return self.a_str + def _setter(self, val): + self.a_str = val + var2 = property(_getter, _setter) + + def some_method(self): + def func(): + var = 1 + test = 'bar' + var = 'baz' # [redefined-variable-type] + self.var = 1 # the rule checks for redefinitions in the scope of a function or method + test = 'foo' + myint = 2 + myint = False # [redefined-variable-type] + +_OK = "This is OK" # [redefined-variable-type] + +if _OK: + SOME_FLOAT = 1. + +def dummy_function(): + return 2 + +def other_function(): + instance = MyClass() + instance = True # [redefined-variable-type] + +SOME_FLOAT = dummy_function() # [redefined-variable-type] + +A_GLOB = None +A_GLOB = [1, 2, 3] + +def func2(x): + if x: + var = 'foo' + else: + var = True + + if x: + var2 = 'foo' + elif not x: + var2 = 2 + else: + pass + + if x: + var3 = 'foo' + var3 = 2 # [redefined-variable-type] + else: + pass + + var = 2 # [redefined-variable-type] + + if x: + pass + elif not x: + var4 = True + elif _OK: + pass + else: + var4 = 2. + var4 = 'baz' # [redefined-variable-type] diff --git a/tests/functional/ext/redefined_variable_type/redefined_variable_type.rc b/tests/functional/ext/redefined_variable_type/redefined_variable_type.rc new file mode 100644 index 000000000..8ee18a8f1 --- /dev/null +++ b/tests/functional/ext/redefined_variable_type/redefined_variable_type.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.redefined_variable_type, diff --git a/tests/functional/ext/redefined_variable_type/redefined_variable_type.txt b/tests/functional/ext/redefined_variable_type/redefined_variable_type.txt new file mode 100644 index 000000000..a0205c7aa --- /dev/null +++ b/tests/functional/ext/redefined_variable_type/redefined_variable_type.txt @@ -0,0 +1,10 @@ +redefined-variable-type:17:8:MyClass.__init__:Redefinition of self.var1 type from int to float:HIGH +redefined-variable-type:21:8:MyClass.__init__:Redefinition of a_str type from bool to float:HIGH +redefined-variable-type:33:12:MyClass.some_method.func:Redefinition of var type from int to str:HIGH +redefined-variable-type:37:8:MyClass.some_method:Redefinition of myint type from int to bool:HIGH +redefined-variable-type:39:0::Redefinition of _OK type from bool to str:HIGH +redefined-variable-type:49:4:other_function:Redefinition of instance type from functional.r.redefined_variable_type.MyClass to bool:HIGH +redefined-variable-type:51:0::Redefinition of SOME_FLOAT type from float to int:HIGH +redefined-variable-type:71:8:func2:Redefinition of var3 type from str to int:HIGH +redefined-variable-type:75:4:func2:Redefinition of var type from bool to int:HIGH +redefined-variable-type:85:8:func2:Redefinition of var4 type from float to str:HIGH diff --git a/tests/functional/ext/while_used.py b/tests/functional/ext/while_used.py deleted file mode 100644 index 848da0d51..000000000 --- a/tests/functional/ext/while_used.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Functional test""" - -while True: # [while-used] - print("asdf") - -def fff(): - "zxcv" - i = 0 - while i < 10: # [while-used] - i += 1 diff --git a/tests/functional/ext/while_used.rc b/tests/functional/ext/while_used.rc deleted file mode 100644 index 28e1b1faf..000000000 --- a/tests/functional/ext/while_used.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.while_used, diff --git a/tests/functional/ext/while_used.txt b/tests/functional/ext/while_used.txt deleted file mode 100644 index 80ca84d56..000000000 --- a/tests/functional/ext/while_used.txt +++ /dev/null @@ -1,2 +0,0 @@ -while-used:3:0::Used `while` loop -while-used:9:4:fff:Used `while` loop diff --git a/tests/functional/ext/while_used/while_used.py b/tests/functional/ext/while_used/while_used.py new file mode 100644 index 000000000..848da0d51 --- /dev/null +++ b/tests/functional/ext/while_used/while_used.py @@ -0,0 +1,10 @@ +"""Functional test""" + +while True: # [while-used] + print("asdf") + +def fff(): + "zxcv" + i = 0 + while i < 10: # [while-used] + i += 1 diff --git a/tests/functional/ext/while_used/while_used.rc b/tests/functional/ext/while_used/while_used.rc new file mode 100644 index 000000000..28e1b1faf --- /dev/null +++ b/tests/functional/ext/while_used/while_used.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.while_used, diff --git a/tests/functional/ext/while_used/while_used.txt b/tests/functional/ext/while_used/while_used.txt new file mode 100644 index 000000000..80ca84d56 --- /dev/null +++ b/tests/functional/ext/while_used/while_used.txt @@ -0,0 +1,2 @@ +while-used:3:0::Used `while` loop +while-used:9:4:fff:Used `while` loop diff --git a/tests/functional/m/mccabe.py b/tests/functional/m/mccabe.py deleted file mode 100644 index b5a257b1f..000000000 --- a/tests/functional/m/mccabe.py +++ /dev/null @@ -1,216 +0,0 @@ -# pylint: disable=invalid-name,unnecessary-pass,no-else-return,useless-else-on-loop -# pylint: disable=undefined-variable,consider-using-sys-exit,unused-variable,too-many-return-statements -# pylint: disable=redefined-outer-name,useless-object-inheritance,using-constant-test,unused-argument -# pylint: disable=broad-except, not-context-manager, no-method-argument, no-self-use, unspecified-encoding - -"""Checks use of "too-complex" check""" - - -def f1(): # [too-complex] - """McCabe rating: 1""" - pass - - -def f2(n): # [too-complex] - """McCabe rating: 1""" - k = n + 4 - s = k + n - return s - - -def f3(n): # [too-complex] - """McCabe rating: 3""" - if n > 3: - return "bigger than three" - elif n > 4: - return "is never executed" - else: - return "smaller than or equal to three" - - -def f4(): # [too-complex] - """McCabe rating: 2""" - for i in range(10): - print(i) - - -def f5(mylist): # [too-complex] - """McCabe rating: 2""" - for i in mylist: - print(i) - else: - print(None) - - -def f6(n): # [too-complex] - """McCabe rating: 2""" - if n > 4: - return f(n - 1) - else: - return n - - -def f7(): # [too-complex] - """McCabe rating: 3""" - - def b(): - """McCabe rating: 2""" - - def c(): - """McCabe rating: 1""" - pass - - c() - - b() - - -def f8(): # [too-complex] - """McCabe rating: 4""" - try: - print(1) - except TypeA: - print(2) - except TypeB: - print(3) - else: - print(4) - - -def f9(): # [too-complex] - """McCabe rating: 9""" - myint = 2 - if myint > 5: - pass - else: - if myint <= 5: - pass - else: - myint = 3 - if myint > 2: - if myint > 3: - pass - elif myint == 3: - pass - elif myint < 3: - pass - else: - if myint: - pass - else: - if myint: - pass - myint = 4 - - -def f10(): # [too-complex] - """McCabe rating: 11""" - myint = 2 - if myint == 5: - return myint - elif myint == 6: - return myint - elif myint == 7: - return myint - elif myint == 8: - return myint - elif myint == 9: - return myint - elif myint == 10: - if myint == 8: - while True: - return True - elif myint == 8: - with myint: - return 8 - else: - if myint == 2: - return myint - return myint - return myint - - -class MyClass1(object): - """Class of example to test mccabe""" - - _name = "MyClass" # To force a tail.node=None - - def method1(): # [too-complex] - """McCabe rating: 1""" - pass - - def method2(self, param1): # [too-complex, too-many-branches] - """McCabe rating: 18""" - if not param1: - pass - pass - if param1: - pass - else: - pass - - pass - - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - for value in range(5): - pass - - pass - for count in range(6): - with open("myfile") as fp: - count += 1 - pass - pass - try: - pass - if not param1: - pass - else: - pass - if param1: - raise BaseException("Error") - with open("myfile2") as fp2: - pass - pass - finally: - if param1 is not None: - pass - for count2 in range(8): - try: - pass - except BaseException("Error2"): - pass - return param1 - - -for count in range(10): # [too-complex] - if count == 1: - exit(0) - elif count == 2: - exit(1) - else: - exit(2) - - -def method3(self): # [too-complex] - """McCabe rating: 2""" - try: - if True: - pass - else: - pass - finally: - pass - return True diff --git a/tests/functional/m/mccabe.rc b/tests/functional/m/mccabe.rc deleted file mode 100644 index ac96a1eb5..000000000 --- a/tests/functional/m/mccabe.rc +++ /dev/null @@ -1,4 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.mccabe, - -max-complexity=0 diff --git a/tests/functional/m/mccabe.txt b/tests/functional/m/mccabe.txt deleted file mode 100644 index 3e4a8431d..000000000 --- a/tests/functional/m/mccabe.txt +++ /dev/null @@ -1,15 +0,0 @@ -too-complex:9:0:f1:'f1' is too complex. The McCabe rating is 1:HIGH -too-complex:14:0:f2:'f2' is too complex. The McCabe rating is 1:HIGH -too-complex:21:0:f3:'f3' is too complex. The McCabe rating is 3:HIGH -too-complex:31:0:f4:'f4' is too complex. The McCabe rating is 2:HIGH -too-complex:37:0:f5:'f5' is too complex. The McCabe rating is 2:HIGH -too-complex:45:0:f6:'f6' is too complex. The McCabe rating is 2:HIGH -too-complex:53:0:f7:'f7' is too complex. The McCabe rating is 3:HIGH -too-complex:68:0:f8:'f8' is too complex. The McCabe rating is 4:HIGH -too-complex:80:0:f9:'f9' is too complex. The McCabe rating is 9:HIGH -too-complex:106:0:f10:'f10' is too complex. The McCabe rating is 11:HIGH -too-complex:138:4:MyClass1.method1:'method1' is too complex. The McCabe rating is 1:HIGH -too-complex:142:4:MyClass1.method2:'method2' is too complex. The McCabe rating is 18:HIGH -too-many-branches:142:4:MyClass1.method2:Too many branches (20/12):HIGH -too-complex:198:0::This 'for' is too complex. The McCabe rating is 4:HIGH -too-complex:207:0:method3:'method3' is too complex. The McCabe rating is 2:HIGH diff --git a/tests/functional/m/misplaced_comparison_constant.py b/tests/functional/m/misplaced_comparison_constant.py deleted file mode 100644 index 0162187bf..000000000 --- a/tests/functional/m/misplaced_comparison_constant.py +++ /dev/null @@ -1,49 +0,0 @@ -"""Check that the constants are on the right side of the comparisons""" - -# pylint: disable=singleton-comparison, missing-docstring, too-few-public-methods, useless-object-inheritance - -class MyClass(object): - def __init__(self): - self.attr = 1 - - def dummy_return(self): - return self.attr - -def dummy_return(): - return 2 - -def bad_comparisons(): - """this is not ok""" - instance = MyClass() - for i in range(10): - if 5 <= i: # [misplaced-comparison-constant] - pass - if 1 == i: # [misplaced-comparison-constant] - pass - if 3 < dummy_return(): # [misplaced-comparison-constant] - pass - if 4 != instance.dummy_return(): # [misplaced-comparison-constant] - pass - if 1 == instance.attr: # [misplaced-comparison-constant] - pass - if "aaa" == instance.attr: # [misplaced-comparison-constant] - pass - -def good_comparison(): - """this is ok""" - for i in range(10): - if i == 5: - pass - -def double_comparison(): - """Check that we return early for non-binary comparison""" - for i in range(10): - if i == 1 == 2: - pass - if 2 <= i <= 8: - print("Between 2 and 8 inclusive") - -def const_comparison(): - """Check that we return early for comparison of two constants""" - if 1 == 2: - pass diff --git a/tests/functional/m/misplaced_comparison_constant.rc b/tests/functional/m/misplaced_comparison_constant.rc deleted file mode 100644 index abe6b9f27..000000000 --- a/tests/functional/m/misplaced_comparison_constant.rc +++ /dev/null @@ -1,3 +0,0 @@ -[MASTER] -load-plugins= - pylint.extensions.comparison_placement, diff --git a/tests/functional/m/misplaced_comparison_constant.txt b/tests/functional/m/misplaced_comparison_constant.txt deleted file mode 100644 index b517b499e..000000000 --- a/tests/functional/m/misplaced_comparison_constant.txt +++ /dev/null @@ -1,6 +0,0 @@ -misplaced-comparison-constant:19:11:bad_comparisons:Comparison should be i >= 5 -misplaced-comparison-constant:21:11:bad_comparisons:Comparison should be i == 1 -misplaced-comparison-constant:23:11:bad_comparisons:Comparison should be dummy_return() > 3 -misplaced-comparison-constant:25:11:bad_comparisons:Comparison should be instance.dummy_return() != 4 -misplaced-comparison-constant:27:11:bad_comparisons:Comparison should be instance.attr == 1 -misplaced-comparison-constant:29:11:bad_comparisons:Comparison should be instance.attr == 'aaa' diff --git a/tests/functional/m/missing/missing_param_doc.py b/tests/functional/m/missing/missing_param_doc.py deleted file mode 100644 index 75f813578..000000000 --- a/tests/functional/m/missing/missing_param_doc.py +++ /dev/null @@ -1,142 +0,0 @@ -#pylint: disable= missing-module-docstring - -def foobar1(arg1, arg2): #[missing-any-param-doc] - """function foobar ... - """ - print(arg1, arg2) - -def foobar2(arg1, arg2): #[missing-any-param-doc] - """function foobar ... - Parameters - ---------- - """ - print(arg1, arg2) - -def foobar3(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] - """function foobar ... - Parameters - ---------- - arg1: int - arg3: float - """ - print(arg1, arg2, arg3) - -def foobar4(arg1, arg2): #[missing-param-doc, missing-type-doc] - """function foobar ... - Parameters - ---------- - arg1: int - description - """ - print(arg1, arg2) - -def foobar5(arg1, arg2): #[missing-param-doc, missing-type-doc] - """function foobar ... - Parameters - ---------- - arg1: - description - arg2: str - """ - print(arg1, arg2) - -def foobar6(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] - """function foobar ... - Parameters - ---------- - arg1: int - description - arg2: int - """ - print(arg1, arg2, arg3) - -def foobar7(arg1, arg2): #[missing-any-param-doc] - """function foobar ... - Parameters - ---------- - arg1 - """ - print(arg1, arg2) - -def foobar8(arg1): #[missing-any-param-doc] - """function foobar""" - - print(arg1) - -def foobar9(arg1, arg2, arg3): #[missing-param-doc] - """function foobar ... - Parameters - ---------- - arg1: int - arg2: int - arg3: str - """ - print(arg1, arg2, arg3) - -def foobar10(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] - """function foobar ... - Parameters - ---------- - arg1: - desc1 - arg2: int - arg3: - desc3 - """ - print(arg1, arg2, arg3) - -def foobar11(arg1, arg2): #[missing-any-param-doc] - """function foobar ... - Args - ---------- - arg1 - arg2 - """ - print(arg1, arg2) - -def foobar12(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc] - """function foobar ... - Args - ---------- - arg1: int - arg2: - does something - arg3 - """ - print(arg1, arg2, arg3) - -def foobar13(arg1, *args, arg3=";"): - """Description of the function - - Parameters - ---------- - arg1 : str - Path to the input. - *args : - Relevant parameters. - arg3 : str, optional - File separator. - """ - print(arg1, args, arg3) - -def foobar14(arg1, *args): - """Description of the function - - Parameters - ---------- - arg1 : str - Path to the input. - *args : - Relevant parameters. - """ - print(arg1, args) - -def foobar15(*args): - """Description of the function - - Parameters - ---------- - *args : - Relevant parameters. - """ - print(args) diff --git a/tests/functional/m/missing/missing_param_doc.rc b/tests/functional/m/missing/missing_param_doc.rc deleted file mode 100644 index d4a6dc172..000000000 --- a/tests/functional/m/missing/missing_param_doc.rc +++ /dev/null @@ -1,8 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.docparams, - -[PARAMETER_DOCUMENTATION] -accept-no-param-doc=no -accept-no-raise-doc=no -accept-no-return-doc=no -accept-no-yields-doc=no diff --git a/tests/functional/m/missing/missing_param_doc.txt b/tests/functional/m/missing/missing_param_doc.txt deleted file mode 100644 index b03e20072..000000000 --- a/tests/functional/m/missing/missing_param_doc.txt +++ /dev/null @@ -1,18 +0,0 @@ -missing-any-param-doc:3:0:foobar1:"Missing any documentation in ""foobar1""" -missing-any-param-doc:8:0:foobar2:"Missing any documentation in ""foobar2""" -missing-param-doc:15:0:foobar3:"""arg1, arg2, arg3"" missing in parameter documentation" -missing-type-doc:15:0:foobar3:"""arg2"" missing in parameter type documentation" -missing-param-doc:24:0:foobar4:"""arg2"" missing in parameter documentation" -missing-type-doc:24:0:foobar4:"""arg2"" missing in parameter type documentation" -missing-param-doc:33:0:foobar5:"""arg2"" missing in parameter documentation" -missing-type-doc:33:0:foobar5:"""arg1"" missing in parameter type documentation" -missing-param-doc:43:0:foobar6:"""arg2, arg3"" missing in parameter documentation" -missing-type-doc:43:0:foobar6:"""arg3"" missing in parameter type documentation" -missing-any-param-doc:53:0:foobar7:"Missing any documentation in ""foobar7""" -missing-any-param-doc:61:0:foobar8:"Missing any documentation in ""foobar8""" -missing-param-doc:66:0:foobar9:"""arg1, arg2, arg3"" missing in parameter documentation" -missing-param-doc:76:0:foobar10:"""arg2"" missing in parameter documentation" -missing-type-doc:76:0:foobar10:"""arg1, arg3"" missing in parameter type documentation" -missing-any-param-doc:88:0:foobar11:Missing any documentation in "foobar11" -missing-param-doc:97:0:foobar12:"""arg1, arg3"" missing in parameter documentation" -missing-type-doc:97:0:foobar12:"""arg2, arg3"" missing in parameter type documentation" diff --git a/tests/functional/o/overlapping_exceptions.py b/tests/functional/o/overlapping_exceptions.py deleted file mode 100644 index c5eab48cc..000000000 --- a/tests/functional/o/overlapping_exceptions.py +++ /dev/null @@ -1,66 +0,0 @@ -# pylint: disable=missing-docstring - -import socket - - -class SomeException(Exception): - pass - - -class SubclassException(SomeException): - pass - - -AliasException = SomeException - -try: - pass -except (SomeException, SomeException): # [overlapping-except] - pass - -try: - pass -except (SomeException, SubclassException): # [overlapping-except] - pass - -try: - pass -except (SomeException, AliasException): # [overlapping-except] - pass - -try: - pass -except (AliasException, SubclassException): # [overlapping-except] - pass - -try: - pass -# +1:[overlapping-except, overlapping-except, overlapping-except] -except (SomeException, AliasException, SubclassException): - pass - -try: - pass -except (ArithmeticError, FloatingPointError): # [overlapping-except] - pass - -try: - pass -except (ValueError, UnicodeDecodeError): # [overlapping-except] - pass - - -try: - pass -except (IOError, OSError): # [overlapping-except] - pass - -try: - pass -except (socket.error, OSError): # [overlapping-except] - pass - -try: - pass -except (ConnectionError, socket.error): # [overlapping-except] - pass diff --git a/tests/functional/o/overlapping_exceptions.rc b/tests/functional/o/overlapping_exceptions.rc deleted file mode 100644 index ad49162c0..000000000 --- a/tests/functional/o/overlapping_exceptions.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.overlapping_exceptions, diff --git a/tests/functional/o/overlapping_exceptions.txt b/tests/functional/o/overlapping_exceptions.txt deleted file mode 100644 index 6669ae0f8..000000000 --- a/tests/functional/o/overlapping_exceptions.txt +++ /dev/null @@ -1,12 +0,0 @@ -overlapping-except:18:7::Overlapping exceptions (SomeException and SomeException are the same):HIGH -overlapping-except:23:7::Overlapping exceptions (SomeException is an ancestor class of SubclassException):HIGH -overlapping-except:28:7::Overlapping exceptions (SomeException and AliasException are the same):HIGH -overlapping-except:33:7::Overlapping exceptions (AliasException is an ancestor class of SubclassException):HIGH -overlapping-except:39:7::Overlapping exceptions (AliasException is an ancestor class of SubclassException):HIGH -overlapping-except:39:7::Overlapping exceptions (SomeException and AliasException are the same):HIGH -overlapping-except:39:7::Overlapping exceptions (SomeException is an ancestor class of SubclassException):HIGH -overlapping-except:44:7::Overlapping exceptions (ArithmeticError is an ancestor class of FloatingPointError):HIGH -overlapping-except:49:7::Overlapping exceptions (ValueError is an ancestor class of UnicodeDecodeError):HIGH -overlapping-except:55:7::Overlapping exceptions (IOError and OSError are the same):HIGH -overlapping-except:60:7::Overlapping exceptions (socket.error and OSError are the same):HIGH -overlapping-except:65:7::Overlapping exceptions (socket.error is an ancestor class of ConnectionError):HIGH diff --git a/tests/functional/p/plugin_does_not_exists.py b/tests/functional/p/plugin_does_not_exists.py deleted file mode 100644 index 8b31d2348..000000000 --- a/tests/functional/p/plugin_does_not_exists.py +++ /dev/null @@ -1,5 +0,0 @@ -# pylint: disable=missing-docstring - -from shadok import ShadokInteger # [import-error] - -ShadokInteger("Buga ZoMeu") diff --git a/tests/functional/p/plugin_does_not_exists.rc b/tests/functional/p/plugin_does_not_exists.rc deleted file mode 100644 index 72e7c1af7..000000000 --- a/tests/functional/p/plugin_does_not_exists.rc +++ /dev/null @@ -1,3 +0,0 @@ -[master] -load-plugins= - pylint.extensions.check_does_not_exists_in_venv, diff --git a/tests/functional/p/plugin_does_not_exists.txt b/tests/functional/p/plugin_does_not_exists.txt deleted file mode 100644 index 8d5a79f24..000000000 --- a/tests/functional/p/plugin_does_not_exists.txt +++ /dev/null @@ -1 +0,0 @@ -import-error:3:0::Unable to import 'shadok':HIGH diff --git a/tests/functional/p/py_version/py_version_35.py b/tests/functional/p/py_version/py_version_35.py deleted file mode 100644 index ee880c54a..000000000 --- a/tests/functional/p/py_version/py_version_35.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Test warnings aren't emitted for features that require Python > 3.5""" -# pylint: disable=invalid-name - -# consider-using-f-string -> requires Python 3.6 -"Hello {}".format("World") - - -# ------ -# CodeStyle extension - -# consider-using-assignment-expr -> requires Python 3.8 -a1 = 2 -if a1: - ... diff --git a/tests/functional/p/py_version/py_version_35.rc b/tests/functional/p/py_version/py_version_35.rc deleted file mode 100644 index 6f19ec36a..000000000 --- a/tests/functional/p/py_version/py_version_35.rc +++ /dev/null @@ -1,3 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.code_style -py-version=3.5 diff --git a/tests/functional/r/redefined_variable_type.py b/tests/functional/r/redefined_variable_type.py deleted file mode 100644 index aa89383d9..000000000 --- a/tests/functional/r/redefined_variable_type.py +++ /dev/null @@ -1,85 +0,0 @@ -"""Checks variable types aren't redefined within a method or a function""" - -# pylint: disable=too-few-public-methods,missing-docstring,unused-variable,invalid-name, useless-object-inheritance - -_OK = True - -class MyClass(object): - - class Klass(object): - def __init__(self): - self.var2 = 'var' - - def __init__(self): - self.var = True - self.var1 = 2 - self.var2 = 1. - self.var1 = 2. # [redefined-variable-type] - self.a_str = "hello" - a_str = False - (a_str, b_str) = (1, 2) # no support for inference on tuple assignment - a_str = 2.0 if self.var else 1.0 # [redefined-variable-type] - - def _getter(self): - return self.a_str - def _setter(self, val): - self.a_str = val - var2 = property(_getter, _setter) - - def some_method(self): - def func(): - var = 1 - test = 'bar' - var = 'baz' # [redefined-variable-type] - self.var = 1 # the rule checks for redefinitions in the scope of a function or method - test = 'foo' - myint = 2 - myint = False # [redefined-variable-type] - -_OK = "This is OK" # [redefined-variable-type] - -if _OK: - SOME_FLOAT = 1. - -def dummy_function(): - return 2 - -def other_function(): - instance = MyClass() - instance = True # [redefined-variable-type] - -SOME_FLOAT = dummy_function() # [redefined-variable-type] - -A_GLOB = None -A_GLOB = [1, 2, 3] - -def func2(x): - if x: - var = 'foo' - else: - var = True - - if x: - var2 = 'foo' - elif not x: - var2 = 2 - else: - pass - - if x: - var3 = 'foo' - var3 = 2 # [redefined-variable-type] - else: - pass - - var = 2 # [redefined-variable-type] - - if x: - pass - elif not x: - var4 = True - elif _OK: - pass - else: - var4 = 2. - var4 = 'baz' # [redefined-variable-type] diff --git a/tests/functional/r/redefined_variable_type.rc b/tests/functional/r/redefined_variable_type.rc deleted file mode 100644 index 8ee18a8f1..000000000 --- a/tests/functional/r/redefined_variable_type.rc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.redefined_variable_type, diff --git a/tests/functional/r/redefined_variable_type.txt b/tests/functional/r/redefined_variable_type.txt deleted file mode 100644 index a0205c7aa..000000000 --- a/tests/functional/r/redefined_variable_type.txt +++ /dev/null @@ -1,10 +0,0 @@ -redefined-variable-type:17:8:MyClass.__init__:Redefinition of self.var1 type from int to float:HIGH -redefined-variable-type:21:8:MyClass.__init__:Redefinition of a_str type from bool to float:HIGH -redefined-variable-type:33:12:MyClass.some_method.func:Redefinition of var type from int to str:HIGH -redefined-variable-type:37:8:MyClass.some_method:Redefinition of myint type from int to bool:HIGH -redefined-variable-type:39:0::Redefinition of _OK type from bool to str:HIGH -redefined-variable-type:49:4:other_function:Redefinition of instance type from functional.r.redefined_variable_type.MyClass to bool:HIGH -redefined-variable-type:51:0::Redefinition of SOME_FLOAT type from float to int:HIGH -redefined-variable-type:71:8:func2:Redefinition of var3 type from str to int:HIGH -redefined-variable-type:75:4:func2:Redefinition of var type from bool to int:HIGH -redefined-variable-type:85:8:func2:Redefinition of var4 type from float to str:HIGH diff --git a/tests/functional/u/useless/useless_type_doc.py b/tests/functional/u/useless/useless_type_doc.py deleted file mode 100644 index 110a7a5f5..000000000 --- a/tests/functional/u/useless/useless_type_doc.py +++ /dev/null @@ -1,73 +0,0 @@ -#pylint: disable = missing-any-param-doc -"""demonstrate FP with useless-type-doc""" - - -def function(public_param: int, _some_private_param: bool = False) -> None: - """does things - - Args: - public_param: an ordinary parameter - """ - for _ in range(public_param): - ... - if _some_private_param: - ... - else: - ... - - -def smart_function(public_param: int, _some_private_param: bool = False) -> None: - """We're speaking about _some_private_param without really documenting it. - - Args: - public_param: an ordinary parameter - """ - for _ in range(public_param): - ... - if _some_private_param: - ... - else: - ... - - -# +1: [useless-type-doc,useless-param-doc] -def function_useless_doc(public_param: int, _some_private_param: bool = False) -> None: - """does things - - Args: - public_param: an ordinary parameter - _some_private_param (bool): private param - - """ - for _ in range(public_param): - ... - if _some_private_param: - ... - else: - ... - - -def test(_new: str) -> str: - """foobar - - :return: comment - """ - return "" - - -def smarter_test(_new: str) -> str: - """We're speaking about _new without really documenting it. - - :return: comment - """ - return "" - - -# +1: [useless-type-doc,useless-param-doc] -def test_two(_new: str) -> str: - """foobar - - :param str _new: - :return: comment - """ - return "" diff --git a/tests/functional/u/useless/useless_type_doc.rc b/tests/functional/u/useless/useless_type_doc.rc deleted file mode 100644 index d4a6dc172..000000000 --- a/tests/functional/u/useless/useless_type_doc.rc +++ /dev/null @@ -1,8 +0,0 @@ -[MASTER] -load-plugins=pylint.extensions.docparams, - -[PARAMETER_DOCUMENTATION] -accept-no-param-doc=no -accept-no-raise-doc=no -accept-no-return-doc=no -accept-no-yields-doc=no diff --git a/tests/functional/u/useless/useless_type_doc.txt b/tests/functional/u/useless/useless_type_doc.txt deleted file mode 100644 index 9e1963e90..000000000 --- a/tests/functional/u/useless/useless_type_doc.txt +++ /dev/null @@ -1,4 +0,0 @@ -useless-param-doc:34:0:function_useless_doc:"""_some_private_param"" useless ignored parameter documentation":HIGH -useless-type-doc:34:0:function_useless_doc:"""_some_private_param"" useless ignored parameter type documentation":HIGH -useless-param-doc:67:0:test_two:"""_new"" useless ignored parameter documentation":HIGH -useless-type-doc:67:0:test_two:"""_new"" useless ignored parameter type documentation":HIGH -- cgit v1.2.1