diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0cae8c0b14..2ff8c6024c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: rev: v1.4 hooks: - id: autoflake - exclude: &fixtures tests/functional/|tests/input|tests/extensions/data|tests/regrtest_data/|tests/data/ + exclude: &fixtures tests/functional/|tests/input|tests/regrtest_data/|tests/data/ args: - --in-place - --remove-all-unused-imports diff --git a/tests/extensions/data/overlapping_exceptions.py b/tests/extensions/data/overlapping_exceptions.py deleted file mode 100644 index 5ee50f3147..0000000000 --- a/tests/extensions/data/overlapping_exceptions.py +++ /dev/null @@ -1,45 +0,0 @@ -# pylint: disable=missing-docstring - -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 diff --git a/tests/extensions/data/overlapping_exceptions_py33.py b/tests/extensions/data/overlapping_exceptions_py33.py deleted file mode 100644 index 16d5c30d18..0000000000 --- a/tests/extensions/data/overlapping_exceptions_py33.py +++ /dev/null @@ -1,18 +0,0 @@ -# pylint: disable=missing-docstring - -import socket - -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/extensions/test_bad_builtin.py b/tests/extensions/test_bad_builtin.py deleted file mode 100644 index 4512873f03..0000000000 --- a/tests/extensions/test_bad_builtin.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2016-2018, 2020 Claudiu Popa -# Copyright (c) 2016-2017 Derek Gustafson -# Copyright (c) 2019-2021 Pierre Sassoulas -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020 hippo91 -# Copyright (c) 2020 Damien Baty -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.bad_builtin -""" -from os import path as osp - -import pytest - -from pylint.extensions.bad_builtin import BadBuiltinChecker -from pylint.lint import fix_import_path -from pylint.lint.pylinter import PyLinter - -EXPECTED = [ - "Used builtin function 'map'. Using a list comprehension can be clearer.", - "Used builtin function 'filter'. Using a list comprehension can be clearer.", -] - - -@pytest.fixture(scope="module") -def checker(): - return BadBuiltinChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_types_redefined(linter: PyLinter) -> None: - elif_test = osp.join(osp.dirname(osp.abspath(__file__)), "data", "bad_builtin.py") - with fix_import_path([elif_test]): - linter.check([elif_test]) - msgs = sorted(linter.reporter.messages, key=lambda item: item.line) - assert len(msgs) == 2 - for msg, expected in zip(msgs, EXPECTED): - assert msg.symbol == "bad-builtin" - assert msg.msg == expected diff --git a/tests/extensions/test_broad_try_clause.py b/tests/extensions/test_broad_try_clause.py deleted file mode 100644 index 4e38adb235..0000000000 --- a/tests/extensions/test_broad_try_clause.py +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright (c) 2019-2020 Claudiu Popa -# Copyright (c) 2019-2020 Tyler Thieding -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020-2021 Pierre Sassoulas -# Copyright (c) 2020 hippo91 -# Copyright (c) 2020 Damien Baty -# Copyright (c) 2020 Anthony Sottile -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.broad_try_clause`""" -import unittest -from os import path as osp -from typing import TYPE_CHECKING, Optional - -from pylint import checkers -from pylint.extensions.broad_try_clause import BroadTryClauseChecker -from pylint.lint import PyLinter -from pylint.reporters import BaseReporter - -if TYPE_CHECKING: - from pylint.reporters.ureports.nodes import Section - - -class BroadTryClauseTestReporter(BaseReporter): - def on_set_current_module(self, module: str, filepath: Optional[str]) -> None: - self.messages = [] - - def _display(self, layout: "Section") -> None: - pass - - -class BroadTryClauseTC(unittest.TestCase): - _linter = PyLinter() - - @classmethod - def setUpClass(cls): - cls._linter.set_reporter(BroadTryClauseTestReporter()) - checkers.initialize(cls._linter) - cls._linter.register_checker(BroadTryClauseChecker(cls._linter)) - cls._linter.disable("I") - - def test_broad_try_clause_message(self) -> None: - broad_try_clause_test = osp.join( - osp.dirname(osp.abspath(__file__)), "data", "broad_try_clause.py" - ) - self._linter.check([broad_try_clause_test]) - msgs = self._linter.reporter.messages - self.assertEqual(len(msgs), 4) - - self.assertEqual(msgs[0].symbol, "too-many-try-statements") - self.assertEqual( - msgs[0].msg, "try clause contains 3 statements, expected at most 1" - ) - self.assertEqual(msgs[0].line, 5) - - self.assertEqual(msgs[1].symbol, "too-many-try-statements") - self.assertEqual( - msgs[1].msg, "try clause contains 3 statements, expected at most 1" - ) - self.assertEqual(msgs[1].line, 12) - - self.assertEqual(msgs[2].symbol, "too-many-try-statements") - self.assertEqual( - msgs[2].msg, "try clause contains 4 statements, expected at most 1" - ) - self.assertEqual(msgs[2].line, 19) - - self.assertEqual(msgs[3].symbol, "too-many-try-statements") - self.assertEqual( - msgs[3].msg, "try clause contains 7 statements, expected at most 1" - ) - self.assertEqual(msgs[3].line, 29) diff --git a/tests/extensions/test_check_mccabe.py b/tests/extensions/test_check_mccabe.py deleted file mode 100644 index 14d2d37add..0000000000 --- a/tests/extensions/test_check_mccabe.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2016-2018, 2020 Claudiu Popa -# Copyright (c) 2016-2017 Derek Gustafson -# Copyright (c) 2016 Moises Lopez -# Copyright (c) 2019-2021 Pierre Sassoulas -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020 hippo91 -# Copyright (c) 2020 Damien Baty -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_mccabe""" -# pylint: disable=redefined-outer-name - -from os import path as osp -from typing import List - -import pytest - -from pylint.extensions import mccabe -from pylint.lint.pylinter import PyLinter - -EXPECTED_MSGS = [ - "'f1' is too complex. The McCabe rating is 1", - "'f2' is too complex. The McCabe rating is 1", - "'f3' is too complex. The McCabe rating is 3", - "'f4' is too complex. The McCabe rating is 2", - "'f5' is too complex. The McCabe rating is 2", - "'f6' is too complex. The McCabe rating is 2", - "'f7' is too complex. The McCabe rating is 3", - "'f8' is too complex. The McCabe rating is 4", - "'f9' is too complex. The McCabe rating is 9", - "'method1' is too complex. The McCabe rating is 1", - "This 'for' is too complex. The McCabe rating is 4", - "'method3' is too complex. The McCabe rating is 2", - "'f10' is too complex. The McCabe rating is 11", - "'method2' is too complex. The McCabe rating is 18", -] - - -@pytest.fixture(scope="module") -def enable(): - return ["too-complex"] - - -@pytest.fixture(scope="module") -def disable(): - return ["all"] - - -@pytest.fixture(scope="module") -def register(): - return mccabe.register - - -@pytest.fixture -def fname_mccabe_example() -> str: - return osp.join(osp.dirname(osp.abspath(__file__)), "data", "mccabe.py") - - -@pytest.mark.parametrize( - "complexity, expected", [(0, EXPECTED_MSGS), (9, EXPECTED_MSGS[-2:])] -) -def test_max_mccabe_rate( - linter: PyLinter, fname_mccabe_example: str, complexity: int, expected: List[str] -) -> None: - linter.global_set_option("max-complexity", complexity) - linter.check([fname_mccabe_example]) - real_msgs = [message.msg for message in linter.reporter.messages] - assert sorted(expected) == sorted(real_msgs) diff --git a/tests/extensions/test_comparetozero.py b/tests/extensions/test_comparetozero.py deleted file mode 100644 index 7b5bb1624d..0000000000 --- a/tests/extensions/test_comparetozero.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2016 Alexander Todorov -# Copyright (c) 2016 Łukasz Rogalski -# Copyright (c) 2017-2018, 2020 Claudiu Popa -# Copyright (c) 2019-2021 Pierre Sassoulas -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020 hippo91 -# Copyright (c) 2020 Anthony Sottile -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.emptystring""" - -import os -import unittest -from typing import TYPE_CHECKING, Optional - -from pylint import checkers -from pylint.extensions.comparetozero import CompareToZeroChecker -from pylint.lint import PyLinter -from pylint.reporters import BaseReporter - -if TYPE_CHECKING: - from pylint.reporters.ureports.nodes import Section - - -class CompareToZeroTestReporter(BaseReporter): - def on_set_current_module(self, module: str, filepath: Optional[str]) -> None: - self.messages = [] - - def _display(self, layout: "Section") -> None: - pass - - -class CompareToZeroUsedTC(unittest.TestCase): - _linter = PyLinter() - - @classmethod - def setUpClass(cls) -> None: - cls._linter.set_reporter(CompareToZeroTestReporter()) - checkers.initialize(cls._linter) - cls._linter.register_checker(CompareToZeroChecker(cls._linter)) - cls._linter.disable("I") - - def test_comparetozero_message(self) -> None: - elif_test = os.path.join( - os.path.dirname(os.path.abspath(__file__)), "data", "compare_to_zero.py" - ) - self._linter.check([elif_test]) - msgs = self._linter.reporter.messages - self.assertEqual(len(msgs), 4) - for msg in msgs: - self.assertEqual(msg.symbol, "compare-to-zero") - self.assertEqual(msg.msg, "Avoid comparisons to zero") - self.assertEqual(msgs[0].line, 6) - self.assertEqual(msgs[1].line, 9) - self.assertEqual(msgs[2].line, 12) - self.assertEqual(msgs[3].line, 15) diff --git a/tests/extensions/test_docstyle.py b/tests/extensions/test_docstyle.py deleted file mode 100644 index 7c1d019e7b..0000000000 --- a/tests/extensions/test_docstyle.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2016-2018, 2020 Claudiu Popa -# Copyright (c) 2016-2017 Derek Gustafson -# Copyright (c) 2016 Luis Escobar -# Copyright (c) 2019-2021 Pierre Sassoulas -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020 hippo91 -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_docstring -""" - -from os.path import abspath, dirname, join - -import pytest - -from pylint.extensions.docstyle import DocStringStyleChecker -from pylint.lint.pylinter import PyLinter - -EXPECTED_MSGS = [ - "First line empty in function docstring", - "First line empty in class docstring", - "First line empty in method docstring", - "Bad docstring quotes in method, expected \"\"\", given '''", - 'Bad docstring quotes in method, expected """, given "', - 'Bad docstring quotes in method, expected """, given \'', - 'Bad docstring quotes in method, expected """, given \'', -] - -EXPECTED_SYMBOLS = [ - "docstring-first-line-empty", - "docstring-first-line-empty", - "docstring-first-line-empty", - "bad-docstring-quotes", - "bad-docstring-quotes", - "bad-docstring-quotes", - "bad-docstring-quotes", -] - - -@pytest.fixture(scope="module") -def checker(): - return DocStringStyleChecker - - -def test_docstring_message(linter: PyLinter) -> None: - docstring_test = join(dirname(abspath(__file__)), "data", "docstring.py") - linter.check([docstring_test]) - msgs = linter.reporter.messages - assert len(msgs) == 7 - for msg, expected_symbol, expected_msg in zip( - msgs, EXPECTED_SYMBOLS, EXPECTED_MSGS - ): - assert msg.symbol == expected_symbol - assert msg.msg == expected_msg diff --git a/tests/extensions/test_elseif_used.py b/tests/extensions/test_elseif_used.py deleted file mode 100644 index 994a5efcf9..0000000000 --- a/tests/extensions/test_elseif_used.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2015-2018, 2020 Claudiu Popa -# Copyright (c) 2015 LOGILAB S.A. (Paris, FRANCE) -# Copyright (c) 2016-2017 Derek Gustafson -# Copyright (c) 2019-2021 Pierre Sassoulas -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020 hippo91 -# Copyright (c) 2020 Damien Baty -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_elif -""" -from os import path as osp - -import pytest - -from pylint.extensions.check_elif import ElseifUsedChecker -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return ElseifUsedChecker - - -def test_elseif_message(linter: PyLinter) -> None: - elif_test = osp.join(osp.dirname(osp.abspath(__file__)), "data", "elif.py") - linter.check([elif_test]) - msgs = linter.reporter.messages - assert len(msgs) == 2 - for msg in msgs: - assert msg.symbol == "else-if-used" - assert msg.msg == 'Consider using "elif" instead of "else if"' - assert msgs[0].line == 9 - assert msgs[1].line == 21 diff --git a/tests/extensions/test_empty_comment.py b/tests/extensions/test_empty_comment.py deleted file mode 100644 index 42d1b51f23..0000000000 --- a/tests/extensions/test_empty_comment.py +++ /dev/null @@ -1,35 +0,0 @@ -from pathlib import Path - -import pytest - -from pylint.extensions import empty_comment -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return empty_comment.CommentChecker - - -@pytest.fixture(scope="module") -def enable(): - return ["empty-comment"] - - -@pytest.fixture(scope="module") -def disable(): - return ["all"] - - -def test_comment_base_case(linter: PyLinter) -> None: - comment_test = str(Path(__file__).parent.joinpath("data", "empty_comment.py")) - linter.check([comment_test]) - msgs = linter.reporter.messages - assert len(msgs) == 4 - for msg in msgs: - assert msg.symbol == "empty-comment" - assert msg.msg == "Line with empty comment" - assert msgs[0].line == 2 - assert msgs[1].line == 3 - assert msgs[2].line == 5 - assert msgs[3].line == 7 diff --git a/tests/extensions/test_emptystring.py b/tests/extensions/test_emptystring.py deleted file mode 100644 index f89f9202fa..0000000000 --- a/tests/extensions/test_emptystring.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2016 Łukasz Rogalski -# Copyright (c) 2016 Alexander Todorov -# Copyright (c) 2017-2018, 2020 Claudiu Popa -# Copyright (c) 2017 Derek Gustafson -# Copyright (c) 2019-2021 Pierre Sassoulas -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020 hippo91 -# Copyright (c) 2020 Damien Baty -# Copyright (c) 2020 Anthony Sottile -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.emptystring -""" -from os import path as osp - -import pytest - -from pylint.extensions.emptystring import CompareToEmptyStringChecker -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return CompareToEmptyStringChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_emptystring_message(linter: PyLinter) -> None: - elif_test = osp.join( - osp.dirname(osp.abspath(__file__)), "data", "empty_string_comparison.py" - ) - linter.check([elif_test]) - msgs = linter.reporter.messages - expected_lineno = [6, 9, 12, 15] - assert len(msgs) == len(expected_lineno) - for msg, lineno in zip(msgs, expected_lineno): - assert msg.symbol == "compare-to-empty-string" - assert msg.msg == "Avoid comparisons to empty string" - assert msg.line == lineno diff --git a/tests/extensions/test_overlapping_exceptions.py b/tests/extensions/test_overlapping_exceptions.py deleted file mode 100644 index 005e0bcf94..0000000000 --- a/tests/extensions/test_overlapping_exceptions.py +++ /dev/null @@ -1,88 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.overlapping_exceptions -""" - -from os.path import dirname, join - -import pytest - -from pylint.extensions.overlapping_exceptions import OverlappingExceptionsChecker -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return OverlappingExceptionsChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_overlapping_exceptions(linter: PyLinter) -> None: - test = join(dirname(__file__), "data", "overlapping_exceptions.py") - linter.check([test]) - msgs = linter.reporter.messages - - expected = [ - (13, "Overlapping exceptions (SomeException and SomeException are the same)"), - ( - 18, - "Overlapping exceptions (SomeException is an ancestor class of SubclassException)", - ), - (23, "Overlapping exceptions (SomeException and AliasException are the same)"), - ( - 28, - "Overlapping exceptions (AliasException is an ancestor class of SubclassException)", - ), - (34, "Overlapping exceptions (SomeException and AliasException are the same)"), - ( - 34, - "Overlapping exceptions (SomeException is an ancestor class of SubclassException)", - ), - ( - 34, - "Overlapping exceptions (AliasException is an ancestor class of SubclassException)", - ), - ( - 39, - "Overlapping exceptions (ArithmeticError is an ancestor class of FloatingPointError)", - ), - ( - 44, - "Overlapping exceptions (ValueError is an ancestor class of UnicodeDecodeError)", - ), - ] - - assert len(msgs) == len(expected) - for msg, exp in zip(msgs, expected): - assert msg.msg_id == "W0714" - assert msg.symbol == "overlapping-except" - assert msg.category == "warning" - assert (msg.line, msg.msg) == exp - - -def test_overlapping_exceptions_py33(linter: PyLinter) -> None: - """From Python 3.3 both IOError and socket.error are aliases for OSError.""" - test = join(dirname(__file__), "data", "overlapping_exceptions_py33.py") - linter.check([test]) - msgs = linter.reporter.messages - - expected = [ - (7, "Overlapping exceptions (IOError and OSError are the same)"), - (12, "Overlapping exceptions (socket.error and OSError are the same)"), - ( - 17, - "Overlapping exceptions (socket.error is an ancestor class of ConnectionError)", - ), - ] - - assert len(msgs) == len(expected) - for msg, exp in zip(msgs, expected): - assert msg.msg_id == "W0714" - assert msg.symbol == "overlapping-except" - assert msg.category == "warning" - assert (msg.line, msg.msg) == exp diff --git a/tests/extensions/test_redefined.py b/tests/extensions/test_redefined.py deleted file mode 100644 index 1f945bf791..0000000000 --- a/tests/extensions/test_redefined.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2016-2020 Claudiu Popa -# Copyright (c) 2016-2017 Derek Gustafson -# Copyright (c) 2019-2021 Pierre Sassoulas -# Copyright (c) 2019 Ashley Whetter -# Copyright (c) 2020 hippo91 -# Copyright (c) 2020 Damien Baty -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_elif""" -from os import path as osp - -import pytest - -from pylint.extensions.redefined_variable_type import MultipleTypesChecker -from pylint.lint import fix_import_path -from pylint.lint.pylinter import PyLinter - -EXPECTED = [ - "Redefinition of self.var1 type from int to float", - "Redefinition of a_str type from bool to float", - "Redefinition of var type from int to str", - "Redefinition of myint type from int to bool", - "Redefinition of _OK type from bool to str", - "Redefinition of instance type from redefined.MyClass to bool", - "Redefinition of SOME_FLOAT type from float to int", - "Redefinition of var3 type from str to int", - "Redefinition of var type from bool to int", - "Redefinition of var4 type from float to str", -] - - -@pytest.fixture(scope="module") -def checker(): - return MultipleTypesChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_types_redefined(linter: PyLinter) -> None: - elif_test = osp.join(osp.dirname(osp.abspath(__file__)), "data", "redefined.py") - with fix_import_path([elif_test]): - linter.check([elif_test]) - msgs = sorted(linter.reporter.messages, key=lambda item: item.line) - assert len(msgs) == 10 - for msg, expected in zip(msgs, EXPECTED): - assert msg.symbol == "redefined-variable-type" - assert msg.msg == expected diff --git a/tests/extensions/data/bad_builtin.py b/tests/functional/ext/bad_builtin/bad_builtin_extension.py similarity index 100% rename from tests/extensions/data/bad_builtin.py rename to tests/functional/ext/bad_builtin/bad_builtin_extension.py 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 0000000000..de9b4244a6 --- /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 0000000000..e074657b2d --- /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 similarity index 100% rename from tests/functional/ext/bad_builtins.py rename to 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 similarity index 100% rename from tests/functional/ext/bad_builtins.rc rename to 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 similarity index 100% rename from tests/functional/ext/bad_builtins.txt rename to tests/functional/ext/bad_builtin/bad_builtins.txt diff --git a/tests/extensions/data/broad_try_clause.py b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.py similarity index 88% rename from tests/extensions/data/broad_try_clause.py rename to tests/functional/ext/broad_try_clause/broad_try_clause_extension.py index 2bbc4e7a22..6fc85c6b27 100644 --- a/tests/extensions/data/broad_try_clause.py +++ b/tests/functional/ext/broad_try_clause/broad_try_clause_extension.py @@ -2,21 +2,21 @@ MY_DICTIONARY = {"key_one": 1, "key_two": 2, "key_three": 3} -try: # [max-try-statements] +try: # [too-many-try-statements] value = MY_DICTIONARY["key_one"] value += 1 print("This one has an except clause only.") except KeyError: pass -try: # [max-try-statements] +try: # [too-many-try-statements] value = MY_DICTIONARY["key_one"] value += 1 print("This one has a finally clause only.") finally: pass -try: # [max-try-statements] +try: # [too-many-try-statements] value = MY_DICTIONARY["key_one"] value += 1 print("This one has an except clause...") @@ -26,7 +26,7 @@ finally: pass -try: # [max-try-statements] +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.") 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 0000000000..1737783e0a --- /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 0000000000..8f97f9b247 --- /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/extensions/data/elif.py b/tests/functional/ext/check_elif/check_elif.py similarity index 85% rename from tests/extensions/data/elif.py rename to tests/functional/ext/check_elif/check_elif.py index 22e79c1dba..b9722f349a 100644 --- a/tests/extensions/data/elif.py +++ b/tests/functional/ext/check_elif/check_elif.py @@ -1,12 +1,13 @@ """Checks use of "else if" triggers a refactor message""" + def my_function(): """docstring""" myint = 2 if myint > 5: pass else: - if myint <= 5: + if myint <= 5: # [else-if-used] pass else: myint = 3 @@ -18,7 +19,7 @@ def my_function(): elif myint < 3: pass else: - if myint: + if myint: # [else-if-used] pass else: if myint: diff --git a/tests/functional/ext/check_elif/check_elif.rc b/tests/functional/ext/check_elif/check_elif.rc new file mode 100644 index 0000000000..b9b1de49d3 --- /dev/null +++ b/tests/functional/ext/check_elif/check_elif.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.check_elif, diff --git a/tests/functional/ext/check_elif/check_elif.txt b/tests/functional/ext/check_elif/check_elif.txt new file mode 100644 index 0000000000..43d1e3b1ee --- /dev/null +++ b/tests/functional/ext/check_elif/check_elif.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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_assignment_expr.py rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_assignment_expr.rc rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_assignment_expr.txt rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.py rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.rc rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_namedtuple_or_dataclass.txt rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_tuple.py rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_tuple.rc rename to 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 similarity index 100% rename from tests/functional/ext/code_style/code_style_consider_using_tuple.txt rename to tests/functional/ext/code_style/consider_using_tuple.txt diff --git a/tests/functional/p/py_version/py_version_35.py b/tests/functional/ext/code_style/py_version_35.py similarity index 100% rename from tests/functional/p/py_version/py_version_35.py rename to tests/functional/ext/code_style/py_version_35.py diff --git a/tests/functional/p/py_version/py_version_35.rc b/tests/functional/ext/code_style/py_version_35.rc similarity index 100% rename from tests/functional/p/py_version/py_version_35.rc rename to tests/functional/ext/code_style/py_version_35.rc diff --git a/tests/extensions/data/compare_to_zero.py b/tests/functional/ext/comparetozero/comparetozero.py similarity index 100% rename from tests/extensions/data/compare_to_zero.py rename to tests/functional/ext/comparetozero/comparetozero.py diff --git a/tests/functional/ext/comparetozero/comparetozero.rc b/tests/functional/ext/comparetozero/comparetozero.rc new file mode 100644 index 0000000000..e9b836539e --- /dev/null +++ b/tests/functional/ext/comparetozero/comparetozero.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.comparetozero, diff --git a/tests/functional/ext/comparetozero/comparetozero.txt b/tests/functional/ext/comparetozero/comparetozero.txt new file mode 100644 index 0000000000..c5862e1b7a --- /dev/null +++ b/tests/functional/ext/comparetozero/comparetozero.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/m/misplaced_comparison_constant.py b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.py similarity index 100% rename from tests/functional/m/misplaced_comparison_constant.py rename to tests/functional/ext/comparison_placement/misplaced_comparison_constant.py 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 0000000000..a8df8ab8bb --- /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/m/misplaced_comparison_constant.txt b/tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt similarity index 100% rename from tests/functional/m/misplaced_comparison_constant.txt rename to tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt diff --git a/tests/functional/ext/confusing_elif.py b/tests/functional/ext/confusing_elif/confusing_elif.py similarity index 100% rename from tests/functional/ext/confusing_elif.py rename to 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 similarity index 100% rename from tests/functional/ext/confusing_elif.rc rename to 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 similarity index 100% rename from tests/functional/ext/confusing_elif.txt rename to 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 similarity index 100% rename from tests/functional/ext/consider_ternary_expression.py rename to 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 similarity index 100% rename from tests/functional/ext/consider_ternary_expression.rc rename to 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 similarity index 100% rename from tests/functional/ext/consider_ternary_expression.txt rename to 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 similarity index 100% rename from tests/functional/ext/docparams.py rename to tests/functional/ext/docparams/docparams.py diff --git a/tests/functional/ext/docparams.rc b/tests/functional/ext/docparams/docparams.rc similarity index 100% rename from tests/functional/ext/docparams.rc rename to tests/functional/ext/docparams/docparams.rc diff --git a/tests/functional/ext/docparams.txt b/tests/functional/ext/docparams/docparams.txt similarity index 100% rename from tests/functional/ext/docparams.txt rename to tests/functional/ext/docparams/docparams.txt diff --git a/tests/functional/m/missing/missing_param_doc.py b/tests/functional/ext/docparams/missing_param_doc.py similarity index 100% rename from tests/functional/m/missing/missing_param_doc.py rename to tests/functional/ext/docparams/missing_param_doc.py diff --git a/tests/functional/m/missing/missing_param_doc.rc b/tests/functional/ext/docparams/missing_param_doc.rc similarity index 100% rename from tests/functional/m/missing/missing_param_doc.rc rename to tests/functional/ext/docparams/missing_param_doc.rc diff --git a/tests/functional/m/missing/missing_param_doc.txt b/tests/functional/ext/docparams/missing_param_doc.txt similarity index 100% rename from tests/functional/m/missing/missing_param_doc.txt rename to tests/functional/ext/docparams/missing_param_doc.txt diff --git a/tests/functional/u/useless/useless_type_doc.py b/tests/functional/ext/docparams/useless_type_doc.py similarity index 100% rename from tests/functional/u/useless/useless_type_doc.py rename to tests/functional/ext/docparams/useless_type_doc.py diff --git a/tests/functional/u/useless/useless_type_doc.rc b/tests/functional/ext/docparams/useless_type_doc.rc similarity index 100% rename from tests/functional/u/useless/useless_type_doc.rc rename to tests/functional/ext/docparams/useless_type_doc.rc diff --git a/tests/functional/u/useless/useless_type_doc.txt b/tests/functional/ext/docparams/useless_type_doc.txt similarity index 100% rename from tests/functional/u/useless/useless_type_doc.txt rename to tests/functional/ext/docparams/useless_type_doc.txt diff --git a/tests/extensions/data/docstring.py b/tests/functional/ext/docstyle/docstyle.py similarity index 57% rename from tests/extensions/data/docstring.py rename to tests/functional/ext/docstyle/docstyle.py index 8f34c657f8..a5b6161b05 100644 --- a/tests/extensions/data/docstring.py +++ b/tests/functional/ext/docstyle/docstyle.py @@ -1,35 +1,36 @@ """Checks of Dosctrings 'docstring-first-line-empty' 'bad-docstring-quotes'""" -def check_messages(*messages): +def check_messages(*messages): # [docstring-first-line-empty] """ docstring""" return messages + def function2(): """Test Ok""" -class FFFF: + +class FFFF: # [docstring-first-line-empty] """ Test Docstring First Line Empty """ - def method1(self): + def method1(self): # [docstring-first-line-empty, bad-docstring-quotes] ''' Test Triple Single Quotes docstring ''' - def method2(self): + def method2(self): # [bad-docstring-quotes] "bad docstring 1" - def method3(self): + def method3(self): # [bad-docstring-quotes] 'bad docstring 2' - def method4(self): + def method4(self): # [bad-docstring-quotes] ' """bad docstring 3 ' - @check_messages('bad-open-mode', 'redundant-unittest-assert', - 'deprecated-module') + @check_messages("bad-open-mode", "redundant-unittest-assert", "deprecated-module") def method5(self): """Test OK 1 with decorators""" diff --git a/tests/functional/ext/docstyle/docstyle.rc b/tests/functional/ext/docstyle/docstyle.rc new file mode 100644 index 0000000000..5128289ffb --- /dev/null +++ b/tests/functional/ext/docstyle/docstyle.rc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.docstyle, diff --git a/tests/functional/ext/docstyle/docstyle.txt b/tests/functional/ext/docstyle/docstyle.txt new file mode 100644 index 0000000000..8a30eedeee --- /dev/null +++ b/tests/functional/ext/docstyle/docstyle.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/extensions/data/empty_comment.py b/tests/functional/ext/empty_comment/empty_comment.py similarity index 71% rename from tests/extensions/data/empty_comment.py rename to tests/functional/ext/empty_comment/empty_comment.py index 8a18df2ebd..6adaa4fc15 100644 --- a/tests/extensions/data/empty_comment.py +++ b/tests/functional/ext/empty_comment/empty_comment.py @@ -1,9 +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 0000000000..1bbd021e70 --- /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 0000000000..ae4eee33ec --- /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/extensions/data/empty_string_comparison.py b/tests/functional/ext/emptystring/empty_string_comparison.py similarity index 100% rename from tests/extensions/data/empty_string_comparison.py rename to tests/functional/ext/emptystring/empty_string_comparison.py 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 0000000000..e6e3ded018 --- /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 0000000000..7e31c3d25f --- /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 similarity index 100% rename from tests/functional/ext/for_any_all.py rename to 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 similarity index 100% rename from tests/functional/ext/for_any_all.rc rename to 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 similarity index 100% rename from tests/functional/ext/for_any_all.txt rename to tests/functional/ext/for_any_all/for_any_all.txt diff --git a/tests/extensions/data/mccabe.py b/tests/functional/ext/mccabe/mccabe.py similarity index 74% rename from tests/extensions/data/mccabe.py rename to tests/functional/ext/mccabe/mccabe.py index fdbdb5f0c2..b5a257b1f6 100644 --- a/tests/extensions/data/mccabe.py +++ b/tests/functional/ext/mccabe/mccabe.py @@ -1,19 +1,24 @@ +# 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(): +def f1(): # [too-complex] """McCabe rating: 1""" pass -def f2(n): +def f2(n): # [too-complex] """McCabe rating: 1""" k = n + 4 s = k + n return s -def f3(n): +def f3(n): # [too-complex] """McCabe rating: 3""" if n > 3: return "bigger than three" @@ -23,13 +28,13 @@ def f3(n): return "smaller than or equal to three" -def f4(): +def f4(): # [too-complex] """McCabe rating: 2""" for i in range(10): print(i) -def f5(mylist): +def f5(mylist): # [too-complex] """McCabe rating: 2""" for i in mylist: print(i) @@ -37,7 +42,7 @@ def f5(mylist): print(None) -def f6(n): +def f6(n): # [too-complex] """McCabe rating: 2""" if n > 4: return f(n - 1) @@ -45,18 +50,22 @@ def f6(n): return n -def f7(): +def f7(): # [too-complex] """McCabe rating: 3""" + def b(): """McCabe rating: 2""" + def c(): """McCabe rating: 1""" pass + c() + b() -def f8(): +def f8(): # [too-complex] """McCabe rating: 4""" try: print(1) @@ -68,7 +77,7 @@ def f8(): print(4) -def f9(): +def f9(): # [too-complex] """McCabe rating: 9""" myint = 2 if myint > 5: @@ -94,7 +103,7 @@ def f9(): myint = 4 -def f10(): +def f10(): # [too-complex] """McCabe rating: 11""" myint = 2 if myint == 5: @@ -123,13 +132,14 @@ def f10(): class MyClass1(object): """Class of example to test mccabe""" - _name = 'MyClass' # To force a tail.node=None - def method1(): + _name = "MyClass" # To force a tail.node=None + + def method1(): # [too-complex] """McCabe rating: 1""" pass - def method2(self, param1): + def method2(self, param1): # [too-complex, too-many-branches] """McCabe rating: 18""" if not param1: pass @@ -159,7 +169,7 @@ def method2(self, param1): pass for count in range(6): - with open('myfile') as fp: + with open("myfile") as fp: count += 1 pass pass @@ -170,8 +180,8 @@ def method2(self, param1): else: pass if param1: - raise BaseException('Error') - with open('myfile2') as fp2: + raise BaseException("Error") + with open("myfile2") as fp2: pass pass finally: @@ -180,12 +190,12 @@ def method2(self, param1): for count2 in range(8): try: pass - except BaseException('Error2'): + except BaseException("Error2"): pass return param1 -for count in range(10): +for count in range(10): # [too-complex] if count == 1: exit(0) elif count == 2: @@ -194,7 +204,8 @@ def method2(self, param1): exit(2) -def method3(self): +def method3(self): # [too-complex] + """McCabe rating: 2""" try: if True: pass diff --git a/tests/functional/ext/mccabe/mccabe.rc b/tests/functional/ext/mccabe/mccabe.rc new file mode 100644 index 0000000000..ac96a1eb59 --- /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 0000000000..3e4a8431dd --- /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 0000000000..c5eab48cc6 --- /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 0000000000..ad49162c0d --- /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 0000000000..6669ae0f87 --- /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/p/plugin_does_not_exists.py b/tests/functional/ext/plugin_does_not_exists.py similarity index 100% rename from tests/functional/p/plugin_does_not_exists.py rename to tests/functional/ext/plugin_does_not_exists.py diff --git a/tests/functional/p/plugin_does_not_exists.rc b/tests/functional/ext/plugin_does_not_exists.rc similarity index 100% rename from tests/functional/p/plugin_does_not_exists.rc rename to tests/functional/ext/plugin_does_not_exists.rc diff --git a/tests/functional/p/plugin_does_not_exists.txt b/tests/functional/ext/plugin_does_not_exists.txt similarity index 100% rename from tests/functional/p/plugin_does_not_exists.txt rename to tests/functional/ext/plugin_does_not_exists.txt diff --git a/tests/extensions/data/redefined.py b/tests/functional/ext/redefined_variable_type/redefined_variable_type.py similarity index 96% rename from tests/extensions/data/redefined.py rename to tests/functional/ext/redefined_variable_type/redefined_variable_type.py index 8829c4383c..aa89383d9e 100644 --- a/tests/extensions/data/redefined.py +++ b/tests/functional/ext/redefined_variable_type/redefined_variable_type.py @@ -18,7 +18,7 @@ def __init__(self): 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 + a_str = 2.0 if self.var else 1.0 # [redefined-variable-type] def _getter(self): return self.a_str 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 0000000000..8ee18a8f10 --- /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 0000000000..e2d52aed74 --- /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 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/set_membership/set_membership_use_set_membership.py b/tests/functional/ext/set_membership/use_set_membership.py similarity index 100% rename from tests/functional/ext/set_membership/set_membership_use_set_membership.py rename to tests/functional/ext/set_membership/use_set_membership.py diff --git a/tests/functional/ext/set_membership/set_membership_use_set_membership.rc b/tests/functional/ext/set_membership/use_set_membership.rc similarity index 100% rename from tests/functional/ext/set_membership/set_membership_use_set_membership.rc rename to tests/functional/ext/set_membership/use_set_membership.rc diff --git a/tests/functional/ext/set_membership/set_membership_use_set_membership.txt b/tests/functional/ext/set_membership/use_set_membership.txt similarity index 100% rename from tests/functional/ext/set_membership/set_membership_use_set_membership.txt rename to tests/functional/ext/set_membership/use_set_membership.txt diff --git a/tests/functional/ext/typing/typing_consider_using_alias.py b/tests/functional/ext/typing/consider_using_alias.py similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_alias.py rename to tests/functional/ext/typing/consider_using_alias.py diff --git a/tests/functional/ext/typing/typing_consider_using_alias.rc b/tests/functional/ext/typing/consider_using_alias.rc similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_alias.rc rename to tests/functional/ext/typing/consider_using_alias.rc diff --git a/tests/functional/ext/typing/typing_consider_using_alias.txt b/tests/functional/ext/typing/consider_using_alias.txt similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_alias.txt rename to tests/functional/ext/typing/consider_using_alias.txt diff --git a/tests/functional/ext/typing/typing_consider_using_alias_without_future.py b/tests/functional/ext/typing/consider_using_alias_without_future.py similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_alias_without_future.py rename to tests/functional/ext/typing/consider_using_alias_without_future.py diff --git a/tests/functional/ext/typing/typing_consider_using_alias_without_future.rc b/tests/functional/ext/typing/consider_using_alias_without_future.rc similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_alias_without_future.rc rename to tests/functional/ext/typing/consider_using_alias_without_future.rc diff --git a/tests/functional/ext/typing/typing_consider_using_alias_without_future.txt b/tests/functional/ext/typing/consider_using_alias_without_future.txt similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_alias_without_future.txt rename to tests/functional/ext/typing/consider_using_alias_without_future.txt diff --git a/tests/functional/ext/typing/typing_consider_using_union.py b/tests/functional/ext/typing/consider_using_union.py similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union.py rename to tests/functional/ext/typing/consider_using_union.py diff --git a/tests/functional/ext/typing/typing_consider_using_union.rc b/tests/functional/ext/typing/consider_using_union.rc similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union.rc rename to tests/functional/ext/typing/consider_using_union.rc diff --git a/tests/functional/ext/typing/typing_consider_using_union.txt b/tests/functional/ext/typing/consider_using_union.txt similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union.txt rename to tests/functional/ext/typing/consider_using_union.txt diff --git a/tests/functional/ext/typing/typing_consider_using_union_py310.py b/tests/functional/ext/typing/consider_using_union_py310.py similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union_py310.py rename to tests/functional/ext/typing/consider_using_union_py310.py diff --git a/tests/functional/ext/typing/typing_consider_using_union_py310.rc b/tests/functional/ext/typing/consider_using_union_py310.rc similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union_py310.rc rename to tests/functional/ext/typing/consider_using_union_py310.rc diff --git a/tests/functional/ext/typing/typing_consider_using_union_py310.txt b/tests/functional/ext/typing/consider_using_union_py310.txt similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union_py310.txt rename to tests/functional/ext/typing/consider_using_union_py310.txt diff --git a/tests/functional/ext/typing/typing_consider_using_union_without_future.py b/tests/functional/ext/typing/consider_using_union_without_future.py similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union_without_future.py rename to tests/functional/ext/typing/consider_using_union_without_future.py diff --git a/tests/functional/ext/typing/typing_consider_using_union_without_future.rc b/tests/functional/ext/typing/consider_using_union_without_future.rc similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union_without_future.rc rename to tests/functional/ext/typing/consider_using_union_without_future.rc diff --git a/tests/functional/ext/typing/typing_consider_using_union_without_future.txt b/tests/functional/ext/typing/consider_using_union_without_future.txt similarity index 100% rename from tests/functional/ext/typing/typing_consider_using_union_without_future.txt rename to tests/functional/ext/typing/consider_using_union_without_future.txt diff --git a/tests/functional/ext/typing/typing_deprecated_alias.py b/tests/functional/ext/typing/deprecated_alias.py similarity index 100% rename from tests/functional/ext/typing/typing_deprecated_alias.py rename to tests/functional/ext/typing/deprecated_alias.py diff --git a/tests/functional/ext/typing/typing_deprecated_alias.rc b/tests/functional/ext/typing/deprecated_alias.rc similarity index 100% rename from tests/functional/ext/typing/typing_deprecated_alias.rc rename to tests/functional/ext/typing/deprecated_alias.rc diff --git a/tests/functional/ext/typing/typing_deprecated_alias.txt b/tests/functional/ext/typing/deprecated_alias.txt similarity index 100% rename from tests/functional/ext/typing/typing_deprecated_alias.txt rename to tests/functional/ext/typing/deprecated_alias.txt diff --git a/tests/functional/ext/while_used.py b/tests/functional/ext/while_used/while_used.py similarity index 100% rename from tests/functional/ext/while_used.py rename to 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 similarity index 100% rename from tests/functional/ext/while_used.rc rename to 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 similarity index 100% rename from tests/functional/ext/while_used.txt rename to tests/functional/ext/while_used/while_used.txt diff --git a/tests/functional/m/misplaced_comparison_constant.rc b/tests/functional/m/misplaced_comparison_constant.rc deleted file mode 100644 index abe6b9f27c..0000000000 --- a/tests/functional/m/misplaced_comparison_constant.rc +++ /dev/null @@ -1,3 +0,0 @@ -[MASTER] -load-plugins= - pylint.extensions.comparison_placement,