Skip to content

Commit

Permalink
Review feedback, mock
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Jan 16, 2025
1 parent f63090e commit 6ba5f88
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/rapids_pre_commit_hooks/codeowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ def check_codeowners(linter: Linter, args: argparse.Namespace) -> None:
check_codeowners_line(linter, args, codeowners_line, found_files)

new_text = ""
for required_codeowners in REQUIRED_CODEOWNERS_LINES:
if required_codeowners.file not in found_files:
for required_codeowners_line in REQUIRED_CODEOWNERS_LINES:
if required_codeowners_line.file not in found_files:
new_text += (
f"{required_codeowners.file} "
f"{required_codeowners_line.file} "
f"""{' '.join(owner(project_prefix=args.project_prefix)
for owner in required_codeowners.owners)}\n"""
for owner in required_codeowners_line.owners)}\n"""
)
if new_text:
if linter.content and not linter.content.endswith("\n"):
Expand Down
27 changes: 26 additions & 1 deletion test/rapids_pre_commit_hooks/test_codeowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,32 @@
# limitations under the License.

from textwrap import dedent
from unittest.mock import Mock
from unittest.mock import Mock, patch

import pytest

from rapids_pre_commit_hooks import codeowners
from rapids_pre_commit_hooks.lint import Linter, LintWarning, Replacement

patch_required_codeowners_lines = patch(
"rapids_pre_commit_hooks.codeowners.REQUIRED_CODEOWNERS_LINES",
[
codeowners.RequiredCodeownersLine(
file="CMakeLists.txt",
owners=[
codeowners.cmake_codeowners,
],
),
codeowners.RequiredCodeownersLine(
file="pyproject.toml",
owners=[
codeowners.hard_coded_codeowners("@rapidsai/ci-codeowners"),
],
allow_extra=True,
),
],
)


@pytest.mark.parametrize(
["line", "skip", "codeowners_line"],
Expand Down Expand Up @@ -169,8 +188,13 @@ def test_parse_codeowners_line(line, skip, codeowners_line):
),
],
),
(
"pyproject.toml @someone-else @rapidsai/ci-codeowners",
[],
),
],
)
@patch_required_codeowners_lines
def test_check_codeowners_line(line, warnings):
codeowners_line = codeowners.parse_codeowners_line(line, 0)
linter = Linter(".github/CODEOWNERS", line)
Expand Down Expand Up @@ -258,6 +282,7 @@ def test_check_codeowners_line(line, warnings):
),
],
)
@patch_required_codeowners_lines
def test_check_codeowners(content, warnings):
linter = Linter(".github/CODEOWNERS", content)
codeowners.check_codeowners(linter, Mock(project_prefix="cudf"))
Expand Down

0 comments on commit 6ba5f88

Please sign in to comment.