diff options
Diffstat (limited to 'tests/checkers')
24 files changed, 78 insertions, 107 deletions
diff --git a/tests/checkers/base/unittest_base.py b/tests/checkers/base/unittest_base.py index 99a8f659e..8e432bffb 100644 --- a/tests/checkers/base/unittest_base.py +++ b/tests/checkers/base/unittest_base.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Unittest for the base checker.""" diff --git a/tests/checkers/base/unittest_multi_naming_style.py b/tests/checkers/base/unittest_multi_naming_style.py index 457913149..5e17e6411 100644 --- a/tests/checkers/base/unittest_multi_naming_style.py +++ b/tests/checkers/base/unittest_multi_naming_style.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Unittest for the NameChecker.""" diff --git a/tests/checkers/base/unittest_name_preset.py b/tests/checkers/base/unittest_name_preset.py index 49a81deff..412e2ee8e 100644 --- a/tests/checkers/base/unittest_name_preset.py +++ b/tests/checkers/base/unittest_name_preset.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Unittest for the NameChecker.""" diff --git a/tests/checkers/conftest.py b/tests/checkers/conftest.py index ac2a187d4..c91a97198 100644 --- a/tests/checkers/conftest.py +++ b/tests/checkers/conftest.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from pathlib import Path diff --git a/tests/checkers/unittest_base_checker.py b/tests/checkers/unittest_base_checker.py index 81a9c73d0..4c4b6d563 100644 --- a/tests/checkers/unittest_base_checker.py +++ b/tests/checkers/unittest_base_checker.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Unittest for the BaseChecker class.""" @@ -132,16 +132,5 @@ def test_base_checker_ordering() -> None: def test_base_checker_invalid_message() -> None: linter = PyLinter() - with pytest.raises(InvalidMessageError): linter.register_checker(MissingFieldsChecker(linter)) - - -def test_get_message_definition() -> None: - checker = LessBasicChecker() - with pytest.warns(DeprecationWarning): - with pytest.raises(InvalidMessageError): - checker.get_message_definition("W123") - - with pytest.warns(DeprecationWarning): - assert checker.get_message_definition("W0001") diff --git a/tests/checkers/unittest_deprecated.py b/tests/checkers/unittest_deprecated.py index d34150247..a9efaa505 100644 --- a/tests/checkers/unittest_deprecated.py +++ b/tests/checkers/unittest_deprecated.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations diff --git a/tests/checkers/unittest_design.py b/tests/checkers/unittest_design.py index f2ea09d2d..379fee559 100644 --- a/tests/checkers/unittest_design.py +++ b/tests/checkers/unittest_design.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt import astroid diff --git a/tests/checkers/unittest_format.py b/tests/checkers/unittest_format.py index fd0699daa..dfaf037b9 100644 --- a/tests/checkers/unittest_format.py +++ b/tests/checkers/unittest_format.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Check format checker helper functions.""" @@ -148,9 +148,10 @@ class TestCheckSpace(CheckerTestCase): encoding_token = tokenize.TokenInfo( tokenize.ENCODING, "utf-8", (0, 0), (0, 0), "" ) - tokens = [encoding_token] + _tokenize_str( - "if (\n None):\n pass\n" - ) + tokens = [ + encoding_token, + *_tokenize_str("if (\n None):\n pass\n"), + ] self.checker.process_tokens(tokens) diff --git a/tests/checkers/unittest_imports.py b/tests/checkers/unittest_imports.py index d454c8161..4a8d6e553 100644 --- a/tests/checkers/unittest_imports.py +++ b/tests/checkers/unittest_imports.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Unit tests for the imports checker.""" diff --git a/tests/checkers/unittest_misc.py b/tests/checkers/unittest_misc.py index e360d3bb6..2f292b81f 100644 --- a/tests/checkers/unittest_misc.py +++ b/tests/checkers/unittest_misc.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Tests for the misc checker.""" diff --git a/tests/checkers/unittest_non_ascii_name.py b/tests/checkers/unittest_non_ascii_name.py index 4f854dddc..0741a9fb0 100644 --- a/tests/checkers/unittest_non_ascii_name.py +++ b/tests/checkers/unittest_non_ascii_name.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations diff --git a/tests/checkers/unittest_refactoring.py b/tests/checkers/unittest_refactoring.py index d40e0eb92..30b1dce2e 100644 --- a/tests/checkers/unittest_refactoring.py +++ b/tests/checkers/unittest_refactoring.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt import os diff --git a/tests/checkers/unittest_similar.py b/tests/checkers/unittest_similar.py index c0f0cdcbf..f5bfc6fb2 100644 --- a/tests/checkers/unittest_similar.py +++ b/tests/checkers/unittest_similar.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from contextlib import redirect_stdout from io import StringIO diff --git a/tests/checkers/unittest_spelling.py b/tests/checkers/unittest_spelling.py index b02cf73a8..08c1fa051 100644 --- a/tests/checkers/unittest_spelling.py +++ b/tests/checkers/unittest_spelling.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Unittest for the spelling checker.""" diff --git a/tests/checkers/unittest_stdlib.py b/tests/checkers/unittest_stdlib.py index 66747deb9..df0bcfd51 100644 --- a/tests/checkers/unittest_stdlib.py +++ b/tests/checkers/unittest_stdlib.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations @@ -48,7 +48,14 @@ class TestStdlibChecker(CheckerTestCase): inner_node: nodes.Name, context: InferenceContext | None = None, # pylint: disable=unused-argument ) -> Iterator[nodes.AssignAttr]: - new_node = nodes.AssignAttr(attrname="alpha", parent=inner_node) + new_node = nodes.AssignAttr( + attrname="alpha", + parent=inner_node, + lineno=0, + col_offset=0, + end_lineno=0, + end_col_offset=0, + ) yield new_node manager = astroid.MANAGER diff --git a/tests/checkers/unittest_strings.py b/tests/checkers/unittest_strings.py index 7927dcc49..6c93e0865 100644 --- a/tests/checkers/unittest_strings.py +++ b/tests/checkers/unittest_strings.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from pylint.checkers import strings diff --git a/tests/checkers/unittest_typecheck.py b/tests/checkers/unittest_typecheck.py index dba69eaf3..c944b863f 100644 --- a/tests/checkers/unittest_typecheck.py +++ b/tests/checkers/unittest_typecheck.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt import astroid import pytest diff --git a/tests/checkers/unittest_unicode/__init__.py b/tests/checkers/unittest_unicode/__init__.py index 3f516f032..bb7a14a70 100644 --- a/tests/checkers/unittest_unicode/__init__.py +++ b/tests/checkers/unittest_unicode/__init__.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt import io from pathlib import Path diff --git a/tests/checkers/unittest_unicode/unittest_bad_chars.py b/tests/checkers/unittest_unicode/unittest_bad_chars.py index 7746ce4ae..e5cdcfe04 100644 --- a/tests/checkers/unittest_unicode/unittest_bad_chars.py +++ b/tests/checkers/unittest_unicode/unittest_bad_chars.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt # pylint: disable=redefined-outer-name diff --git a/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py b/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py index 6b11dcfef..95b2b4602 100644 --- a/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py +++ b/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt import itertools import unicodedata diff --git a/tests/checkers/unittest_unicode/unittest_functions.py b/tests/checkers/unittest_unicode/unittest_functions.py index 0c809ccdc..09401fd64 100644 --- a/tests/checkers/unittest_unicode/unittest_functions.py +++ b/tests/checkers/unittest_unicode/unittest_functions.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations diff --git a/tests/checkers/unittest_unicode/unittest_invalid_encoding.py b/tests/checkers/unittest_unicode/unittest_invalid_encoding.py index e8695a74f..34e344281 100644 --- a/tests/checkers/unittest_unicode/unittest_invalid_encoding.py +++ b/tests/checkers/unittest_unicode/unittest_invalid_encoding.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations diff --git a/tests/checkers/unittest_utils.py b/tests/checkers/unittest_utils.py index ac328d7cd..9d90d4c01 100644 --- a/tests/checkers/unittest_utils.py +++ b/tests/checkers/unittest_utils.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Tests for the pylint.checkers.utils module.""" @@ -11,7 +11,6 @@ import pytest from astroid import nodes from pylint.checkers import utils -from pylint.checkers.base_checker import BaseChecker @pytest.mark.parametrize( @@ -414,7 +413,6 @@ def test_if_sys_guard() -> None: assert utils.is_sys_guard(code[2]) is False -@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_if_typing_guard() -> None: code = astroid.extract_node( """ @@ -422,30 +420,30 @@ def test_if_typing_guard() -> None: import typing as t from typing import TYPE_CHECKING - if typing.TYPE_CHECKING: #@ - pass + if typing.TYPE_CHECKING: + pass #@ - if t.TYPE_CHECKING: #@ - pass + if t.TYPE_CHECKING: + pass #@ - if TYPE_CHECKING: #@ - pass + if TYPE_CHECKING: + pass #@ - if typing.SOME_OTHER_CONST: #@ - pass + if typing.SOME_OTHER_CONST: + pass #@ """ ) assert isinstance(code, list) and len(code) == 4 - assert isinstance(code[0], nodes.If) - assert utils.is_typing_guard(code[0]) is True - assert isinstance(code[1], nodes.If) - assert utils.is_typing_guard(code[1]) is True - assert isinstance(code[2], nodes.If) - assert utils.is_typing_guard(code[2]) is True + assert isinstance(code[0], nodes.Pass) + assert utils.in_type_checking_block(code[0]) is True + assert isinstance(code[1], nodes.Pass) + assert utils.in_type_checking_block(code[1]) is True + assert isinstance(code[2], nodes.Pass) + assert utils.in_type_checking_block(code[2]) is True - assert isinstance(code[3], nodes.If) - assert utils.is_typing_guard(code[3]) is False + assert isinstance(code[3], nodes.Pass) + assert utils.in_type_checking_block(code[3]) is False def test_in_type_checking_block() -> None: @@ -480,30 +478,6 @@ def test_is_empty_literal() -> None: assert not utils.is_empty_str_literal(not_empty_string_node.value) -def test_deprecation_is_inside_lambda() -> None: - """Test that is_inside_lambda is throwing a DeprecationWarning.""" - with pytest.warns(DeprecationWarning) as records: - utils.is_inside_lambda(nodes.NodeNG()) - assert len(records) == 1 - - -def test_deprecation_check_messages() -> None: - with pytest.warns(DeprecationWarning) as records: - - class Checker(BaseChecker): # pylint: disable=unused-variable - @utils.check_messages("my-message") - def visit_assname(self, node: nodes.NodeNG) -> None: - pass - - deprecationMessage = ( - "utils.check_messages will be removed in " - "favour of calling utils.only_required_for_messages in pylint 3.0" - ) - - assert len(records) == 1 - assert records[0].message.args[0] == deprecationMessage - - def test_is_typing_member() -> None: code = astroid.extract_node( """ diff --git a/tests/checkers/unittest_variables.py b/tests/checkers/unittest_variables.py index e3f013226..858873a36 100644 --- a/tests/checkers/unittest_variables.py +++ b/tests/checkers/unittest_variables.py @@ -1,6 +1,6 @@ # 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 -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt import os import re @@ -151,7 +151,7 @@ class TestVariablesCheckerWithTearDown(CheckerTestCase): # Undefined-method in class def # Issue 1824 - # https://github.com/PyCQA/pylint/issues/1824 + # https://github.com/pylint-dev/pylint/issues/1824 node = astroid.parse( """ class MyObject(object): @@ -166,7 +166,7 @@ class TestVariablesCheckerWithTearDown(CheckerTestCase): """Make sure variables from parent lambdas aren't noted as undefined - https://github.com/PyCQA/pylint/issues/760 + https://github.com/pylint-dev/pylint/issues/760 """ node = astroid.parse( """ |