|
4 | 4 |
|
5 | 5 | from commitizen import cli, cmd, git
|
6 | 6 | from commitizen.exceptions import (
|
7 |
| - ExpectedExit, |
8 | 7 | CommitFailedError,
|
9 | 8 | CurrentVersionNotFoundError,
|
| 9 | + DryRunExit, |
| 10 | + ExpectedExit, |
10 | 11 | NoCommitsFoundError,
|
11 | 12 | NoPatternMapError,
|
12 | 13 | NoVersionSpecifiedError,
|
@@ -106,19 +107,18 @@ def test_bump_on_git_with_hooks_no_verify_enabled(mocker):
|
106 | 107 |
|
107 | 108 |
|
108 | 109 | 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 | + ) |
113 | 113 |
|
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) |
116 | 116 |
|
117 |
| - with pytest.raises(NoPatternMapError): |
118 |
| - cli.main() |
| 117 | + with pytest.raises(NoPatternMapError): |
| 118 | + cli.main() |
119 | 119 |
|
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 |
122 | 122 |
|
123 | 123 |
|
124 | 124 | @pytest.mark.usefixtures("tmp_git_project")
|
@@ -176,30 +176,44 @@ def test_bump_when_version_inconsistent_in_version_files(
|
176 | 176 |
|
177 | 177 |
|
178 | 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) |
| 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): |
191 | 198 | cli.main()
|
192 |
| - tag_exists = git.tag_exist("0.2.0") |
193 |
| - assert tag_exists is True |
194 | 199 |
|
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() |
200 | 205 |
|
201 |
| - tag_exists = git.tag_exist("0.3.0") |
202 |
| - assert tag_exists is False |
203 | 206 |
|
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