|
9 | 9 | from commitizen.cz.utils import get_backup_file_path
|
10 | 10 | from commitizen.exceptions import (
|
11 | 11 | CommitError,
|
| 12 | + CommitMessageLengthExceededError, |
12 | 13 | CustomError,
|
13 | 14 | DryRunExit,
|
14 | 15 | NoAnswersError,
|
@@ -379,3 +380,29 @@ def test_commit_command_with_extra_args(config, mocker: MockFixture):
|
379 | 380 | commands.Commit(config, {"extra_cli_args": "-- -extra-args1 -extra-arg2"})()
|
380 | 381 | commit_mock.assert_called_once_with(ANY, args="-- -extra-args1 -extra-arg2")
|
381 | 382 | success_mock.assert_called_once()
|
| 383 | + |
| 384 | + |
| 385 | +@pytest.mark.usefixtures("staging_is_clean") |
| 386 | +def test_commit_command_with_message_length_limit(config, mocker: MockFixture): |
| 387 | + prompt_mock = mocker.patch("questionary.prompt") |
| 388 | + prefix = "feat" |
| 389 | + subject = "random subject" |
| 390 | + message_length = len(prefix) + len(": ") + len(subject) |
| 391 | + prompt_mock.return_value = { |
| 392 | + "prefix": prefix, |
| 393 | + "subject": subject, |
| 394 | + "scope": "", |
| 395 | + "is_breaking_change": False, |
| 396 | + "body": "random body", |
| 397 | + "footer": "random footer", |
| 398 | + } |
| 399 | + |
| 400 | + commit_mock = mocker.patch("commitizen.git.commit") |
| 401 | + commit_mock.return_value = cmd.Command("success", "", b"", b"", 0) |
| 402 | + success_mock = mocker.patch("commitizen.out.success") |
| 403 | + |
| 404 | + commands.Commit(config, {"message_length_limit": message_length})() |
| 405 | + success_mock.assert_called_once() |
| 406 | + |
| 407 | + with pytest.raises(CommitMessageLengthExceededError): |
| 408 | + commands.Commit(config, {"message_length_limit": message_length - 1})() |
0 commit comments