Skip to content

Commit

Permalink
Remove more type hints from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Aug 26, 2024
1 parent 293a9a8 commit 21ca4e0
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions test/test_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import subprocess
import sys
from functools import cache
from typing import Generator, Optional, Union

import git
import pytest
import yaml
from packaging.version import Version
from rapids_metadata.metadata import RAPIDSMetadata
from rapids_metadata.remote import fetch_latest

REPO_DIR = os.path.join(os.path.dirname(__file__), "..")
Expand All @@ -35,12 +33,12 @@


@cache
def all_metadata() -> RAPIDSMetadata:
def all_metadata():
return fetch_latest()


@contextlib.contextmanager
def set_cwd(cwd: Union[str, os.PathLike[str]]) -> Generator:
def set_cwd(cwd):
old_cwd = os.getcwd()
os.chdir(cwd)
try:
Expand All @@ -50,20 +48,16 @@ def set_cwd(cwd: Union[str, os.PathLike[str]]) -> Generator:


@pytest.fixture
def git_repo(tmp_path: 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")
w.set_value("user", "email", "[email protected]")
return repo


def run_pre_commit(
git_repo: git.Repo, hook_name: str, expected_status: str, exc: Optional[type]
) -> None:
assert git_repo.working_tree_dir is not None

def list_files(top: str) -> Generator[str, None, None]:
def run_pre_commit(git_repo, hook_name, expected_status, exc):
def list_files(top):
for dirpath, _, filenames in os.walk(top):
for filename in filenames:
yield filename if top == dirpath else os.path.join(
Expand Down Expand Up @@ -110,13 +104,13 @@ def list_files(top: str) -> Generator[str, None, None]:
"hook_name",
ALL_HOOKS,
)
def test_pre_commit_pass(git_repo: git.Repo, hook_name: str) -> None:
def test_pre_commit_pass(git_repo, hook_name):
run_pre_commit(git_repo, hook_name, "pass", None)


@pytest.mark.parametrize(
"hook_name",
ALL_HOOKS,
)
def test_pre_commit_fail(git_repo: git.Repo, hook_name: str) -> None:
def test_pre_commit_fail(git_repo, hook_name):
run_pre_commit(git_repo, hook_name, "fail", subprocess.CalledProcessError)

0 comments on commit 21ca4e0

Please sign in to comment.