Skip to content

Commit

Permalink
s/name/path/
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Aug 27, 2024
1 parent db8e686 commit 151e9d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
13 changes: 8 additions & 5 deletions src/rapids_pre_commit_hooks/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def append_stripped(start: int, item: re.Match):


def add_copy_rename_note(
linter: Linter, warning: LintWarning, change_type: str, old_filename: Optional[str]
linter: Linter,
warning: LintWarning,
change_type: str,
old_filename: Optional[Union[str, os.PathLike[str]]],
):
CHANGE_VERBS = {
"C": "copied",
Expand All @@ -79,7 +82,7 @@ def add_copy_rename_note(
def apply_copyright_revert(
linter: Linter,
change_type: str,
old_filename: Optional[str],
old_filename: Optional[Union[str, os.PathLike[str]]],
old_match: re.Match,
new_match: re.Match,
) -> None:
Expand All @@ -98,7 +101,7 @@ def apply_copyright_revert(
def apply_copyright_update(
linter: Linter,
change_type: str,
old_filename: Optional[str],
old_filename: Optional[Union[str, os.PathLike[str]]],
match: re.Match,
year: int,
) -> None:
Expand All @@ -116,7 +119,7 @@ def apply_copyright_update(
def apply_copyright_check(
linter: Linter,
change_type: str,
old_filename: Optional[str],
old_filename: Optional[Union[str, os.PathLike[str]]],
old_content: Optional[str],
) -> None:
if linter.content != old_content:
Expand Down Expand Up @@ -363,7 +366,7 @@ def the_check(linter: Linter, args: argparse.Namespace):
old_filename = None
old_content = None
else:
old_filename = changed_file.name
old_filename = changed_file.path
old_content = changed_file.data_stream.read().decode()
apply_copyright_check(linter, change_type, old_filename, old_content)

Expand Down
15 changes: 8 additions & 7 deletions test/rapids_pre_commit_hooks/test_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,12 @@ def file_contents_modified(num):
"""
)

os.mkdir(os.path.join(git_repo.working_tree_dir, "dir"))
write_file("file1.txt", file_contents(1))
write_file("file2.txt", file_contents(2))
write_file("dir/file2.txt", file_contents(2))
write_file("file3.txt", file_contents(3))
write_file("file4.txt", file_contents(4))
git_repo.index.add(["file1.txt", "file2.txt", "file3.txt", "file4.txt"])
git_repo.index.add(["file1.txt", "dir/file2.txt", "file3.txt", "file4.txt"])
git_repo.index.commit("Initial commit")

branch_1 = git_repo.create_head("branch-1", "master")
Expand All @@ -1164,8 +1165,8 @@ def file_contents_modified(num):
branch_2 = git_repo.create_head("branch-2", "master")
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"])
write_file("dir/file2.txt", file_contents_modified(2))
git_repo.index.add(["dir/file2.txt"])
git_repo.index.commit("Update file2.txt")

pr = git_repo.create_head("pr", "branch-1")
Expand All @@ -1177,7 +1178,7 @@ def file_contents_modified(num):
write_file("file4.txt", file_contents_modified(4))
git_repo.index.add(["file4.txt"])
git_repo.index.commit("Update file4.txt")
git_repo.index.move(["file2.txt", "file5.txt"])
git_repo.index.move(["dir/file2.txt", "file5.txt"])
git_repo.index.commit("Rename file2.txt to file5.txt")

write_file("file6.txt", file_contents(6))
Expand Down Expand Up @@ -1215,7 +1216,7 @@ def mock_apply_copyright_check():
with mock_apply_copyright_check() as apply_copyright_check:
copyright_checker(linter, mock_args)
apply_copyright_check.assert_called_once_with(
linter, "R", "file2.txt", file_contents(2)
linter, "R", "dir/file2.txt", file_contents(2)
)

linter = Linter("file3.txt", file_contents_modified(3))
Expand Down Expand Up @@ -1274,7 +1275,7 @@ def mock_apply_copyright_check():
with mock_apply_copyright_check() as apply_copyright_check:
copyright_checker(linter, mock_args)
apply_copyright_check.assert_called_once_with(
linter, "R", "file2.txt", file_contents(2)
linter, "R", "dir/file2.txt", file_contents(2)
)

linter = Linter("file3.txt", file_contents_modified(3))
Expand Down

0 comments on commit 151e9d7

Please sign in to comment.