From 75270290e412dacf8ce30586059f919d0cf53838 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Tue, 25 Jun 2024 11:07:24 -0500 Subject: [PATCH 1/3] 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. --- tests/test_bump.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_bump.py b/tests/test_bump.py index ad187249..ece1bdb7 100644 --- a/tests/test_bump.py +++ b/tests/test_bump.py @@ -1,6 +1,7 @@ """Tests for the bump module.""" from pathlib import Path +import shutil from textwrap import dedent from unittest.mock import MagicMock, patch @@ -125,6 +126,34 @@ def test_passing_new_version_sets_version(self, mock_update_config_file, mock_mo assert mock_update_config_file.call_args[0][3] == version_config.parse(new_version) assert mock_update_config_file.call_args[0][5] is dry_run + @patch("bumpversion.bump.commit_and_tag") + @patch("bumpversion.bump.update_config_file") + def test_doesnt_commit_if_modify_error( + self, mock_update_config_file, mock_commit_and_tag, tmp_path: Path, fixtures_path: Path + ): + from bumpversion import config + + # Arrange + setup_py_path = tmp_path / "setup.py" + setup_py_path.touch() + init_path = tmp_path / "bumpversion/__init__.py" + init_path.parent.mkdir(parents=True) + init_path.touch() + orig_config_path = fixtures_path / "basic_cfg.toml" + dest_config_path = tmp_path / "pyproject.toml" + shutil.copyfile(orig_config_path, dest_config_path) + version_part = "patch" + + # Act + with inside_dir(tmp_path): + config = config.get_configuration(config_file=dest_config_path) + bump.do_bump(version_part, None, config) + + # Assert + mock_commit_and_tag.assert_not_called() + + mock_update_config_file.assert_not_called() + @patch("bumpversion.files.modify_files") @patch("bumpversion.bump.update_config_file") def test_when_new_equals_current_nothing_happens(self, mock_update_config_file, mock_modify_files, tmp_path: Path): From 8f72f868045d5f715e11404ed82455c8d5de6eca Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Tue, 25 Jun 2024 11:07:44 -0500 Subject: [PATCH 2/3] Improve error message for SCM command failures The error message for failures in the SCM command execution has been enhanced. Now it displays not only the command's return code but also the standard output and error, improving the debugging process. --- bumpversion/scm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bumpversion/scm.py b/bumpversion/scm.py index f518e3e4..9ffb23f1 100644 --- a/bumpversion/scm.py +++ b/bumpversion/scm.py @@ -76,7 +76,8 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args if isinstance(exc, TypeError): err_msg = f"Failed to run {cls._COMMIT_COMMAND}: {exc}" else: - err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}" + output = "\n".join([x for x in [exc.stdout, exc.stderr] if x]) + err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {output}" logger.exception(err_msg) raise BumpVersionError(err_msg) from exc finally: From cb050a87ae26421024025010a38d9e9a0cdd6f44 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Tue, 25 Jun 2024 11:11:59 -0500 Subject: [PATCH 3/3] Add VersionNotFoundError test in test_bump.py The code in test_bump.py file has been modified to include a test for VersionNotFoundError exception. This ensures that the implementation properly handles cases where a specified version could not be found. --- tests/test_bump.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_bump.py b/tests/test_bump.py index ece1bdb7..f61f6179 100644 --- a/tests/test_bump.py +++ b/tests/test_bump.py @@ -8,7 +8,7 @@ import pytest from bumpversion import bump -from bumpversion.exceptions import ConfigurationError +from bumpversion.exceptions import ConfigurationError, VersionNotFoundError from bumpversion.files import ConfiguredFile from bumpversion.scm import Git, SCMInfo from tests.conftest import get_config_data, inside_dir @@ -147,7 +147,8 @@ def test_doesnt_commit_if_modify_error( # Act with inside_dir(tmp_path): config = config.get_configuration(config_file=dest_config_path) - bump.do_bump(version_part, None, config) + with pytest.raises(VersionNotFoundError): + bump.do_bump(version_part, None, config) # Assert mock_commit_and_tag.assert_not_called()