|
4 | 4 | import os
|
5 | 5 | import platform
|
6 | 6 | import shutil
|
| 7 | +import subprocess |
7 | 8 |
|
8 | 9 | import pytest
|
9 | 10 | from commitizen import cmd, exceptions, git
|
@@ -327,3 +328,32 @@ def test_commit_with_spaces_in_path(mocker, file_path, expected_cmd):
|
327 | 328 |
|
328 | 329 | mock_run.assert_called_once_with(expected_cmd)
|
329 | 330 | 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