Skip to content

Commit 67db626

Browse files
committed
test(message_length_limit): validate negative message_length_limit
1 parent e626291 commit 67db626

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/commands/test_check_command.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,29 @@ def test_check_command_cli_overrides_config_message_length_limit(
392392
success_mock.assert_called_once()
393393

394394

395+
def test_check_command_with_negative_cli_message_length_limit_raises(config):
396+
with pytest.raises(InvalidCommandArgumentError):
397+
commands.Check(
398+
config=config,
399+
arguments={
400+
"message": "fix(scope): some commit message",
401+
"message_length_limit": -1,
402+
},
403+
)
404+
405+
406+
def test_check_command_with_negative_config_message_length_limit_raises(config):
407+
config.settings["message_length_limit"] = -1
408+
with pytest.raises(InvalidCommandArgumentError):
409+
commands.Check(
410+
config=config,
411+
arguments={
412+
"message": "fix(scope): some commit message",
413+
"message_length_limit": None,
414+
},
415+
)
416+
417+
395418
class ValidationCz(BaseCommitizen):
396419
def questions(self) -> list[CzQuestion]:
397420
return [

tests/commands/test_commit_command.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CommitMessageLengthExceededError,
1313
CustomError,
1414
DryRunExit,
15+
InvalidCommandArgumentError,
1516
NoAnswersError,
1617
NoCommitBackupError,
1718
NotAGitProjectError,
@@ -403,3 +404,14 @@ def test_commit_message_length_cli_zero_disables_limit(
403404
)
404405
commands.Commit(config, {"message_length_limit": 0})()
405406
success_mock.assert_called_once()
407+
408+
409+
def test_commit_message_length_cli_negative_raises(config):
410+
with pytest.raises(InvalidCommandArgumentError):
411+
commands.Commit(config, {"message_length_limit": -1})
412+
413+
414+
def test_commit_message_length_config_negative_raises_when_cli_unset(config):
415+
config.settings["message_length_limit"] = -1
416+
with pytest.raises(InvalidCommandArgumentError):
417+
commands.Commit(config, {"message_length_limit": None})

0 commit comments

Comments
 (0)