Skip to content

Commit 0d66920

Browse files
committed
test(add-a-test-for-handling-blank-with-path-in-git-commit): add a test for handling blank with path in git commit
issue#572 issue#572
1 parent 8d5f630 commit 0d66920

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_git.py

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import platform
66
import shutil
7+
import subprocess
78

89
import pytest
910
from commitizen import cmd, exceptions, git
@@ -327,3 +328,32 @@ def test_commit_with_spaces_in_path(mocker, file_path, expected_cmd):
327328

328329
mock_run.assert_called_once_with(expected_cmd)
329330
mock_unlink.assert_called_once_with(file_path)
331+
332+
333+
@pytest.mark.parametrize(
334+
"project_subpath",
335+
[
336+
"path/with/no/blanks",
337+
"path/with single/blank",
338+
],
339+
)
340+
def test_git_commit_command_with_varied_paths_handles_blank(
341+
tmp_commitizen_project, tmp_path, project_subpath
342+
):
343+
project_path = os.path.join(str(tmp_path), project_subpath)
344+
os.makedirs(project_path, exist_ok=True)
345+
with tmp_commitizen_project.as_cwd():
346+
message = "fix: path with single blank"
347+
filepath = os.path.join(project_path, "test.txt")
348+
create_file_and_commit(message, filepath)
349+
process = subprocess.Popen(
350+
["git", "log", "-n", "1", "--pretty=format:%s"], stdout=subprocess.PIPE
351+
)
352+
output, _ = process.communicate()
353+
actual_command_message = output.decode("utf-8").strip()
354+
expected_message = f"{message}"
355+
assert actual_command_message == expected_message, (
356+
f"The command's output could not be correctly parsed to match the expected message. "
357+
f"Actual message: '{actual_command_message}', "
358+
f"Expected format: '{expected_message}'."
359+
)

0 commit comments

Comments
 (0)