From 293a9a87de3a219b9388cfb514d6d7290ab7388b Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 26 Aug 2024 14:18:18 -0400 Subject: [PATCH] Remove type hints from tests --- .../test_alpha_spec.py | 64 ++++----- .../rapids_pre_commit_hooks/test_copyright.py | 128 +++++++----------- test/rapids_pre_commit_hooks/test_lint.py | 62 ++++----- .../test_pyproject_license.py | 16 +-- test/rapids_pre_commit_hooks/test_shell.py | 4 +- 5 files changed, 118 insertions(+), 156 deletions(-) diff --git a/test/rapids_pre_commit_hooks/test_alpha_spec.py b/test/rapids_pre_commit_hooks/test_alpha_spec.py index 9412004..ce61ff8 100644 --- a/test/rapids_pre_commit_hooks/test_alpha_spec.py +++ b/test/rapids_pre_commit_hooks/test_alpha_spec.py @@ -16,7 +16,6 @@ import os.path from itertools import chain from textwrap import dedent -from typing import Iterator, Optional from unittest.mock import MagicMock, Mock, call, patch import pytest @@ -32,7 +31,7 @@ @contextlib.contextmanager -def set_cwd(cwd: os.PathLike[str]) -> Iterator: +def set_cwd(cwd): old_cwd = os.getcwd() os.chdir(cwd) try: @@ -53,12 +52,8 @@ def set_cwd(cwd: os.PathLike[str]) -> Iterator: ], ) def test_get_rapids_version( - tmp_path: os.PathLike, - version_file: Optional[str], - version_arg: Optional[str], - expected_version: Optional[str], - raises: contextlib.AbstractContextManager, -) -> None: + tmp_path, version_file, version_arg, expected_version, raises +): MOCK_METADATA = RAPIDSMetadata( versions={ "24.06": RAPIDSVersion( @@ -87,11 +82,10 @@ def test_get_rapids_version( assert version == MOCK_METADATA.versions[expected_version] -def test_anchor_preserving_loader() -> None: +def test_anchor_preserving_loader(): loader = alpha_spec.AnchorPreservingLoader("- &a A\n- *a") try: root = loader.get_single_node() - assert root is not None finally: loader.dispose() assert loader.document_anchors == [{"a": root.value[0]}] @@ -129,7 +123,7 @@ def test_anchor_preserving_loader() -> None: "rapids_pre_commit_hooks.alpha_spec.get_rapids_version", Mock(return_value=latest_metadata), ) -def test_strip_cuda_suffix(name: str, stripped_name: str) -> None: +def test_strip_cuda_suffix(name, stripped_name): assert alpha_spec.strip_cuda_suffix(Mock(), name) == stripped_name @@ -174,14 +168,14 @@ def test_strip_cuda_suffix(name: str, stripped_name: str) -> None: ], ) def test_check_and_mark_anchor( - used_anchors_before: set[str], - node_index: int, - descend: bool, - anchor: Optional[str], - used_anchors_after: set[str], -) -> None: + used_anchors_before, + node_index, + descend, + anchor, + used_anchors_after, +): NODES = [Mock() for _ in range(3)] - ANCHORS: dict[str, yaml.Node] = { + ANCHORS = { "anchor1": NODES[0], "anchor2": NODES[1], } @@ -252,15 +246,12 @@ def test_check_and_mark_anchor( "rapids_pre_commit_hooks.alpha_spec.get_rapids_version", Mock(return_value=latest_metadata), ) -def test_check_package_spec( - package: str, content: str, mode: str, replacement: str -) -> None: +def test_check_package_spec(package, content, mode, replacement): args = Mock(mode=mode) linter = lint.Linter("dependencies.yaml", content) loader = alpha_spec.AnchorPreservingLoader(content) try: composed = loader.get_single_node() - assert composed is not None finally: loader.dispose() alpha_spec.check_package_spec( @@ -284,7 +275,7 @@ def test_check_package_spec( "rapids_pre_commit_hooks.alpha_spec.get_rapids_version", Mock(return_value=latest_metadata), ) -def test_check_package_spec_anchor() -> None: +def test_check_package_spec_anchor(): CONTENT = dedent( """\ - &cudf cudf>=24.04,<24.06 @@ -298,10 +289,9 @@ def test_check_package_spec_anchor() -> None: loader = alpha_spec.AnchorPreservingLoader(CONTENT) try: composed = loader.get_single_node() - assert composed is not None finally: loader.dispose() - used_anchors: set[str] = set() + used_anchors = set() expected_linter = lint.Linter("dependencies.yaml", CONTENT) expected_linter.add_warning( @@ -359,7 +349,7 @@ def test_check_package_spec_anchor() -> None: ), ], ) -def test_check_packages(content: str, indices: list[int], use_anchor: bool) -> None: +def test_check_packages(content, indices, use_anchor): with patch( "rapids_pre_commit_hooks.alpha_spec.check_package_spec", Mock() ) as mock_check_package_spec: @@ -367,7 +357,7 @@ def test_check_packages(content: str, indices: list[int], use_anchor: bool) -> N linter = lint.Linter("dependencies.yaml", content) composed = yaml.compose(content) anchors = {"anchor": composed} - used_anchors: set[str] = set() + used_anchors = set() alpha_spec.check_packages(linter, args, anchors, used_anchors, composed) assert used_anchors == ({"anchor"} if use_anchor else set()) alpha_spec.check_packages(linter, args, anchors, used_anchors, composed) @@ -397,7 +387,7 @@ def test_check_packages(content: str, indices: list[int], use_anchor: bool) -> N ), ], ) -def test_check_common(content: str, indices: list[tuple[int, int]]) -> None: +def test_check_common(content, indices): with patch( "rapids_pre_commit_hooks.alpha_spec.check_packages", Mock() ) as mock_check_packages: @@ -432,7 +422,7 @@ def test_check_common(content: str, indices: list[tuple[int, int]]) -> None: ), ], ) -def test_check_matrices(content: str, indices: list[tuple[int, int]]) -> None: +def test_check_matrices(content, indices): with patch( "rapids_pre_commit_hooks.alpha_spec.check_packages", Mock() ) as mock_check_packages: @@ -478,7 +468,7 @@ def test_check_matrices(content: str, indices: list[tuple[int, int]]) -> None: ), ], ) -def test_check_specific(content: str, indices: list[tuple[int, int]]) -> None: +def test_check_specific(content, indices): with patch( "rapids_pre_commit_hooks.alpha_spec.check_matrices", Mock() ) as mock_check_matrices: @@ -532,10 +522,10 @@ def test_check_specific(content: str, indices: list[tuple[int, int]]) -> None: ], ) def test_check_dependencies( - content: str, - common_indices: list[tuple[int, int]], - specific_indices: list[tuple[int, int]], -) -> None: + content, + common_indices, + specific_indices, +): with patch( "rapids_pre_commit_hooks.alpha_spec.check_common", Mock() ) as mock_check_common, patch( @@ -572,7 +562,7 @@ def test_check_dependencies( ), ], ) -def test_check_root(content: str, indices: list[int]) -> None: +def test_check_root(content, indices): with patch( "rapids_pre_commit_hooks.alpha_spec.check_dependencies", Mock() ) as mock_check_dependencies: @@ -587,7 +577,7 @@ def test_check_root(content: str, indices: list[int]) -> None: ] -def test_check_alpha_spec() -> None: +def test_check_alpha_spec(): CONTENT = "dependencies: []" with patch( "rapids_pre_commit_hooks.alpha_spec.check_root", Mock() @@ -607,7 +597,7 @@ def test_check_alpha_spec() -> None: ) -def test_check_alpha_spec_integration(tmp_path: os.PathLike[str]) -> None: +def test_check_alpha_spec_integration(tmp_path): CONTENT = dedent( """\ dependencies: diff --git a/test/rapids_pre_commit_hooks/test_copyright.py b/test/rapids_pre_commit_hooks/test_copyright.py index ea920f1..340c9cc 100644 --- a/test/rapids_pre_commit_hooks/test_copyright.py +++ b/test/rapids_pre_commit_hooks/test_copyright.py @@ -12,13 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import argparse import datetime import os.path import tempfile -from io import BufferedReader from textwrap import dedent -from typing import Any, Optional, TextIO, Union from unittest.mock import Mock, patch import git @@ -29,7 +26,7 @@ from rapids_pre_commit_hooks.lint import Linter -def test_match_copyright() -> None: +def test_match_copyright(): CONTENT = dedent( r""" Copyright (c) 2024 NVIDIA CORPORATION @@ -70,7 +67,7 @@ def test_match_copyright() -> None: ] -def test_strip_copyright() -> None: +def test_strip_copyright(): CONTENT = dedent( r""" This is a line before the first copyright statement @@ -96,10 +93,8 @@ def test_strip_copyright() -> None: @freeze_time("2024-01-18") -def test_apply_copyright_check() -> None: - def run_apply_copyright_check( - old_content: Optional[str], new_content: str - ) -> Linter: +def test_apply_copyright_check(): + def run_apply_copyright_check(old_content, new_content): linter = Linter("file.txt", new_content) copyright.apply_copyright_check(linter, old_content) return linter @@ -178,7 +173,7 @@ def run_apply_copyright_check( @pytest.fixture -def git_repo(tmp_path: os.PathLike[str]) -> git.Repo: +def git_repo(tmp_path): repo = git.Repo.init(tmp_path) with repo.config_writer() as w: w.set_value("user", "name", "RAPIDS Test Fixtures") @@ -186,9 +181,7 @@ def git_repo(tmp_path: os.PathLike[str]) -> git.Repo: return repo -def test_get_target_branch(git_repo: git.Repo) -> None: - assert git_repo.working_tree_dir is not None - +def test_get_target_branch(git_repo): with patch.dict("os.environ", {}, clear=True): args = Mock(main_branch=None, target_branch=None) @@ -271,16 +264,15 @@ def test_get_target_branch(git_repo: git.Repo) -> None: assert copyright.get_target_branch(git_repo, args) == "master" -def test_get_target_branch_upstream_commit(git_repo: git.Repo) -> None: - def fn(repo: git.Repo, filename: str) -> str: - assert repo.working_tree_dir is not None +def test_get_target_branch_upstream_commit(git_repo): + def fn(repo, filename): return os.path.join(repo.working_tree_dir, filename) - def write_file(repo: git.Repo, filename: str, contents: str): + def write_file(repo, filename, contents): with open(fn(repo, filename), "w") as f: f.write(contents) - def mock_target_branch(branch: Any): + def mock_target_branch(branch): return patch( "rapids_pre_commit_hooks.copyright.get_target_branch", Mock(return_value=branch), @@ -318,7 +310,7 @@ def mock_target_branch(branch: Any): remote_1_branch_1 = remote_repo_1.create_head( "branch-1-renamed", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_1 # type: ignore[misc] + remote_repo_1.head.reference = remote_1_branch_1 remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file1.txt", "File 1 modified") remote_repo_1.index.add(["file1.txt"]) @@ -330,7 +322,7 @@ def mock_target_branch(branch: Any): remote_1_branch_2 = remote_repo_1.create_head( "branch-2", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_2 # type: ignore[misc] + remote_repo_1.head.reference = remote_1_branch_2 remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file2.txt", "File 2 modified") remote_repo_1.index.add(["file2.txt"]) @@ -339,7 +331,7 @@ def mock_target_branch(branch: Any): remote_1_branch_3 = remote_repo_1.create_head( "branch-3", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_3 # type: ignore[misc] + remote_repo_1.head.reference = remote_1_branch_3 remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file3.txt", "File 3 modified") remote_repo_1.index.add(["file3.txt"]) @@ -351,7 +343,7 @@ def mock_target_branch(branch: Any): remote_1_branch_4 = remote_repo_1.create_head( "branch-4", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_4 # type: ignore[misc] + remote_repo_1.head.reference = remote_1_branch_4 remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file4.txt", "File 4 modified") remote_repo_1.index.add(["file4.txt"]) @@ -363,7 +355,7 @@ def mock_target_branch(branch: Any): remote_1_branch_7 = remote_repo_1.create_head( "branch-7", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_7 # type: ignore[misc] + remote_repo_1.head.reference = remote_1_branch_7 remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file7.txt", "File 7 modified") remote_repo_1.index.add(["file7.txt"]) @@ -379,7 +371,7 @@ def mock_target_branch(branch: Any): remote_2_branch_3 = remote_repo_2.create_head( "branch-3", remote_2_master.commit ) - remote_repo_2.head.reference = remote_2_branch_3 # type: ignore[misc] + remote_repo_2.head.reference = remote_2_branch_3 remote_repo_2.head.reset(index=True, working_tree=True) write_file(remote_repo_2, "file3.txt", "File 3 modified") remote_repo_2.index.add(["file3.txt"]) @@ -391,7 +383,7 @@ def mock_target_branch(branch: Any): remote_2_branch_4 = remote_repo_2.create_head( "branch-4", remote_2_master.commit ) - remote_repo_2.head.reference = remote_2_branch_4 # type: ignore[misc] + remote_repo_2.head.reference = remote_2_branch_4 remote_repo_2.head.reset(index=True, working_tree=True) write_file(remote_repo_2, "file4.txt", "File 4 modified") remote_repo_2.index.add(["file4.txt"]) @@ -403,7 +395,7 @@ def mock_target_branch(branch: Any): remote_2_branch_5 = remote_repo_2.create_head( "branch-5", remote_2_master.commit ) - remote_repo_2.head.reference = remote_2_branch_5 # type: ignore[misc] + remote_repo_2.head.reference = remote_2_branch_5 remote_repo_2.head.reset(index=True, working_tree=True) write_file(remote_repo_2, "file5.txt", "File 5 modified") remote_repo_2.index.add(["file5.txt"]) @@ -433,7 +425,7 @@ def mock_target_branch(branch: Any): with branch_1.config_writer() as w: w.set_value("remote", "unconventional/remote/name/1") w.set_value("merge", "branch-1-renamed") - git_repo.head.reference = branch_1 # type: ignore[misc] + git_repo.head.reference = branch_1 git_repo.head.reset(index=True, working_tree=True) git_repo.index.remove("file1.txt", working_tree=True) git_repo.index.commit( @@ -442,7 +434,7 @@ def mock_target_branch(branch: Any): ) branch_6 = git_repo.create_head("branch-6", remote_1.refs["master"]) - git_repo.head.reference = branch_6 # type: ignore[misc] + git_repo.head.reference = branch_6 git_repo.head.reset(index=True, working_tree=True) git_repo.index.remove(["file6.txt"], working_tree=True) git_repo.index.commit("Remove file6.txt") @@ -451,7 +443,7 @@ def mock_target_branch(branch: Any): with branch_7.config_writer() as w: w.set_value("remote", "unconventional/remote/name/1") w.set_value("merge", "branch-7") - git_repo.head.reference = branch_7 # type: ignore[misc] + git_repo.head.reference = branch_7 git_repo.head.reset(index=True, working_tree=True) git_repo.index.remove(["file7.txt"], working_tree=True) git_repo.index.commit( @@ -459,7 +451,7 @@ def mock_target_branch(branch: Any): commit_date=datetime.datetime(2024, 2, 1, tzinfo=datetime.timezone.utc), ) - git_repo.head.reference = main # type: ignore[misc] + git_repo.head.reference = main git_repo.head.reset(index=True, working_tree=True) with mock_target_branch("branch-1"): @@ -517,12 +509,8 @@ def mock_target_branch(branch: Any): ) -def test_get_changed_files(git_repo: git.Repo) -> None: - f: Union[BufferedReader, TextIO] - - assert git_repo.working_tree_dir is not None - - def mock_os_walk(top: Union[str, os.PathLike[str]]): +def test_get_changed_files(git_repo): + def mock_os_walk(top): return patch( "os.walk", Mock( @@ -553,15 +541,14 @@ def mock_os_walk(top: Union[str, os.PathLike[str]]): "subdir1/subdir2/sub.txt": None, } - def fn(filename: str) -> str: - assert git_repo.working_tree_dir is not None + def fn(filename): return os.path.join(git_repo.working_tree_dir, filename) - def write_file(filename: str, contents: str): + def write_file(filename, contents): with open(fn(filename), "w") as f: f.write(contents) - def file_contents(verbed: str) -> str: + def file_contents(verbed): return f"This file will be {verbed}\n" * 100 write_file("untouched.txt", file_contents("untouched")) @@ -614,7 +601,7 @@ def file_contents(verbed: str) -> str: git_repo.index.commit("Remove modified.txt") pr_branch = git_repo.create_head("pr", "HEAD~") - git_repo.head.reference = pr_branch # type: ignore[misc] + git_repo.head.reference = pr_branch git_repo.head.reset(index=True, working_tree=True) write_file("copied_2.txt", file_contents("copied")) @@ -662,7 +649,7 @@ def file_contents(verbed: str) -> str: target_branch = git_repo.heads["master"] merge_base = git_repo.merge_base(target_branch, "HEAD")[0] old_files = { - blob.path: blob # type: ignore[union-attr] + blob.path: blob for blob in merge_base.tree.traverse(lambda b, _: isinstance(b, git.Blob)) } @@ -698,31 +685,24 @@ def file_contents(verbed: str) -> str: if old: with open(fn(new), "rb") as f: new_contents = f.read() - old_contents = old_files[old].data_stream.read() # type: ignore[union-attr] + old_contents = old_files[old].data_stream.read() assert new_contents != old_contents - assert ( - changed_files[new].data_stream.read() # type: ignore[union-attr] - == old_contents - ) + assert changed_files[new].data_stream.read() == old_contents for new, old in superfluous.items(): if old: with open(fn(new), "rb") as f: new_contents = f.read() - old_contents = old_files[old].data_stream.read() # type: ignore[union-attr] + old_contents = old_files[old].data_stream.read() assert new_contents == old_contents - assert ( - changed_files[new].data_stream.read() # type: ignore[union-attr] - == old_contents - ) + assert changed_files[new].data_stream.read() == old_contents -def test_get_changed_files_multiple_merge_bases(git_repo: git.Repo) -> None: - def fn(filename: str) -> str: - assert git_repo.working_tree_dir is not None +def test_get_changed_files_multiple_merge_bases(git_repo): + def fn(filename): return os.path.join(git_repo.working_tree_dir, filename) - def write_file(filename: str, contents: str): + def write_file(filename, contents): with open(fn(filename), "w") as f: f.write(contents) @@ -733,7 +713,7 @@ def write_file(filename: str, contents: str): git_repo.index.commit("Initial commit") branch_1 = git_repo.create_head("branch-1", "master") - git_repo.head.reference = branch_1 # type: ignore[misc] + git_repo.head.reference = branch_1 git_repo.index.reset(index=True, working_tree=True) write_file("file1.txt", "File 1 modified\n") git_repo.index.add("file1.txt") @@ -743,7 +723,7 @@ def write_file(filename: str, contents: str): ) branch_2 = git_repo.create_head("branch-2", "master") - git_repo.head.reference = branch_2 # type: ignore[misc] + git_repo.head.reference = branch_2 git_repo.index.reset(index=True, working_tree=True) write_file("file2.txt", "File 2 modified\n") git_repo.index.add("file2.txt") @@ -753,7 +733,7 @@ def write_file(filename: str, contents: str): ) branch_1_2 = git_repo.create_head("branch-1-2", "master") - git_repo.head.reference = branch_1_2 # type: ignore[misc] + git_repo.head.reference = branch_1_2 git_repo.index.reset(index=True, working_tree=True) write_file("file1.txt", "File 1 modified\n") write_file("file2.txt", "File 2 modified\n") @@ -765,7 +745,7 @@ def write_file(filename: str, contents: str): ) branch_3 = git_repo.create_head("branch-3", "master") - git_repo.head.reference = branch_3 # type: ignore[misc] + git_repo.head.reference = branch_3 git_repo.index.reset(index=True, working_tree=True) write_file("file1.txt", "File 1 modified\n") write_file("file2.txt", "File 2 modified\n") @@ -797,7 +777,7 @@ def write_file(filename: str, contents: str): } -def test_normalize_git_filename() -> None: +def test_normalize_git_filename(): assert copyright.normalize_git_filename("file.txt") == "file.txt" assert copyright.normalize_git_filename("sub/file.txt") == "sub/file.txt" assert copyright.normalize_git_filename("sub//file.txt") == "sub/file.txt" @@ -825,9 +805,7 @@ def test_normalize_git_filename() -> None: ("nonexistent/sub.txt", False), ], ) -def test_find_blob(git_repo: git.Repo, path: str, present: bool) -> None: - assert git_repo.working_tree_dir is not None - +def test_find_blob(git_repo, path, present): with open(os.path.join(git_repo.working_tree_dir, "top.txt"), "w"): pass os.mkdir(os.path.join(git_repo.working_tree_dir, "sub1")) @@ -839,23 +817,21 @@ def test_find_blob(git_repo: git.Repo, path: str, present: bool) -> None: blob = copyright.find_blob(git_repo.head.commit.tree, path) if present: - assert blob is not None assert blob.path == path else: assert blob is None @freeze_time("2024-01-18") -def test_check_copyright(git_repo: git.Repo) -> None: - def fn(filename: str) -> str: - assert git_repo.working_tree_dir is not None +def test_check_copyright(git_repo): + def fn(filename): return os.path.join(git_repo.working_tree_dir, filename) - def write_file(filename: str, contents: str): + def write_file(filename, contents): with open(fn(filename), "w") as f: f.write(contents) - def file_contents(num: int) -> str: + def file_contents(num): return dedent( rf"""\ Copyright (c) 2021-2023 NVIDIA CORPORATION @@ -863,7 +839,7 @@ def file_contents(num: int) -> str: """ ) - def file_contents_modified(num: int) -> str: + def file_contents_modified(num): return dedent( rf"""\ Copyright (c) 2021-2023 NVIDIA CORPORATION @@ -879,21 +855,21 @@ def file_contents_modified(num: int) -> str: git_repo.index.commit("Initial commit") branch_1 = git_repo.create_head("branch-1", "master") - git_repo.head.reference = branch_1 # type: ignore[misc] + git_repo.head.reference = branch_1 git_repo.head.reset(index=True, working_tree=True) write_file("file1.txt", file_contents_modified(1)) git_repo.index.add(["file1.txt"]) git_repo.index.commit("Update file1.txt") branch_2 = git_repo.create_head("branch-2", "master") - git_repo.head.reference = branch_2 # type: ignore[misc] + git_repo.head.reference = branch_2 git_repo.head.reset(index=True, working_tree=True) write_file("file2.txt", file_contents_modified(2)) git_repo.index.add(["file2.txt"]) git_repo.index.commit("Update file2.txt") pr = git_repo.create_head("pr", "branch-1") - git_repo.head.reference = pr # type: ignore[misc] + git_repo.head.reference = pr git_repo.head.reset(index=True, working_tree=True) write_file("file3.txt", file_contents_modified(3)) git_repo.index.add(["file3.txt"]) @@ -909,8 +885,8 @@ def file_contents_modified(num: int) -> str: def mock_repo_cwd(): return patch("os.getcwd", Mock(return_value=git_repo.working_tree_dir)) - def mock_target_branch_upstream_commit(target_branch: str): - def func(repo: git.Repo, args: argparse.Namespace) -> git.Commit: + def mock_target_branch_upstream_commit(target_branch): + def func(repo, args): assert target_branch == args.target_branch return repo.heads[target_branch].commit diff --git a/test/rapids_pre_commit_hooks/test_lint.py b/test/rapids_pre_commit_hooks/test_lint.py index 53687a6..285b5c4 100644 --- a/test/rapids_pre_commit_hooks/test_lint.py +++ b/test/rapids_pre_commit_hooks/test_lint.py @@ -12,11 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import argparse import contextlib import os.path from textwrap import dedent -from typing import BinaryIO, Generator, TextIO from unittest.mock import Mock, call, patch import pytest @@ -30,12 +28,12 @@ class TestLinter: - LONG_CONTENTS: str = ( + LONG_CONTENTS = ( "line 1\nline 2\rline 3\r\nline 4\r\n\nline 6\r\n\r\nline 8\n\r\n" "line 10\r\r\nline 12\r\n\rline 14\n\nline 16\r\rline 18\n\rline 20" ) - def test_lines(self) -> None: + def test_lines(self): linter = Linter("test.txt", self.LONG_CONTENTS) assert linter.lines == [ (0, 6), @@ -108,16 +106,16 @@ def test_lines(self) -> None: ) def test_line_for_pos( self, - contents: str, - pos: int, - line: int, - raises: contextlib.AbstractContextManager, - ) -> None: + contents, + pos, + line, + raises, + ): linter = Linter("test.txt", contents) with raises: assert linter.line_for_pos(pos) == line - def test_fix(self) -> None: + def test_fix(self): linter = Linter("test.txt", "Hello world!") assert linter.fix() == "Hello world!" @@ -143,7 +141,7 @@ def test_fix(self) -> None: class TestLintMain: @pytest.fixture - def hello_world_file(self, tmp_path: str) -> Generator[TextIO, None, None]: + def hello_world_file(self, tmp_path): with open(os.path.join(tmp_path, "hello_world.txt"), "w+") as f: f.write("Hello world!") f.flush() @@ -151,7 +149,7 @@ def hello_world_file(self, tmp_path: str) -> Generator[TextIO, None, None]: yield f @pytest.fixture - def hello_file(self, tmp_path: str) -> Generator[TextIO, None, None]: + def hello_file(self, tmp_path): with open(os.path.join(tmp_path, "hello.txt"), "w+") as f: f.write("Hello!") f.flush() @@ -159,7 +157,7 @@ def hello_file(self, tmp_path: str) -> Generator[TextIO, None, None]: yield f @pytest.fixture - def binary_file(self, tmp_path: str) -> Generator[BinaryIO, None, None]: + def binary_file(self, tmp_path): with open(os.path.join(tmp_path, "binary.bin"), "wb+") as f: f.write(b"\xDE\xAD\xBE\xEF") f.flush() @@ -167,7 +165,7 @@ def binary_file(self, tmp_path: str) -> Generator[BinaryIO, None, None]: yield f @pytest.fixture - def long_file(self, tmp_path: str) -> Generator[TextIO, None, None]: + def long_file(self, tmp_path): with open(os.path.join(tmp_path, "long.txt"), "w+") as f: f.write("This is a long file\nIt has multiple lines\n") f.flush() @@ -175,7 +173,7 @@ def long_file(self, tmp_path: str) -> Generator[TextIO, None, None]: yield f @pytest.fixture - def bracket_file(self, tmp_path: str) -> Generator[TextIO, None, None]: + def bracket_file(self, tmp_path): with open(os.path.join(tmp_path, "file[with]brackets.txt"), "w+") as f: f.write("This [file] [has] [brackets]\n") f.flush() @@ -183,14 +181,14 @@ def bracket_file(self, tmp_path: str) -> Generator[TextIO, None, None]: yield f @contextlib.contextmanager - def mock_console(self) -> Generator[Mock, None, None]: + def mock_console(self): m = Mock() with patch("rich.console.Console", m), patch( "rapids_pre_commit_hooks.lint.Console", m ): yield m - def the_check(self, linter: Linter, args: argparse.Namespace) -> None: + def the_check(self, linter, args): assert args.check_test linter.add_warning((0, 5), "say good bye instead").add_replacement( (0, 5), "Good bye" @@ -198,25 +196,25 @@ def the_check(self, linter: Linter, args: argparse.Namespace) -> None: if linter.content[5] != "!": linter.add_warning((5, 5), "use punctuation").add_replacement((5, 5), ",") - def long_file_check(self, linter: Linter, args: argparse.Namespace) -> None: + def long_file_check(self, linter, args): linter.add_warning((0, len(linter.content)), "this is a long file") - def long_fix_check(self, linter: Linter, args: argparse.Namespace) -> None: + def long_fix_check(self, linter, args): linter.add_warning((0, 19), "this is a long line").add_replacement( (0, 19), "This is a long file\nIt's even longer now" ) - def long_delete_fix_check(self, linter: Linter, args: argparse.Namespace) -> None: + def long_delete_fix_check(self, linter, args): linter.add_warning( (0, len(linter.content)), "this is a long file" ).add_replacement((0, len(linter.content)), "This is a short file now") - def bracket_check(self, linter: Linter, args: argparse.Namespace) -> None: + def bracket_check(self, linter, args): linter.add_warning((0, 28), "this [file] has brackets").add_replacement( (12, 17), "[has more]" ) - def test_no_warnings_no_fix(self, hello_world_file: TextIO) -> None: + def test_no_warnings_no_fix(self, hello_world_file): with patch( "sys.argv", ["check-test", "--check-test", hello_world_file.name] ), self.mock_console() as console: @@ -229,7 +227,7 @@ def test_no_warnings_no_fix(self, hello_world_file: TextIO) -> None: call(highlight=False), ] - def test_no_warnings_fix(self, hello_world_file: TextIO) -> None: + def test_no_warnings_fix(self, hello_world_file): with patch( "sys.argv", ["check-test", "--check-test", "--fix", hello_world_file.name] ), self.mock_console() as console: @@ -242,7 +240,7 @@ def test_no_warnings_fix(self, hello_world_file: TextIO) -> None: call(highlight=False), ] - def test_warnings_no_fix(self, hello_world_file: TextIO) -> None: + def test_warnings_no_fix(self, hello_world_file): with patch( "sys.argv", ["check-test", "--check-test", hello_world_file.name] ), self.mock_console() as console, pytest.raises(SystemExit, match=r"^1$"): @@ -273,7 +271,7 @@ def test_warnings_no_fix(self, hello_world_file: TextIO) -> None: call().print(), ] - def test_warnings_fix(self, hello_world_file: TextIO) -> None: + def test_warnings_fix(self, hello_world_file): with patch( "sys.argv", ["check-test", "--check-test", "--fix", hello_world_file.name] ), self.mock_console() as console, pytest.raises(SystemExit, match=r"^1$"): @@ -304,7 +302,7 @@ def test_warnings_fix(self, hello_world_file: TextIO) -> None: call().print(), ] - def test_multiple_files(self, hello_world_file: TextIO, hello_file: TextIO) -> None: + def test_multiple_files(self, hello_world_file, hello_file): with patch( "sys.argv", [ @@ -353,7 +351,7 @@ def test_multiple_files(self, hello_world_file: TextIO, hello_file: TextIO) -> N call().print(), ] - def test_binary_file(self, binary_file: BinaryIO) -> None: + def test_binary_file(self, binary_file): mock_linter = Mock(wraps=Linter) with patch( "sys.argv", @@ -373,7 +371,7 @@ def test_binary_file(self, binary_file: BinaryIO) -> None: ctx.add_check(self.the_check) mock_linter.assert_not_called() - def test_long_file(self, long_file: TextIO) -> None: + def test_long_file(self, long_file): with patch( "sys.argv", [ @@ -411,7 +409,7 @@ def test_long_file(self, long_file: TextIO) -> None: call().print(), ] - def test_long_file_delete(self, long_file: TextIO) -> None: + def test_long_file_delete(self, long_file): with patch( "sys.argv", [ @@ -444,7 +442,7 @@ def test_long_file_delete(self, long_file: TextIO) -> None: call().print(), ] - def test_long_file_fix(self, long_file: TextIO) -> None: + def test_long_file_fix(self, long_file): with patch( "sys.argv", [ @@ -483,7 +481,7 @@ def test_long_file_fix(self, long_file: TextIO) -> None: call().print(), ] - def test_long_file_delete_fix(self, long_file: TextIO) -> None: + def test_long_file_delete_fix(self, long_file): with patch( "sys.argv", [ @@ -511,7 +509,7 @@ def test_long_file_delete_fix(self, long_file: TextIO) -> None: call().print(), ] - def test_bracket_file(self, bracket_file: TextIO) -> None: + def test_bracket_file(self, bracket_file): with patch( "sys.argv", [ diff --git a/test/rapids_pre_commit_hooks/test_pyproject_license.py b/test/rapids_pre_commit_hooks/test_pyproject_license.py index fa24ac9..195224e 100644 --- a/test/rapids_pre_commit_hooks/test_pyproject_license.py +++ b/test/rapids_pre_commit_hooks/test_pyproject_license.py @@ -21,8 +21,6 @@ from rapids_pre_commit_hooks import pyproject_license from rapids_pre_commit_hooks.lint import Linter -_LocType = tuple[int, int] - @pytest.mark.parametrize( ["key", "append", "loc"], @@ -54,7 +52,7 @@ ), ], ) -def test_find_value_location(key: tuple[str, ...], append: bool, loc: _LocType) -> None: +def test_find_value_location(key, append, loc): CONTENT = dedent( """\ [table] @@ -182,12 +180,12 @@ def test_find_value_location(key: tuple[str, ...], append: bool, loc: _LocType) ], ) def test_check_pyproject_license( - document: str, - loc: _LocType, - message: str, - replacement_loc: _LocType, - replacement_text: str, -) -> None: + document, + loc, + message, + replacement_loc, + replacement_text, +): linter = Linter("pyproject.toml", document) pyproject_license.check_pyproject_license(linter, Mock()) diff --git a/test/rapids_pre_commit_hooks/test_shell.py b/test/rapids_pre_commit_hooks/test_shell.py index 50dbec3..f5ddbf2 100644 --- a/test/rapids_pre_commit_hooks/test_shell.py +++ b/test/rapids_pre_commit_hooks/test_shell.py @@ -18,7 +18,7 @@ from rapids_pre_commit_hooks.shell.verify_conda_yes import VerifyCondaYesVisitor -def run_shell_linter(content: str, cls: type) -> Linter: +def run_shell_linter(content, cls): linter = Linter("test.sh", content) visitor = cls(linter, None) parts = bashlex.parse(content) @@ -27,7 +27,7 @@ def run_shell_linter(content: str, cls: type) -> Linter: return linter -def test_verify_conda_yes() -> None: +def test_verify_conda_yes(): CONTENT = r""" conda install -y pkg1 conda install --yes pkg2 pkg3