diff options
Diffstat (limited to 'tests/functional/ext')
71 files changed, 967 insertions, 0 deletions
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_builtins.py b/tests/functional/ext/bad_builtin/bad_builtins.py index 9737e0ffc..9737e0ffc 100644 --- a/tests/functional/ext/bad_builtins.py +++ b/tests/functional/ext/bad_builtin/bad_builtins.py diff --git a/tests/functional/ext/bad_builtins.rc b/tests/functional/ext/bad_builtin/bad_builtins.rc index e32b9f32c..e32b9f32c 100644 --- a/tests/functional/ext/bad_builtins.rc +++ b/tests/functional/ext/bad_builtin/bad_builtins.rc diff --git a/tests/functional/ext/bad_builtins.txt b/tests/functional/ext/bad_builtin/bad_builtins.txt index 093b1d1e5..093b1d1e5 100644 --- a/tests/functional/ext/bad_builtins.txt +++ b/tests/functional/ext/bad_builtin/bad_builtins.txt 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/consider_using_assignment_expr.py index 4f9a83700..4f9a83700 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.py +++ b/tests/functional/ext/code_style/consider_using_assignment_expr.py diff --git a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.rc b/tests/functional/ext/code_style/consider_using_assignment_expr.rc index 2a659c07d..2a659c07d 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.rc +++ b/tests/functional/ext/code_style/consider_using_assignment_expr.rc diff --git a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.txt b/tests/functional/ext/code_style/consider_using_assignment_expr.txt index 64179ba72..64179ba72 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_assignment_expr.txt +++ b/tests/functional/ext/code_style/consider_using_assignment_expr.txt diff --git a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.py b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.py index 627de7684..627de7684 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.py +++ b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.py diff --git a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.rc b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.rc index 47767a206..47767a206 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.rc +++ b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.rc diff --git a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.txt b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.txt index 6c471db96..6c471db96 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.txt +++ b/tests/functional/ext/code_style/consider_using_namedtuple_or_dataclass.txt diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.py b/tests/functional/ext/code_style/consider_using_tuple.py index d24396079..d24396079 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.py +++ b/tests/functional/ext/code_style/consider_using_tuple.py diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.rc b/tests/functional/ext/code_style/consider_using_tuple.rc index 47767a206..47767a206 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.rc +++ b/tests/functional/ext/code_style/consider_using_tuple.rc diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.txt b/tests/functional/ext/code_style/consider_using_tuple.txt index 167c8c037..167c8c037 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.txt +++ b/tests/functional/ext/code_style/consider_using_tuple.txt 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/confusing_elif.py index 9f1d1ffe9..9f1d1ffe9 100644 --- a/tests/functional/ext/confusing_elif.py +++ b/tests/functional/ext/confusing_elif/confusing_elif.py diff --git a/tests/functional/ext/confusing_elif.rc b/tests/functional/ext/confusing_elif/confusing_elif.rc index 6a11b2c09..6a11b2c09 100644 --- a/tests/functional/ext/confusing_elif.rc +++ b/tests/functional/ext/confusing_elif/confusing_elif.rc diff --git a/tests/functional/ext/confusing_elif.txt b/tests/functional/ext/confusing_elif/confusing_elif.txt index 55cc0d13f..55cc0d13f 100644 --- a/tests/functional/ext/confusing_elif.txt +++ b/tests/functional/ext/confusing_elif/confusing_elif.txt diff --git a/tests/functional/ext/consider_ternary_expression.py b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py index 5ed5eaac4..5ed5eaac4 100644 --- a/tests/functional/ext/consider_ternary_expression.py +++ b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py diff --git a/tests/functional/ext/consider_ternary_expression.rc b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc index 39b1d7975..39b1d7975 100644 --- a/tests/functional/ext/consider_ternary_expression.rc +++ b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc diff --git a/tests/functional/ext/consider_ternary_expression.txt b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt index 08e51e61d..08e51e61d 100644 --- a/tests/functional/ext/consider_ternary_expression.txt +++ b/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt diff --git a/tests/functional/ext/docparams.py b/tests/functional/ext/docparams/docparams.py index 8dbb0295a..8dbb0295a 100644 --- a/tests/functional/ext/docparams.py +++ b/tests/functional/ext/docparams/docparams.py diff --git a/tests/functional/ext/docparams.rc b/tests/functional/ext/docparams/docparams.rc index eda78b640..eda78b640 100644 --- a/tests/functional/ext/docparams.rc +++ b/tests/functional/ext/docparams/docparams.rc diff --git a/tests/functional/ext/docparams.txt b/tests/functional/ext/docparams/docparams.txt index 7aa6631ed..7aa6631ed 100644 --- a/tests/functional/ext/docparams.txt +++ b/tests/functional/ext/docparams/docparams.txt 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/for_any_all.py index 785cefebd..785cefebd 100644 --- a/tests/functional/ext/for_any_all.py +++ b/tests/functional/ext/for_any_all/for_any_all.py diff --git a/tests/functional/ext/for_any_all.rc b/tests/functional/ext/for_any_all/for_any_all.rc index 41b0eaa71..41b0eaa71 100644 --- a/tests/functional/ext/for_any_all.rc +++ b/tests/functional/ext/for_any_all/for_any_all.rc diff --git a/tests/functional/ext/for_any_all.txt b/tests/functional/ext/for_any_all/for_any_all.txt index da01f06fd..da01f06fd 100644 --- a/tests/functional/ext/for_any_all.txt +++ b/tests/functional/ext/for_any_all/for_any_all.txt 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/while_used.py index 848da0d51..848da0d51 100644 --- a/tests/functional/ext/while_used.py +++ b/tests/functional/ext/while_used/while_used.py diff --git a/tests/functional/ext/while_used.rc b/tests/functional/ext/while_used/while_used.rc index 28e1b1faf..28e1b1faf 100644 --- a/tests/functional/ext/while_used.rc +++ b/tests/functional/ext/while_used/while_used.rc diff --git a/tests/functional/ext/while_used.txt b/tests/functional/ext/while_used/while_used.txt index 80ca84d56..80ca84d56 100644 --- a/tests/functional/ext/while_used.txt +++ b/tests/functional/ext/while_used/while_used.txt |