Skip to content

Commit fb2b60c

Browse files
committed
test: add missing tests for get_filenames_in_commit with git_reference
Add test coverage for get_filenames_in_commit() when called with an explicit git_reference parameter. Previously only the error case and the integration test (no git_reference) existed. New tests: - test_get_filenames_in_commit: success case without git_reference - test_get_filenames_in_commit_with_git_reference: success case with explicit reference, verifying the correct git command is called - test_get_filenames_in_commit_error_with_git_reference: error case with explicit reference Closes #1860 Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com>
1 parent 7543ca6 commit fb2b60c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_git.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,21 @@ def test_commit_with_spaces_in_path(
387387
mock_unlink.assert_called_once_with(file_path)
388388

389389

390+
def test_get_filenames_in_commit(util: UtilFixture):
391+
"""Test getting filenames from the last commit (default, no git_reference)."""
392+
util.mock_cmd(out="file1.py\nfile2.py\n")
393+
result = git.get_filenames_in_commit()
394+
assert result == ["file1.py", "file2.py"]
395+
396+
397+
def test_get_filenames_in_commit_with_git_reference(util: UtilFixture):
398+
"""Test getting filenames with an explicit git reference."""
399+
mock = util.mock_cmd(out="src/main.py\nREADME.md\n")
400+
result = git.get_filenames_in_commit("HEAD~1")
401+
assert result == ["src/main.py", "README.md"]
402+
mock.assert_called_once_with("git show --name-only --pretty=format: HEAD~1")
403+
404+
390405
def test_get_filenames_in_commit_error(util: UtilFixture):
391406
"""Test that GitCommandError is raised when git command fails."""
392407
util.mock_cmd(err="fatal: bad object HEAD", return_code=1)
@@ -395,6 +410,17 @@ def test_get_filenames_in_commit_error(util: UtilFixture):
395410
assert str(excinfo.value) == "fatal: bad object HEAD"
396411

397412

413+
def test_get_filenames_in_commit_error_with_git_reference(util: UtilFixture):
414+
"""Test that GitCommandError is raised with an explicit git reference."""
415+
mock = util.mock_cmd(
416+
err="fatal: bad object abc123", return_code=128
417+
)
418+
with pytest.raises(GitCommandError) as excinfo:
419+
git.get_filenames_in_commit("abc123")
420+
assert str(excinfo.value) == "fatal: bad object abc123"
421+
mock.assert_called_once_with("git show --name-only --pretty=format: abc123")
422+
423+
398424
@pytest.mark.parametrize(
399425
"linebreak", ["\n", "\r\n"], ids=["line_feed", "carriage_return"]
400426
)

0 commit comments

Comments
 (0)