Skip to content

Commit 87e2327

Browse files
yuukidachLee-W
authored andcommitted
test(check): add test of checking commit message with comment in it
1 parent 9ccabe5 commit 87e2327

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

commitizen/commands/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _get_commits(self):
9595
return git.get_commits(end=self.rev_range)
9696

9797
def _filter_comments(self, msg: str) -> str:
98-
lines = [line for line in msg.split('\n') if not line.startswith('#')]
98+
lines = [line for line in msg.split("\n") if not line.startswith("#")]
9999
return "\n".join(lines)
100100

101101
@staticmethod

tests/commands/test_check_command.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,23 @@ def test_check_command_with_pipe_message_and_failed(mocker):
275275
with pytest.raises(InvalidCommitMessageError) as excinfo:
276276
cli.main()
277277
assert "commit validation: failed!" in str(excinfo.value)
278+
279+
280+
def test_check_command_with_comment_in_messege_file(mocker, capsys):
281+
testargs = ["cz", "check", "--commit-msg-file", "some_file"]
282+
mocker.patch.object(sys, "argv", testargs)
283+
mocker.patch(
284+
"commitizen.commands.check.open",
285+
mocker.mock_open(
286+
read_data="# <type>: (If applied, this commit will...) <subject>\n"
287+
"# |<---- Try to Limit to a Max of 50 char ---->|\n"
288+
"ci: add commitizen pre-commit hook\n"
289+
"\n"
290+
"# Explain why this change is being made\n"
291+
"# |<---- Try To Limit Each Line to a Max Of 72 Char ---->|\n"
292+
"This pre-commit hook will check our commits automatically."
293+
),
294+
)
295+
cli.main()
296+
out, _ = capsys.readouterr()
297+
assert "Commit validation: successful!" in out

0 commit comments

Comments
 (0)