Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use python-typing-update on half of the tests directory #6317

Merged
merged 6 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/pyreverse/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

from typing import Callable, Optional
from __future__ import annotations

from collections.abc import Callable

import pytest
from astroid.nodes.scoped_nodes import Module
Expand Down Expand Up @@ -65,7 +67,7 @@ def html_config() -> PyreverseConfig:

@pytest.fixture(scope="session")
def get_project() -> Callable:
def _get_project(module: str, name: Optional[str] = "No Name") -> Project:
def _get_project(module: str, name: str | None = "No Name") -> Project:
"""Return an astroid project representation."""

def _astroid_wrapper(func: Callable, modname: str) -> Module:
Expand Down
12 changes: 8 additions & 4 deletions tests/pyreverse/test_diadefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

"""Unit test for the extensions.diadefslib modules."""

# pylint: disable=redefined-outer-name

from __future__ import annotations

import sys
from collections.abc import Callable
from pathlib import Path
from typing import Callable, Dict, List, Tuple

import pytest
from astroid import nodes
Expand All @@ -22,14 +26,14 @@
from pylint.testutils.pyreverse import PyreverseConfig


def _process_classes(classes: List[DiagramEntity]) -> List[Tuple[bool, str]]:
def _process_classes(classes: list[DiagramEntity]) -> list[tuple[bool, str]]:
"""Extract class names of a list."""
return sorted((isinstance(c.node, nodes.ClassDef), c.title) for c in classes)


def _process_relations(
relations: Dict[str, List[Relationship]]
) -> List[Tuple[str, str, str]]:
relations: dict[str, list[Relationship]]
) -> list[tuple[str, str, str]]:
"""Extract relation indices from a relation list."""
result = []
for rel_type, rels in relations.items():
Expand Down
5 changes: 4 additions & 1 deletion tests/pyreverse/test_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

"""Unit test for the diagrams modules."""
from typing import Callable

from __future__ import annotations

from collections.abc import Callable

from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler
from pylint.pyreverse.inspector import Linker
Expand Down
5 changes: 4 additions & 1 deletion tests/pyreverse/test_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

"""For the visitors.diadefs module."""

# pylint: disable=redefined-outer-name

from __future__ import annotations

import os
from typing import Callable
from collections.abc import Callable

import astroid
import pytest
Expand Down
6 changes: 5 additions & 1 deletion tests/pyreverse/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

"""Unittest for the main module."""

from __future__ import annotations

import os
import sys
from typing import Any, Iterator
from collections.abc import Iterator
from typing import Any
from unittest import mock

import pytest
Expand Down
6 changes: 3 additions & 3 deletions tests/pyreverse/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

from typing import Type
from __future__ import annotations

import pytest
from astroid import nodes
Expand All @@ -29,7 +29,7 @@
],
)
def test_explicit_layout(
layout: Layout, printer_class: Type[Printer], expected_content: str, line_index: int
layout: Layout, printer_class: type[Printer], expected_content: str, line_index: int
) -> None:
printer = printer_class(title="unittest", layout=layout)
assert printer.lines[line_index].strip() == expected_content
Expand All @@ -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]):
with pytest.raises(ValueError):
printer_class(title="unittest", layout=layout)

Expand Down
5 changes: 3 additions & 2 deletions tests/pyreverse/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

"""Unit test for ``DiagramWriter``."""

from __future__ import annotations

import codecs
import os
from collections.abc import Callable, Iterator
from difflib import unified_diff
from typing import Callable, Iterator, List
from unittest.mock import Mock

import pytest
Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(self):
setattr(self, attr, value)


def _file_lines(path: str) -> List[str]:
def _file_lines(path: str) -> list[str]:
# we don't care about the actual encoding, but python3 forces us to pick one
with codecs.open(path, encoding="latin1") as stream:
lines = [
Expand Down
11 changes: 6 additions & 5 deletions tests/test_check_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

# pylint: disable=protected-access,missing-function-docstring,no-self-use

from __future__ import annotations

import argparse
import multiprocessing
import os
from typing import List

import dill
import pytest
Expand Down Expand Up @@ -41,7 +42,7 @@ def _gen_file_data(idx: int = 0) -> FileItem:
return file_data


def _gen_file_datas(count: int = 1) -> List[FileItem]:
def _gen_file_datas(count: int = 1) -> list[FileItem]:
return [_gen_file_data(idx) for idx in range(count)]


Expand All @@ -62,7 +63,7 @@ class SequentialTestChecker(BaseChecker):

def __init__(self, linter: PyLinter) -> None:
super().__init__(linter)
self.data: List[str] = []
self.data: list[str] = []
self.linter = linter

def process_module(self, _node: nodes.Module) -> None:
Expand Down Expand Up @@ -101,7 +102,7 @@ class ParallelTestChecker(BaseChecker, MapReduceMixin):

def __init__(self, linter: PyLinter) -> None:
super().__init__(linter)
self.data: List[str] = []
self.data: list[str] = []
self.linter = linter

def open(self) -> None:
Expand All @@ -116,7 +117,7 @@ def close(self) -> None:
def get_map_data(self):
return self.data

def reduce_map_data(self, linter: PyLinter, data: List[List[str]]) -> None:
def reduce_map_data(self, linter: PyLinter, data: list[list[str]]) -> None:
recombined = type(self)(linter)
recombined.open()
aggregated = []
Expand Down
15 changes: 8 additions & 7 deletions tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

"""Functional/non regression tests for pylint."""

from __future__ import annotations

import re
import sys
from os.path import abspath, dirname, join
from typing import List, Optional, Tuple

import pytest

Expand All @@ -29,13 +30,13 @@ def exception_str(self, ex) -> str: # pylint: disable=unused-argument


class LintTestUsingModule:
INPUT_DIR: Optional[str] = None
INPUT_DIR: str | None = None
DEFAULT_PACKAGE = "input"
package = DEFAULT_PACKAGE
linter = linter
module: Optional[str] = None
depends: Optional[List[Tuple[str, str]]] = None
output: Optional[str] = None
module: str | None = None
depends: list[tuple[str, str]] | None = None
output: str | None = None

def _test_functionality(self) -> None:
if self.module:
Expand All @@ -54,7 +55,7 @@ def _check_result(self, got: str) -> None:
)
assert self._get_expected() == got, error_msg

