Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed regression in config update. #110

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bumpversion/config/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def update_config_file(
search=config.search,
replace=config.replace,
regex=config.regex,
ignore_missing_version=config.ignore_missing_version,
ignore_missing_version=True,
serialize=config.serialize,
parse=config.parse,
)
Expand Down
68 changes: 68 additions & 0 deletions tests/test_bump.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for the bump module."""
from pathlib import Path
from textwrap import dedent
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -186,3 +187,70 @@ def test_commit_and_tag_with_config_file(mock_context):
config.scm_info.tool.commit_to_scm.assert_called_once()
config.scm_info.tool.tag_in_scm.assert_called_once()
assert set(config.scm_info.tool.commit_to_scm.call_args[0][0]) == {"foo.txt", "bar.txt", "pyproject.toml"}


def test_key_path_required_for_toml_change(tmp_path: Path, caplog):
"""If the key_path is not provided, the toml file should use standard search and replace."""
from bumpversion import config
from bumpversion.version_part import VersionConfig

# Arrange
config_path = tmp_path / "pyproject.toml"
config_path.write_text(
dedent(
"""
[project]
version = "0.1.26"
[tool.bumpversion]
current_version = "0.1.26"
allow_dirty = true
commit = true
[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = "version = \\"{current_version}\\""
replace = "version = \\"{new_version}\\""
"""
)
)

conf = config.get_configuration(config_file=config_path)

# Act
from click.testing import CliRunner, Result
from bumpversion import cli

runner: CliRunner = CliRunner()
with inside_dir(tmp_path):
result: Result = runner.invoke(
cli.cli,
["bump", "-vv", "minor"],
)

if result.exit_code != 0:
print(caplog.text)
print("Here is the output:")
print(result.output)
import traceback

print(traceback.print_exception(result.exc_info[1]))

# Assert
assert result.exit_code == 0
assert config_path.read_text() == dedent(
"""
[project]
version = "0.2.0"
[tool.bumpversion]
current_version = "0.2.0"
allow_dirty = true
commit = true
[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = "version = \\"{current_version}\\""
replace = "version = \\"{new_version}\\""
"""
)
Loading