summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-09-09 12:56:40 +0200
committerGitHub <noreply@github.com>2022-09-09 12:56:40 +0200
commit2b6bd64d43ed109b1ee15f0993c010660cf56b13 (patch)
tree0f8605ed4d6b2dc4d0d176a4761d6fdd6526eb4d /tests
parent6bac42efacdf1c1777db2021ca6ceda89eb8f199 (diff)
downloadpylint-git-2b6bd64d43ed109b1ee15f0993c010660cf56b13.tar.gz
Finish some incomplete typing signatures (#7442)
Diffstat (limited to 'tests')
-rw-r--r--tests/checkers/unittest_unicode/unittest_bad_chars.py4
-rw-r--r--tests/checkers/unittest_unicode/unittest_functions.py18
-rw-r--r--tests/config/test_functional_config_loading.py4
-rw-r--r--tests/extensions/test_private_import.py12
-rw-r--r--tests/lint/test_pylinter.py5
-rw-r--r--tests/pyreverse/test_main.py13
-rw-r--r--tests/pyreverse/test_printer.py2
-rw-r--r--tests/reporters/unittest_reporting.py8
-rw-r--r--tests/test_func.py6
9 files changed, 41 insertions, 31 deletions
diff --git a/tests/checkers/unittest_unicode/unittest_bad_chars.py b/tests/checkers/unittest_unicode/unittest_bad_chars.py
index 08b4c9539..7746ce4ae 100644
--- a/tests/checkers/unittest_unicode/unittest_bad_chars.py
+++ b/tests/checkers/unittest_unicode/unittest_bad_chars.py
@@ -41,7 +41,9 @@ def bad_char_file_generator(tmp_path: Path) -> Callable[[str, bool, str], Path]:
"# Invalid char esc: \x1B",
)
- def _bad_char_file_generator(codec: str, add_invalid_bytes: bool, line_ending: str):
+ def _bad_char_file_generator(
+ codec: str, add_invalid_bytes: bool, line_ending: str
+ ) -> Path:
byte_suffix = b""
if add_invalid_bytes:
if codec == "utf-8":
diff --git a/tests/checkers/unittest_unicode/unittest_functions.py b/tests/checkers/unittest_unicode/unittest_functions.py
index c2fef9357..0c809ccdc 100644
--- a/tests/checkers/unittest_unicode/unittest_functions.py
+++ b/tests/checkers/unittest_unicode/unittest_functions.py
@@ -105,8 +105,10 @@ SEARCH_DICT_BYTE_UTF8 = {
def test_map_positions_to_result(
line: pylint.checkers.unicode._StrLike,
expected: dict[int, pylint.checkers.unicode._BadChar],
- search_dict,
-):
+ search_dict: dict[
+ pylint.checkers.unicode._StrLike, pylint.checkers.unicode._BadChar
+ ],
+) -> None:
"""Test all possible outcomes for map position function in UTF-8 and ASCII."""
if isinstance(line, bytes):
newline = b"\n"
@@ -133,7 +135,7 @@ def test_map_positions_to_result(
pytest.param(b"12345678\n\r", id="wrong_order_byte"),
],
)
-def test_line_length(line: pylint.checkers.unicode._StrLike):
+def test_line_length(line: pylint.checkers.unicode._StrLike) -> None:
assert pylint.checkers.unicode._line_length(line, "utf-8") == 10
@@ -146,7 +148,7 @@ def test_line_length(line: pylint.checkers.unicode._StrLike):
pytest.param("12345678\n\r", id="wrong_order"),
],
)
-def test_line_length_utf16(line: str):
+def test_line_length_utf16(line: str) -> None:
assert pylint.checkers.unicode._line_length(line.encode("utf-16"), "utf-16") == 10
@@ -159,7 +161,7 @@ def test_line_length_utf16(line: str):
pytest.param("12345678\n\r", id="wrong_order"),
],
)
-def test_line_length_utf32(line: str):
+def test_line_length_utf32(line: str) -> None:
assert pylint.checkers.unicode._line_length(line.encode("utf-32"), "utf-32") == 10
@@ -186,7 +188,7 @@ def test_line_length_utf32(line: str):
("ASCII", "ascii"),
],
)
-def test__normalize_codec_name(codec: str, expected: str):
+def test__normalize_codec_name(codec: str, expected: str) -> None:
assert pylint.checkers.unicode._normalize_codec_name(codec) == expected
@@ -216,7 +218,7 @@ def test__normalize_codec_name(codec: str, expected: str):
)
def test___fix_utf16_32_line_stream(
tmp_path: Path, codec: str, line_ending: str, final_new_line: bool
-):
+) -> None:
"""Content of stream should be the same as should be the length."""
def decode_line(line: bytes, codec: str) -> str:
@@ -260,5 +262,5 @@ def test___fix_utf16_32_line_stream(
("ascii", 1),
],
)
-def test__byte_to_str_length(codec: str, expected: int):
+def test__byte_to_str_length(codec: str, expected: int) -> None:
assert pylint.checkers.unicode._byte_to_str_length(codec) == expected
diff --git a/tests/config/test_functional_config_loading.py b/tests/config/test_functional_config_loading.py
index 64227df79..432bdc1a1 100644
--- a/tests/config/test_functional_config_loading.py
+++ b/tests/config/test_functional_config_loading.py
@@ -64,9 +64,9 @@ def test_functional_config_loading(
configuration_path: str,
default_configuration: PylintConfiguration,
file_to_lint_path: str,
- capsys: CaptureFixture,
+ capsys: CaptureFixture[str],
caplog: LogCaptureFixture,
-):
+) -> None:
"""Functional tests for configurations."""
# logging is helpful to see what's expected and why. The output of the
# program is checked during the test so printing messes with the result.
diff --git a/tests/extensions/test_private_import.py b/tests/extensions/test_private_import.py
index d2d79947f..c82f51a42 100644
--- a/tests/extensions/test_private_import.py
+++ b/tests/extensions/test_private_import.py
@@ -4,7 +4,7 @@
"""Tests the local module directory comparison logic which requires mocking file directories"""
-from unittest.mock import patch
+from unittest.mock import MagicMock, patch
import astroid
@@ -19,7 +19,7 @@ class TestPrivateImport(CheckerTestCase):
CHECKER_CLASS = private_import.PrivateImportChecker
@patch("pathlib.Path.parent")
- def test_internal_module(self, parent) -> None:
+ def test_internal_module(self, parent: MagicMock) -> None:
parent.parts = ("", "dir", "module")
import_from = astroid.extract_node("""from module import _file""")
@@ -27,7 +27,7 @@ class TestPrivateImport(CheckerTestCase):
self.checker.visit_importfrom(import_from)
@patch("pathlib.Path.parent")
- def test_external_module_nested(self, parent) -> None:
+ def test_external_module_nested(self, parent: MagicMock) -> None:
parent.parts = ("", "dir", "module", "module_files", "util")
import_from = astroid.extract_node("""from module import _file""")
@@ -36,7 +36,7 @@ class TestPrivateImport(CheckerTestCase):
self.checker.visit_importfrom(import_from)
@patch("pathlib.Path.parent")
- def test_external_module_dot_import(self, parent) -> None:
+ def test_external_module_dot_import(self, parent: MagicMock) -> None:
parent.parts = ("", "dir", "outer", "inner", "module_files", "util")
import_from = astroid.extract_node("""from outer.inner import _file""")
@@ -45,7 +45,7 @@ class TestPrivateImport(CheckerTestCase):
self.checker.visit_importfrom(import_from)
@patch("pathlib.Path.parent")
- def test_external_module_dot_import_outer_only(self, parent) -> None:
+ def test_external_module_dot_import_outer_only(self, parent: MagicMock) -> None:
parent.parts = ("", "dir", "outer", "extensions")
import_from = astroid.extract_node("""from outer.inner import _file""")
@@ -54,7 +54,7 @@ class TestPrivateImport(CheckerTestCase):
self.checker.visit_importfrom(import_from)
@patch("pathlib.Path.parent")
- def test_external_module(self, parent) -> None:
+ def test_external_module(self, parent: MagicMock) -> None:
parent.parts = ("", "dir", "other")
import_from = astroid.extract_node("""from module import _file""")
diff --git a/tests/lint/test_pylinter.py b/tests/lint/test_pylinter.py
index 495e1c5df..5e2f20ff6 100644
--- a/tests/lint/test_pylinter.py
+++ b/tests/lint/test_pylinter.py
@@ -7,6 +7,7 @@ from unittest import mock
from unittest.mock import patch
import pytest
+from _pytest.recwarn import WarningsRecorder
from py._path.local import LocalPath
from pytest import CaptureFixture
@@ -20,7 +21,7 @@ def raise_exception(*args: Any, **kwargs: Any) -> NoReturn:
@patch.object(FileState, "iter_spurious_suppression_messages", raise_exception)
def test_crash_in_file(
- linter: PyLinter, capsys: CaptureFixture, tmpdir: LocalPath
+ linter: PyLinter, capsys: CaptureFixture[str], tmpdir: LocalPath
) -> None:
with pytest.warns(DeprecationWarning):
args = linter.load_command_line_configuration([__file__])
@@ -35,7 +36,7 @@ def test_crash_in_file(
assert any(m.symbol == "fatal" for m in linter.reporter.messages)
-def test_check_deprecation(linter: PyLinter, recwarn):
+def test_check_deprecation(linter: PyLinter, recwarn: WarningsRecorder) -> None:
linter.check("myfile.py")
msg = recwarn.pop()
assert "check function will only accept sequence" in str(msg)
diff --git a/tests/pyreverse/test_main.py b/tests/pyreverse/test_main.py
index 1e09c533f..bb580f4d8 100644
--- a/tests/pyreverse/test_main.py
+++ b/tests/pyreverse/test_main.py
@@ -14,6 +14,7 @@ from unittest import mock
import pytest
from _pytest.capture import CaptureFixture
+from _pytest.fixtures import SubRequest
from pylint.lint import fix_import_path
from pylint.pyreverse import main
@@ -23,13 +24,13 @@ PROJECT_ROOT_DIR = os.path.abspath(os.path.join(TEST_DATA_DIR, ".."))
@pytest.fixture(name="mock_subprocess")
-def mock_utils_subprocess():
+def mock_utils_subprocess() -> Iterator[mock.MagicMock]:
with mock.patch("pylint.pyreverse.utils.subprocess") as mock_subprocess:
yield mock_subprocess
@pytest.fixture
-def mock_graphviz(mock_subprocess):
+def mock_graphviz(mock_subprocess: mock.MagicMock) -> Iterator[None]:
mock_subprocess.run.return_value = mock.Mock(
stderr=(
'Format: "XYZ" not recognized. Use one of: '
@@ -45,7 +46,7 @@ def mock_graphviz(mock_subprocess):
@pytest.fixture(params=[PROJECT_ROOT_DIR, TEST_DATA_DIR])
-def setup_path(request) -> Iterator[None]:
+def setup_path(request: SubRequest) -> Iterator[None]:
current_sys_path = list(sys.path)
sys.path[:] = []
current_dir = os.getcwd()
@@ -68,7 +69,9 @@ def test_project_root_in_sys_path() -> None:
@mock.patch("pylint.pyreverse.main.DiadefsHandler", new=mock.MagicMock())
@mock.patch("pylint.pyreverse.main.writer")
@pytest.mark.usefixtures("mock_graphviz")
-def test_graphviz_supported_image_format(mock_writer, capsys: CaptureFixture) -> None:
+def test_graphviz_supported_image_format(
+ mock_writer: mock.MagicMock, capsys: CaptureFixture[str]
+) -> None:
"""Test that Graphviz is used if the image format is supported."""
with pytest.raises(SystemExit) as wrapped_sysexit:
# we have to catch the SystemExit so the test execution does not stop
@@ -88,7 +91,7 @@ def test_graphviz_supported_image_format(mock_writer, capsys: CaptureFixture) ->
@mock.patch("pylint.pyreverse.main.writer")
@pytest.mark.usefixtures("mock_graphviz")
def test_graphviz_cant_determine_supported_formats(
- mock_writer, mock_subprocess, capsys: CaptureFixture
+ mock_writer: mock.MagicMock, mock_subprocess: mock.MagicMock, capsys: CaptureFixture
) -> None:
"""Test that Graphviz is used if the image format is supported."""
mock_subprocess.run.return_value.stderr = "..."
diff --git a/tests/pyreverse/test_printer.py b/tests/pyreverse/test_printer.py
index d6785940f..4248e8bae 100644
--- a/tests/pyreverse/test_printer.py
+++ b/tests/pyreverse/test_printer.py
@@ -39,7 +39,7 @@ def test_explicit_layout(
"layout, printer_class",
[(Layout.BOTTOM_TO_TOP, PlantUmlPrinter), (Layout.RIGHT_TO_LEFT, PlantUmlPrinter)],
)
-def test_unsupported_layout(layout: Layout, printer_class: type[Printer]):
+def test_unsupported_layout(layout: Layout, printer_class: type[Printer]) -> None:
with pytest.raises(ValueError):
printer_class(title="unittest", layout=layout)
diff --git a/tests/reporters/unittest_reporting.py b/tests/reporters/unittest_reporting.py
index c81590359..ea7d6758b 100644
--- a/tests/reporters/unittest_reporting.py
+++ b/tests/reporters/unittest_reporting.py
@@ -35,7 +35,7 @@ def disable():
return ["I"]
-def test_template_option(linter):
+def test_template_option(linter: PyLinter) -> None:
output = StringIO()
linter.reporter.out = output
linter.config.msg_template = "{msg_id}:{line:03d}"
@@ -46,7 +46,7 @@ def test_template_option(linter):
assert output.getvalue() == "************* Module 0123\nC0301:001\nC0301:002\n"
-def test_template_option_default(linter) -> None:
+def test_template_option_default(linter: PyLinter) -> None:
"""Test the default msg-template setting."""
output = StringIO()
linter.reporter.out = output
@@ -60,7 +60,7 @@ def test_template_option_default(linter) -> None:
assert out_lines[2] == "my_module:2:0: C0301: Line too long (3/4) (line-too-long)"
-def test_template_option_end_line(linter) -> None:
+def test_template_option_end_line(linter: PyLinter) -> None:
"""Test the msg-template option with end_line and end_column."""
output = StringIO()
linter.reporter.out = output
@@ -79,7 +79,7 @@ def test_template_option_end_line(linter) -> None:
assert out_lines[2] == "my_mod:2:0:2:4: C0301: Line too long (3/4) (line-too-long)"
-def test_template_option_non_existing(linter) -> None:
+def test_template_option_non_existing(linter: PyLinter) -> None:
"""Test the msg-template option with non-existent options.
This makes sure that this option remains backwards compatible as new
parameters do not break on previous versions
diff --git a/tests/test_func.py b/tests/test_func.py
index 6fd7585b9..528019692 100644
--- a/tests/test_func.py
+++ b/tests/test_func.py
@@ -25,11 +25,13 @@ FILTER_RGX = None
INFO_TEST_RGX = re.compile(r"^func_i\d\d\d\d$")
-def exception_str(self, ex) -> str: # pylint: disable=unused-argument
+def exception_str(
+ self: Exception, ex: Exception # pylint: disable=unused-argument
+) -> str:
"""Function used to replace default __str__ method of exception instances
This function is not typed because it is legacy code
"""
- return f"in {ex.file}\n:: {', '.join(ex.args)}"
+ return f"in {ex.file}\n:: {', '.join(ex.args)}" # type: ignore[attr-defined] # Defined in the caller
class LintTestUsingModule: