Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(git): add a test for handling blank with path in git commit #1044

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}'."
)