Skip to content

Commit 0842d37

Browse files
committed
test(test_git): mock os
1 parent 3dba422 commit 0842d37

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
@@ -449,3 +449,27 @@ def test_git_commit_from_rev_and_commit():
449449
assert commit.author == "John Doe"
450450
assert commit.author_email == "john@example.com"
451451
assert commit.parents == []
452+
453+
454+
@pytest.mark.parametrize(
455+
"os_name,committer_date,expected_cmd",
456+
[
457+
(
458+
"nt",
459+
"2024-03-20",
460+
'cmd /v /c "set GIT_COMMITTER_DATE=2024-03-20&& git commit -F "temp.txt""',
461+
),
462+
(
463+
"posix",
464+
"2024-03-20",
465+
'GIT_COMMITTER_DATE=2024-03-20 git commit -F "temp.txt"',
466+
),
467+
("nt", None, 'git commit -F "temp.txt"'),
468+
("posix", None, 'git commit -F "temp.txt"'),
469+
],
470+
)
471+
def test_create_commit_cmd_string(mocker, os_name, committer_date, expected_cmd):
472+
"""Test the OS-specific behavior of _create_commit_cmd_string"""
473+
mocker.patch("os.name", os_name)
474+
result = git._create_commit_cmd_string("", committer_date, "temp.txt")
475+
assert result == expected_cmd

0 commit comments

Comments
 (0)