Skip to content

Commit ad9d803

Browse files
committed
test(bump): add test case for dry run
1 parent 168c9f0 commit ad9d803

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

tests/commands/test_bump_command.py

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from commitizen import cli, cmd, git
66
from commitizen.exceptions import (
7-
ExpectedExit,
87
CommitFailedError,
98
CurrentVersionNotFoundError,
9+
DryRunExit,
10+
ExpectedExit,
1011
NoCommitsFoundError,
1112
NoPatternMapError,
1213
NoVersionSpecifiedError,
@@ -106,19 +107,18 @@ def test_bump_on_git_with_hooks_no_verify_enabled(mocker):
106107

107108

108109
def test_bump_when_bumpping_is_not_support(mocker, capsys, tmp_commitizen_project):
109-
with tmp_commitizen_project.as_cwd():
110-
create_file_and_commit(
111-
"feat: new user interface\n\nBREAKING CHANGE: age is no longer supported"
112-
)
110+
create_file_and_commit(
111+
"feat: new user interface\n\nBREAKING CHANGE: age is no longer supported"
112+
)
113113

114-
testargs = ["cz", "-n", "cz_jira", "bump", "--yes"]
115-
mocker.patch.object(sys, "argv", testargs)
114+
testargs = ["cz", "-n", "cz_jira", "bump", "--yes"]
115+
mocker.patch.object(sys, "argv", testargs)
116116

117-
with pytest.raises(NoPatternMapError):
118-
cli.main()
117+
with pytest.raises(NoPatternMapError):
118+
cli.main()
119119

120-
_, err = capsys.readouterr()
121-
assert "'cz_jira' rule does not support bump" in err
120+
_, err = capsys.readouterr()
121+
assert "'cz_jira' rule does not support bump" in err
122122

123123

124124
@pytest.mark.usefixtures("tmp_git_project")
@@ -176,30 +176,44 @@ def test_bump_when_version_inconsistent_in_version_files(
176176

177177

178178
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)
179+
tmp_version_file = tmp_commitizen_project.join("__version__.py")
180+
tmp_version_file.write("0.1.0")
181+
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
182+
tmp_commitizen_cfg_file.write(
183+
f"{tmp_commitizen_cfg_file.read()}\n"
184+
f'version_files = ["{str(tmp_version_file)}"]'
185+
)
186+
187+
create_file_and_commit("feat: new user interface")
188+
testargs = ["cz", "bump", "--yes"]
189+
mocker.patch.object(sys, "argv", testargs)
190+
cli.main()
191+
tag_exists = git.tag_exist("0.2.0")
192+
assert tag_exists is True
193+
194+
create_file_and_commit("feat: another new feature")
195+
testargs = ["cz", "bump", "--yes", "--files-only"]
196+
mocker.patch.object(sys, "argv", testargs)
197+
with pytest.raises(ExpectedExit):
191198
cli.main()
192-
tag_exists = git.tag_exist("0.2.0")
193-
assert tag_exists is True
194199

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+
tag_exists = git.tag_exist("0.3.0")
201+
assert tag_exists is False
202+
203+
with open(tmp_version_file, "r") as f:
204+
assert "0.3.0" in f.read()
200205

201-
tag_exists = git.tag_exist("0.3.0")
202-
assert tag_exists is False
203206

204-
with open(tmp_version_file, "r") as f:
205-
assert "0.3.0" in f.read()
207+
def test_bump_dry_run(mocker, capsys, tmp_commitizen_project):
208+
create_file_and_commit("feat: new file")
209+
210+
testargs = ["cz", "bump", "--yes", "--dry-run"]
211+
mocker.patch.object(sys, "argv", testargs)
212+
with pytest.raises(DryRunExit):
213+
cli.main()
214+
215+
out, _ = capsys.readouterr()
216+
assert "0.2.0" in out
217+
218+
tag_exists = git.tag_exist("0.2.0")
219+
assert tag_exists is False

0 commit comments

Comments
 (0)