Skip to content

Commit e848587

Browse files
DranaxelAdrianDC
authored andcommitted
test(commit_command): testing '--allow-empty' flag for cz commit
Signed-off-by: Adrian DC <[email protected]>
1 parent c4dae52 commit e848587

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: tests/commands/test_commit_command.py

+24
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,30 @@ def test_commit_when_nothing_to_commit(config, mocker: MockFixture):
324324
assert "No files added to staging!" in str(excinfo.value)
325325

326326

327+
@pytest.mark.usefixtures("staging_is_clean")
328+
def test_commit_with_allow_empty(config, mocker: MockFixture):
329+
prompt_mock = mocker.patch("questionary.prompt")
330+
prompt_mock.return_value = {
331+
"prefix": "feat",
332+
"subject": "user created",
333+
"scope": "",
334+
"is_breaking_change": False,
335+
"body": "closes #21",
336+
"footer": "",
337+
}
338+
339+
commit_mock = mocker.patch("commitizen.git.commit")
340+
commit_mock.return_value = cmd.Command("success", "", b"", b"", 0)
341+
success_mock = mocker.patch("commitizen.out.success")
342+
343+
commands.Commit(config, {"allow_empty": True})()
344+
345+
commit_mock.assert_called_with(
346+
"feat: user created\n\ncloses #21", args="--allow-empty"
347+
)
348+
success_mock.assert_called_once()
349+
350+
327351
@pytest.mark.usefixtures("staging_is_clean")
328352
def test_commit_when_customized_expected_raised(config, mocker: MockFixture, capsys):
329353
_err = ValueError()

Diff for: tests/commands/test_commit_command/test_commit_command_shows_description_when_use_help_option.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
usage: cz commit [-h] [--retry] [--no-retry] [--dry-run]
22
[--write-message-to-file FILE_PATH] [-s] [-a]
3-
[-l MESSAGE_LENGTH_LIMIT]
3+
[-l MESSAGE_LENGTH_LIMIT] [--allow-empty]
44

55
create new commit
66

@@ -18,3 +18,4 @@ options:
1818
not told Git about are not affected.
1919
-l, --message-length-limit MESSAGE_LENGTH_LIMIT
2020
length limit of the commit message; 0 for no limit
21+
--allow-empty Allow to create a commit without staging changes

0 commit comments

Comments
 (0)