Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a7b3228

Browse files
saygoxLee-W
authored andcommitted
test(commands/commit): add a test for is_blank_commit_file
1 parent e13b4f9 commit a7b3228

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

‎commitizen/commands/commit.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def manual_edit(self, message: str) -> str:
9797
def is_blank_commit_file(self, filename) -> bool:
9898
if not exists(filename):
9999
return True
100-
with open(filename, "tr") as f:
101-
for x in f:
100+
with open(filename) as f:
101+
for x in f.readlines():
102102
if len(x) == 0 or x[0] == "#":
103103
continue
104104
elif x[0] != "\r" and x[0] != "\n":

‎tests/commands/test_commit_command.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ def test_commit_from_pre_commit_msg_hook(config, mocker, capsys):
541541
"footer": "",
542542
}
543543

544+
is_blank_commit_file_mock = mocker.patch(
545+
"commitizen.commands.commit.Commit.is_blank_commit_file"
546+
)
547+
is_blank_commit_file_mock.return_value = True
548+
544549
commit_mock = mocker.patch("commitizen.git.commit")
545550
commit_mock.return_value = cmd.Command("success", "", "", "", 0)
546551

@@ -554,3 +559,52 @@ def test_commit_from_pre_commit_msg_hook(config, mocker, capsys):
554559
out, _ = capsys.readouterr()
555560
assert "Commit message is successful!" in out
556561
commit_mock.assert_not_called()
562+
563+
564+
def test_commit_with_msg_from_pre_commit_msg_hook(config, mocker, capsys):
565+
testargs = ["cz", "commit", "--commit-msg-file", "some_file"]
566+
mocker.patch.object(sys, "argv", testargs)
567+
568+
prompt_mock = mocker.patch("questionary.prompt")
569+
prompt_mock.return_value = {
570+
"prefix": "feat",
571+
"subject": "user created",
572+
"scope": "",
573+
"is_breaking_change": False,
574+
"body": "",
575+
"footer": "",
576+
}
577+
578+
is_blank_commit_file_mock = mocker.patch(
579+
"commitizen.commands.commit.Commit.is_blank_commit_file"
580+
)
581+
is_blank_commit_file_mock.return_value = False
582+
583+
commit_mock = mocker.patch("commitizen.git.commit")
584+
commit_mock.return_value = cmd.Command("success", "", "", "", 0)
585+
586+
cli.main()
587+
588+
prompt_mock.assert_not_called()
589+
commit_mock.assert_not_called()
590+
591+
592+
@pytest.mark.parametrize(
593+
"isexist, commitmsg, returnvalue",
594+
[
595+
[False, "", True],
596+
[True, "\n#test", True],
597+
[True, "test: test\n#test", False],
598+
[True, "#test: test\n#test", True],
599+
],
600+
)
601+
def test_is_blank_commit_file(config, mocker, isexist, commitmsg, returnvalue):
602+
exists_mock = mocker.patch("commitizen.commands.commit.exists")
603+
exists_mock.return_value = isexist
604+
605+
reader_mock = mocker.mock_open(read_data=commitmsg)
606+
mocker.patch("builtins.open", reader_mock)
607+
608+
commit_cmd = commands.Commit(config, {})
609+
ret = commit_cmd.is_blank_commit_file("test")
610+
assert ret == returnvalue

‎tests/wrap_stdio/test_wrap_stdio.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
from commitizen import wrap_stdio
44

5+
6+
def test_import_sub_files():
7+
import commitizen.wrap_stdio.linux # noqa: F401
8+
import commitizen.wrap_stdio.unix # noqa: F401
9+
import commitizen.wrap_stdio.windows # noqa: F401
10+
11+
512
if sys.platform == "win32": # pragma: no cover
613
pass
714
elif sys.platform == "linux":

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /