|
4 | 4 |
|
5 | 5 | from commitizen import cli, cmd, git
|
6 | 6 | from commitizen.exceptions import (
|
| 7 | + ExpectedExit, |
7 | 8 | CommitFailedError,
|
8 | 9 | CurrentVersionNotFoundError,
|
9 | 10 | NoCommitsFoundError,
|
@@ -104,12 +105,8 @@ def test_bump_on_git_with_hooks_no_verify_enabled(mocker):
|
104 | 105 | assert tag_exists is True
|
105 | 106 |
|
106 | 107 |
|
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(): |
113 | 110 | create_file_and_commit(
|
114 | 111 | "feat: new user interface\n\nBREAKING CHANGE: age is no longer supported"
|
115 | 112 | )
|
@@ -176,3 +173,33 @@ def test_bump_when_version_inconsistent_in_version_files(
|
176 | 173 | partial_expected_error_message = "Current version 0.1.0 is not found in"
|
177 | 174 | _, err = capsys.readouterr()
|
178 | 175 | 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