Skip to content

Commit 7527029

Browse files
committed
Add test for no commit on modification error
A test has been added to the bumpversion library to ensure that no commit and tag is made if there is an error modification. Specifically, the test checks the "do_bump" function and asserts that "mock_commit_and_tag" and "mock_update_config_file" are not called under these conditions.
1 parent ce31778 commit 7527029

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_bump.py

+29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the bump module."""
22

33
from pathlib import Path
4+
import shutil
45
from textwrap import dedent
56
from unittest.mock import MagicMock, patch
67

@@ -125,6 +126,34 @@ def test_passing_new_version_sets_version(self, mock_update_config_file, mock_mo
125126
assert mock_update_config_file.call_args[0][3] == version_config.parse(new_version)
126127
assert mock_update_config_file.call_args[0][5] is dry_run
127128

129+
@patch("bumpversion.bump.commit_and_tag")
130+
@patch("bumpversion.bump.update_config_file")
131+
def test_doesnt_commit_if_modify_error(
132+
self, mock_update_config_file, mock_commit_and_tag, tmp_path: Path, fixtures_path: Path
133+
):
134+
from bumpversion import config
135+
136+
# Arrange
137+
setup_py_path = tmp_path / "setup.py"
138+
setup_py_path.touch()
139+
init_path = tmp_path / "bumpversion/__init__.py"
140+
init_path.parent.mkdir(parents=True)
141+
init_path.touch()
142+
orig_config_path = fixtures_path / "basic_cfg.toml"
143+
dest_config_path = tmp_path / "pyproject.toml"
144+
shutil.copyfile(orig_config_path, dest_config_path)
145+
version_part = "patch"
146+
147+
# Act
148+
with inside_dir(tmp_path):
149+
config = config.get_configuration(config_file=dest_config_path)
150+
bump.do_bump(version_part, None, config)
151+
152+
# Assert
153+
mock_commit_and_tag.assert_not_called()
154+
155+
mock_update_config_file.assert_not_called()
156+
128157
@patch("bumpversion.files.modify_files")
129158
@patch("bumpversion.bump.update_config_file")
130159
def test_when_new_equals_current_nothing_happens(self, mock_update_config_file, mock_modify_files, tmp_path: Path):

0 commit comments

Comments
 (0)