summaryrefslogtreecommitdiff
path: root/tests/checkers
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-07-14 22:22:54 +0200
committerGitHub <noreply@github.com>2022-07-14 22:22:54 +0200
commit6417e8cdee987afb773ad5ab9f5f0e82028c7cac (patch)
treee8e770d07deda8ad6db09b85444c058299e25628 /tests/checkers
parentdd5e2c7762294ae91f0e8e850224c14652dd23c6 (diff)
downloadpylint-git-6417e8cdee987afb773ad5ab9f5f0e82028c7cac.tar.gz
[typing] Add typing to the tests directory (#7183)
Diffstat (limited to 'tests/checkers')
-rw-r--r--tests/checkers/__init__.py3
-rw-r--r--tests/checkers/base/unittest_multi_naming_style.py2
-rw-r--r--tests/checkers/unittest_spelling.py54
-rw-r--r--tests/checkers/unittest_stdlib.py8
-rw-r--r--tests/checkers/unittest_unicode/__init__.py2
-rw-r--r--tests/checkers/unittest_unicode/unittest_bad_chars.py6
-rw-r--r--tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py2
-rw-r--r--tests/checkers/unittest_unicode/unittest_invalid_encoding.py2
8 files changed, 38 insertions, 41 deletions
diff --git a/tests/checkers/__init__.py b/tests/checkers/__init__.py
index e8a8ff79f..e69de29bb 100644
--- a/tests/checkers/__init__.py
+++ b/tests/checkers/__init__.py
@@ -1,3 +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
-# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
diff --git a/tests/checkers/base/unittest_multi_naming_style.py b/tests/checkers/base/unittest_multi_naming_style.py
index b9215a1e0..457913149 100644
--- a/tests/checkers/base/unittest_multi_naming_style.py
+++ b/tests/checkers/base/unittest_multi_naming_style.py
@@ -105,7 +105,7 @@ class TestMultiNamingStyle(CheckerTestCase):
function_rgx=MULTI_STYLE_RE,
name_group=("function:method",),
)
- def test_multi_name_detection_group(self):
+ def test_multi_name_detection_group(self) -> None:
function_defs = astroid.extract_node(
"""
class First(object):
diff --git a/tests/checkers/unittest_spelling.py b/tests/checkers/unittest_spelling.py
index 355425596..b07212a19 100644
--- a/tests/checkers/unittest_spelling.py
+++ b/tests/checkers/unittest_spelling.py
@@ -35,13 +35,13 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
reason="missing python-enchant package or missing spelling dictionaries",
)
- def _get_msg_suggestions(self, word, count=4):
+ def _get_msg_suggestions(self, word: str, count: int = 4) -> str:
suggestions = "' or '".join(self.checker.spelling_dict.suggest(word)[:count])
return f"'{suggestions}'"
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_check_bad_coment(self):
+ def test_check_bad_coment(self) -> None:
with self.assertAddsMessages(
MessageTest(
"wrong-spelling-in-comment",
@@ -59,7 +59,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
@set_config(max_spelling_suggestions=2)
- def test_check_bad_comment_custom_suggestion_count(self):
+ def test_check_bad_comment_custom_suggestion_count(self) -> None:
with self.assertAddsMessages(
MessageTest(
"wrong-spelling-in-comment",
@@ -76,7 +76,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_check_bad_docstring(self):
+ def test_check_bad_docstring(self) -> None:
stmt = astroid.extract_node('def fff():\n """bad coment"""\n pass')
with self.assertAddsMessages(
MessageTest(
@@ -109,13 +109,13 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_shebangs(self):
+ def test_skip_shebangs(self) -> None:
self.checker.process_tokens(_tokenize_str("#!/usr/bin/env python"))
assert not self.linter.release_messages()
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_python_coding_comments(self):
+ def test_skip_python_coding_comments(self) -> None:
self.checker.process_tokens(_tokenize_str("# -*- coding: utf-8 -*-"))
assert not self.linter.release_messages()
self.checker.process_tokens(_tokenize_str("# coding=utf-8"))
@@ -138,7 +138,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_top_level_pylint_enable_disable_comments(self):
+ def test_skip_top_level_pylint_enable_disable_comments(self) -> None:
self.checker.process_tokens(
_tokenize_str("# Line 1\n Line 2\n# pylint: disable=ungrouped-imports")
)
@@ -146,13 +146,13 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_words_with_numbers(self):
+ def test_skip_words_with_numbers(self) -> None:
self.checker.process_tokens(_tokenize_str("\n# 0ne\n# Thr33\n# Sh3ll"))
assert not self.linter.release_messages()
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_wiki_words(self):
+ def test_skip_wiki_words(self) -> None:
stmt = astroid.extract_node(
'class ComentAbc(object):\n """ComentAbc with a bad coment"""\n pass'
)
@@ -172,7 +172,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_camel_cased_words(self):
+ def test_skip_camel_cased_words(self) -> None:
stmt = astroid.extract_node(
'class ComentAbc(object):\n """comentAbc with a bad coment"""\n pass'
)
@@ -224,7 +224,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_words_with_underscores(self):
+ def test_skip_words_with_underscores(self) -> None:
stmt = astroid.extract_node(
'def fff(param_name):\n """test param_name"""\n pass'
)
@@ -233,19 +233,19 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_email_address(self):
+ def test_skip_email_address(self) -> None:
self.checker.process_tokens(_tokenize_str("# uname@domain.tld"))
assert not self.linter.release_messages()
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_urls(self):
+ def test_skip_urls(self) -> None:
self.checker.process_tokens(_tokenize_str("# https://github.com/rfk/pyenchant"))
assert not self.linter.release_messages()
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_sphinx_directives(self):
+ def test_skip_sphinx_directives(self) -> None:
stmt = astroid.extract_node(
'class ComentAbc(object):\n """This is :class:`ComentAbc` with a bad coment"""\n pass'
)
@@ -265,7 +265,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_sphinx_directives_2(self):
+ def test_skip_sphinx_directives_2(self) -> None:
stmt = astroid.extract_node(
'class ComentAbc(object):\n """This is :py:attr:`ComentAbc` with a bad coment"""\n pass'
)
@@ -329,7 +329,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_code_flanked_in_double_backticks(self):
+ def test_skip_code_flanked_in_double_backticks(self) -> None:
full_comment = "# The function ``.qsize()`` .qsize()"
with self.assertAddsMessages(
MessageTest(
@@ -347,7 +347,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_code_flanked_in_single_backticks(self):
+ def test_skip_code_flanked_in_single_backticks(self) -> None:
full_comment = "# The function `.qsize()` .qsize()"
with self.assertAddsMessages(
MessageTest(
@@ -365,7 +365,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_skip_mypy_ignore_directives(self):
+ def test_skip_mypy_ignore_directives(self) -> None:
full_comment = "# type: ignore[attr-defined] attr"
with self.assertAddsMessages(
MessageTest(
@@ -404,7 +404,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_handle_words_joined_by_forward_slash(self):
+ def test_handle_words_joined_by_forward_slash(self) -> None:
stmt = astroid.extract_node(
'''
class ComentAbc(object):
@@ -428,7 +428,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_more_than_one_error_in_same_line_for_same_word_on_docstring(self):
+ def test_more_than_one_error_in_same_line_for_same_word_on_docstring(self) -> None:
stmt = astroid.extract_node(
'class ComentAbc(object):\n """Check teh dummy comment teh"""\n pass'
)
@@ -458,7 +458,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_more_than_one_error_in_same_line_for_same_word_on_comment(self):
+ def test_more_than_one_error_in_same_line_for_same_word_on_comment(self) -> None:
with self.assertAddsMessages(
MessageTest(
"wrong-spelling-in-comment",
@@ -485,7 +485,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_docstring_lines_that_look_like_comments_1(self):
+ def test_docstring_lines_that_look_like_comments_1(self) -> None:
stmt = astroid.extract_node(
'''def f():
"""
@@ -508,7 +508,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_docstring_lines_that_look_like_comments_2(self):
+ def test_docstring_lines_that_look_like_comments_2(self) -> None:
stmt = astroid.extract_node(
'''def f():
"""# msitake"""'''
@@ -529,7 +529,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_docstring_lines_that_look_like_comments_3(self):
+ def test_docstring_lines_that_look_like_comments_3(self) -> None:
stmt = astroid.extract_node(
'''def f():
"""
@@ -552,7 +552,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_docstring_lines_that_look_like_comments_4(self):
+ def test_docstring_lines_that_look_like_comments_4(self) -> None:
stmt = astroid.extract_node(
'''def f():
"""
@@ -564,7 +564,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_docstring_lines_that_look_like_comments_5(self):
+ def test_docstring_lines_that_look_like_comments_5(self) -> None:
stmt = astroid.extract_node(
'''def f():
"""
@@ -587,7 +587,7 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
- def test_docstring_lines_that_look_like_comments_6(self):
+ def test_docstring_lines_that_look_like_comments_6(self) -> None:
stmt = astroid.extract_node(
'''def f():
"""
diff --git a/tests/checkers/unittest_stdlib.py b/tests/checkers/unittest_stdlib.py
index f8de2f00d..2f47a4075 100644
--- a/tests/checkers/unittest_stdlib.py
+++ b/tests/checkers/unittest_stdlib.py
@@ -11,7 +11,6 @@ from typing import Any
import astroid
from astroid import nodes
from astroid.manager import AstroidManager
-from astroid.nodes.node_classes import AssignAttr, Name
from pylint.checkers import stdlib
from pylint.testutils import CheckerTestCase
@@ -43,9 +42,10 @@ class TestStdlibChecker(CheckerTestCase):
"""
def infer_func(
- node: Name, context: Any | None = None # pylint: disable=unused-argument
- ) -> Iterator[Iterator | Iterator[AssignAttr]]:
- new_node = nodes.AssignAttr(attrname="alpha", parent=node)
+ inner_node: nodes.Name,
+ context: Any | None = None, # pylint: disable=unused-argument
+ ) -> Iterator[Iterator | Iterator[nodes.AssignAttr]]:
+ new_node = nodes.AssignAttr(attrname="alpha", parent=inner_node)
yield new_node
manager = astroid.MANAGER
diff --git a/tests/checkers/unittest_unicode/__init__.py b/tests/checkers/unittest_unicode/__init__.py
index df1e5bf3d..3f516f032 100644
--- a/tests/checkers/unittest_unicode/__init__.py
+++ b/tests/checkers/unittest_unicode/__init__.py
@@ -82,5 +82,5 @@ class FakeNode:
def __init__(self, content: bytes):
self.content = io.BytesIO(content)
- def stream(self):
+ def stream(self) -> io.BytesIO:
return self.content
diff --git a/tests/checkers/unittest_unicode/unittest_bad_chars.py b/tests/checkers/unittest_unicode/unittest_bad_chars.py
index 7933597f7..41445e226 100644
--- a/tests/checkers/unittest_unicode/unittest_bad_chars.py
+++ b/tests/checkers/unittest_unicode/unittest_bad_chars.py
@@ -29,7 +29,7 @@ def bad_char_file_generator(tmp_path: Path) -> Callable[[str, bool, str], Path]:
The generator also ensures that file generated is correct
"""
- def encode_without_bom(string, encoding):
+ def encode_without_bom(string: str, encoding: str) -> bytes:
return pylint.checkers.unicode._encode_without_bom(string, encoding)
# All lines contain a not extra checked invalid character
@@ -70,7 +70,7 @@ def bad_char_file_generator(tmp_path: Path) -> Callable[[str, bool, str], Path]:
byte_line.decode(codec, "strict")
except UnicodeDecodeError as e:
raise ValueError(
- f"Line {lineno} did raise unexpected error: {byte_line}\n{e}"
+ f"Line {lineno} did raise unexpected error: {byte_line!r}\n{e}"
) from e
else:
try:
@@ -81,7 +81,7 @@ def bad_char_file_generator(tmp_path: Path) -> Callable[[str, bool, str], Path]:
...
else:
raise ValueError(
- f"Line {lineno} did not raise decode error: {byte_line}"
+ f"Line {lineno} did not raise decode error: {byte_line!r}"
)
file = tmp_path / "bad_chars.py"
diff --git a/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py b/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py
index 68134fcc9..c450db211 100644
--- a/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py
+++ b/tests/checkers/unittest_unicode/unittest_bidirectional_unicode.py
@@ -25,7 +25,7 @@ class TestBidirectionalUnicodeChecker(pylint.testutils.CheckerTestCase):
checker: pylint.checkers.unicode.UnicodeChecker
- def test_finds_bidirectional_unicode_that_currently_not_parsed(self):
+ def test_finds_bidirectional_unicode_that_currently_not_parsed(self) -> None:
"""Test an example from https://github.com/nickboucher/trojan-source/tree/main/Python
that is currently not working Python but producing a syntax error
diff --git a/tests/checkers/unittest_unicode/unittest_invalid_encoding.py b/tests/checkers/unittest_unicode/unittest_invalid_encoding.py
index ac12af856..d2807301c 100644
--- a/tests/checkers/unittest_unicode/unittest_invalid_encoding.py
+++ b/tests/checkers/unittest_unicode/unittest_invalid_encoding.py
@@ -130,7 +130,7 @@ class TestInvalidEncoding(pylint.testutils.CheckerTestCase):
"""The codec determined should be exact no matter what we throw at it."""
assert self.checker._determine_codec(io.BytesIO(content)) == (codec, line)
- def test__determine_codec_raises_syntax_error_on_invalid_input(self):
+ def test__determine_codec_raises_syntax_error_on_invalid_input(self) -> None:
"""Invalid input should lead to a SyntaxError."""
with pytest.raises(SyntaxError):
self.checker._determine_codec(io.BytesIO(b"\x80abc"))