Skip to content

Commit 3ce32fb

Browse files
committed
test(test_git): mock os
1 parent 9528310 commit 3ce32fb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_git.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,27 @@ def test_commit_with_spaces_in_path(mocker, file_path, expected_cmd):
401401

402402
mock_run.assert_called_once_with(expected_cmd)
403403
mock_unlink.assert_called_once_with(file_path)
404+
405+
406+
@pytest.mark.parametrize(
407+
"os_name,committer_date,expected_cmd",
408+
[
409+
(
410+
"nt",
411+
"2024-03-20",
412+
'cmd /v /c "set GIT_COMMITTER_DATE=2024-03-20&& git commit -F "temp.txt""',
413+
),
414+
(
415+
"posix",
416+
"2024-03-20",
417+
'GIT_COMMITTER_DATE=2024-03-20 git commit -F "temp.txt"',
418+
),
419+
("nt", None, 'git commit -F "temp.txt"'),
420+
("posix", None, 'git commit -F "temp.txt"'),
421+
],
422+
)
423+
def test_create_commit_cmd_string(mocker, os_name, committer_date, expected_cmd):
424+
"""Test the OS-specific behavior of _create_commit_cmd_string"""
425+
mocker.patch("os.name", os_name)
426+
result = git._create_commit_cmd_string("", committer_date, "temp.txt")
427+
assert result == expected_cmd

0 commit comments

Comments
 (0)