def _test(self, tocheck: List[str]) -> None:
def _test(self, tocheck: list[str]) -> None:
if self.module and INFO_TEST_RGX.match(self.module):
self.linter.enable("I")
else:
Expand Down Expand Up @@ -137,7 +138,7 @@ def test_functionality(


def __test_functionality(
module_file: str, messages_file: str, dependencies: List[Tuple[str, str]]
module_file: str, messages_file: str, dependencies: list[tuple[str, str]]
) -> None:
lint_test = LintTestUpdate() if UPDATE_FILE.exists() else LintTestUsingModule()
lint_test.module = module_file.replace(".py", "")
Expand Down
10 changes: 6 additions & 4 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

"""Functional full-module tests for PyLint."""

from __future__ import annotations

import sys
from pathlib import Path
from typing import Union

import pytest
from _pytest.config import Config
Expand Down Expand Up @@ -46,9 +48,9 @@ def test_functional(
) -> None:
__tracebackhide__ = True # pylint: disable=unused-variable
if UPDATE_FILE.exists():
lint_test: Union[
LintModuleOutputUpdate, testutils.LintModuleTest
] = LintModuleOutputUpdate(test_file, pytestconfig)
lint_test: (
LintModuleOutputUpdate | testutils.LintModuleTest
) = LintModuleOutputUpdate(test_file, pytestconfig)
else:
lint_test = testutils.LintModuleTest(test_file, pytestconfig)
lint_test.setUp()
Expand Down
6 changes: 4 additions & 2 deletions tests/test_import_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

# pylint: disable=redefined-outer-name

from __future__ import annotations

import os
import shutil
from collections.abc import Iterator
from os.path import exists
from typing import Iterator, Union

import pytest
from _pytest.fixtures import SubRequest
Expand All @@ -18,7 +20,7 @@


@pytest.fixture
def dest(request: SubRequest) -> Iterator[Union[Iterator, Iterator[str]]]:
def dest(request: SubRequest) -> Iterator[Iterator | Iterator[str]]:
dest = request.param
yield dest
try:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_pylint_runners.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# 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

# pylint: disable=missing-module-docstring, missing-function-docstring

from __future__ import annotations

import os
import sys
from typing import Callable
from collections.abc import Callable
from unittest.mock import patch

import pytest
Expand Down
12 changes: 8 additions & 4 deletions tests/test_regr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
"""Non regression tests for pylint, which requires a too specific configuration
to be incorporated in the automatic functional test framework
"""

# pylint: disable=redefined-outer-name

from __future__ import annotations

import os
import sys
from collections.abc import Callable, Iterator
from os.path import abspath, dirname, join
from typing import Callable, Iterator, List, cast
from typing import cast

import astroid
import pytest
Expand Down Expand Up @@ -63,7 +67,7 @@ def Equals(expected):
],
)
def test_package(
finalize_linter: PyLinter, file_names: List[str], check: Callable
finalize_linter: PyLinter, file_names: list[str], check: Callable
) -> None:
finalize_linter.check(file_names)
finalize_linter.reporter = cast( # Due to fixture
Expand All @@ -81,7 +85,7 @@ def test_package(
[join(REGR_DATA, "try_finally_disable_msg_crash")],
],
)
def test_crash(finalize_linter: PyLinter, file_names: List[str]) -> None:
def test_crash(finalize_linter: PyLinter, file_names: list[str]) -> None:
finalize_linter.check(file_names)


Expand Down Expand Up @@ -142,5 +146,5 @@ def test_pylint_config_attr() -> None:

@pytest.mark.timeout(30)
@pytest.mark.parametrize("file_names", ([join(REGR_DATA, "hang", "pkg4972.string")],))
def test_hang(finalize_linter: PyLinter, file_names: List[str]) -> None:
def test_hang(finalize_linter: PyLinter, file_names: list[str]) -> None:
finalize_linter.check(file_names)
Loading