Skip to content

Commit

Permalink
test(command): cover 'nothing added' and 'no changes added to commit'
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian DC <[email protected]>
  • Loading branch information
AdrianDC committed Aug 16, 2024
1 parent 81cf342 commit d9ab358
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,60 @@ def test_commit_when_nothing_to_commit(config, mocker: MockFixture):
assert "No files added to staging!" in str(excinfo.value)


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_when_nothing_added_to_commit(config, mocker: MockFixture):
prompt_mock = mocker.patch("questionary.prompt")
prompt_mock.return_value = {
"prefix": "feat",
"subject": "user created",
"scope": "",
"is_breaking_change": False,
"body": "",
"footer": "",
}

commit_mock = mocker.patch("commitizen.git.commit")
commit_mock.return_value = cmd.Command(
"nothing added to commit but untracked files present (use \"git add\" to track)",
"", b"", b"", 0)

error_mock = mocker.patch("commitizen.out.error")

commands.Commit(config, {"all": False})()

prompt_mock.assert_called_once()
error_mock.assert_called_once()

assert "nothing added" in error_mock.call_args[0][0]


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_when_no_changes_added_to_commit(config, mocker: MockFixture):
prompt_mock = mocker.patch("questionary.prompt")
prompt_mock.return_value = {
"prefix": "feat",
"subject": "user created",
"scope": "",
"is_breaking_change": False,
"body": "",
"footer": "",
}

commit_mock = mocker.patch("commitizen.git.commit")
commit_mock.return_value = cmd.Command(
"no changes added to commit (use \"git add\" and/or \"git commit -a\")",
"", b"", b"", 0)

error_mock = mocker.patch("commitizen.out.error")

commands.Commit(config, {"all": False})()

prompt_mock.assert_called_once()
error_mock.assert_called_once()

assert "no changes added to commit" in error_mock.call_args[0][0]


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_when_customized_expected_raised(config, mocker: MockFixture, capsys):
_err = ValueError()
Expand Down

0 comments on commit d9ab358

Please sign in to comment.