Skip to content

Commit

Permalink
test(git): add a test for handling blank with path in git commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliying94 committed Mar 30, 2024
1 parent 8d5f630 commit ef51f24
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import platform
import shutil
import subprocess

import pytest
from commitizen import cmd, exceptions, git
Expand Down Expand Up @@ -327,3 +328,32 @@ def test_commit_with_spaces_in_path(mocker, file_path, expected_cmd):

mock_run.assert_called_once_with(expected_cmd)
mock_unlink.assert_called_once_with(file_path)


@pytest.mark.parametrize(
"project_subpath",
[
"path/with/no/blanks",
"path/with single/blank",
],
)
def test_git_commit_command_with_varied_paths_handles_blank(
tmp_commitizen_project, tmp_path, project_subpath
):
project_path = os.path.join(str(tmp_path), project_subpath)
os.makedirs(project_path, exist_ok=True)
with tmp_commitizen_project.as_cwd():
message = "fix: path with single blank"
filepath = os.path.join(project_path, "test.txt")
create_file_and_commit(message, filepath)
process = subprocess.Popen(
["git", "log", "-n", "1", "--pretty=format:%s"], stdout=subprocess.PIPE
)
output, _ = process.communicate()
actual_command_message = output.decode("utf-8").strip()
expected_message = f"{message}"
assert actual_command_message == expected_message, (
f"The command's output could not be correctly parsed to match the expected message. "
f"Actual message: '{actual_command_message}', "
f"Expected format: '{expected_message}'."
)

0 comments on commit ef51f24

Please sign in to comment.