Skip to content

Commit 016fba7

Browse files
committed
test(bump): add test case for --files-only option
1 parent 68b7d69 commit 016fba7

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

tests/commands/test_bump_command.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from commitizen import cli, cmd, git
66
from commitizen.exceptions import (
7+
ExpectedExit,
78
CommitFailedError,
89
CurrentVersionNotFoundError,
910
NoCommitsFoundError,
@@ -104,12 +105,8 @@ def test_bump_on_git_with_hooks_no_verify_enabled(mocker):
104105
assert tag_exists is True
105106

106107

107-
def test_bump_when_bumpping_is_not_support(mocker, capsys, tmpdir):
108-
with tmpdir.as_cwd():
109-
with open("./pyproject.toml", "w") as f:
110-
f.write("[tool.commitizen]\n" 'version="0.1.0"')
111-
112-
cmd.run("git init")
108+
def test_bump_when_bumpping_is_not_support(mocker, capsys, tmp_commitizen_project):
109+
with tmp_commitizen_project.as_cwd():
113110
create_file_and_commit(
114111
"feat: new user interface\n\nBREAKING CHANGE: age is no longer supported"
115112
)
@@ -176,3 +173,33 @@ def test_bump_when_version_inconsistent_in_version_files(
176173
partial_expected_error_message = "Current version 0.1.0 is not found in"
177174
_, err = capsys.readouterr()
178175
assert partial_expected_error_message in err
176+
177+
178+
def test_bump_files_only(mocker, tmp_commitizen_project):
179+
with tmp_commitizen_project.as_cwd():
180+
tmp_version_file = tmp_commitizen_project.join("__version__.py")
181+
tmp_version_file.write("0.1.0")
182+
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
183+
tmp_commitizen_cfg_file.write(
184+
f"{tmp_commitizen_cfg_file.read()}\n"
185+
f'version_files = ["{str(tmp_version_file)}"]'
186+
)
187+
188+
create_file_and_commit("feat: new user interface")
189+
testargs = ["cz", "bump", "--yes"]
190+
mocker.patch.object(sys, "argv", testargs)
191+
cli.main()
192+
tag_exists = git.tag_exist("0.2.0")
193+
assert tag_exists is True
194+
195+
create_file_and_commit("feat: another new feature")
196+
testargs = ["cz", "bump", "--yes", "--files-only"]
197+
mocker.patch.object(sys, "argv", testargs)
198+
with pytest.raises(ExpectedExit):
199+
cli.main()
200+
201+
tag_exists = git.tag_exist("0.3.0")
202+
assert tag_exists is False
203+
204+
with open(tmp_version_file, "r") as f:
205+
assert "0.3.0" in f.read()

0 commit comments

Comments
 (0)