|
1 | 1 | """Tests for the bump module."""
|
2 | 2 | from pathlib import Path
|
| 3 | +from textwrap import dedent |
3 | 4 | from unittest.mock import MagicMock, patch
|
4 | 5 |
|
5 | 6 | import pytest
|
@@ -186,3 +187,70 @@ def test_commit_and_tag_with_config_file(mock_context):
|
186 | 187 | config.scm_info.tool.commit_to_scm.assert_called_once()
|
187 | 188 | config.scm_info.tool.tag_in_scm.assert_called_once()
|
188 | 189 | assert set(config.scm_info.tool.commit_to_scm.call_args[0][0]) == {"foo.txt", "bar.txt", "pyproject.toml"}
|
| 190 | + |
| 191 | + |
| 192 | +def test_key_path_required_for_toml_change(tmp_path: Path, caplog): |
| 193 | + """If the key_path is not provided, the toml file should use standard search and replace.""" |
| 194 | + from bumpversion import config |
| 195 | + from bumpversion.version_part import VersionConfig |
| 196 | + |
| 197 | + # Arrange |
| 198 | + config_path = tmp_path / "pyproject.toml" |
| 199 | + config_path.write_text( |
| 200 | + dedent( |
| 201 | + """ |
| 202 | + [project] |
| 203 | + version = "0.1.26" |
| 204 | +
|
| 205 | + [tool.bumpversion] |
| 206 | + current_version = "0.1.26" |
| 207 | + allow_dirty = true |
| 208 | + commit = true |
| 209 | +
|
| 210 | + [[tool.bumpversion.files]] |
| 211 | + filename = "pyproject.toml" |
| 212 | + search = "version = \\"{current_version}\\"" |
| 213 | + replace = "version = \\"{new_version}\\"" |
| 214 | + """ |
| 215 | + ) |
| 216 | + ) |
| 217 | + |
| 218 | + conf = config.get_configuration(config_file=config_path) |
| 219 | + |
| 220 | + # Act |
| 221 | + from click.testing import CliRunner, Result |
| 222 | + from bumpversion import cli |
| 223 | + |
| 224 | + runner: CliRunner = CliRunner() |
| 225 | + with inside_dir(tmp_path): |
| 226 | + result: Result = runner.invoke( |
| 227 | + cli.cli, |
| 228 | + ["bump", "-vv", "minor"], |
| 229 | + ) |
| 230 | + |
| 231 | + if result.exit_code != 0: |
| 232 | + print(caplog.text) |
| 233 | + print("Here is the output:") |
| 234 | + print(result.output) |
| 235 | + import traceback |
| 236 | + |
| 237 | + print(traceback.print_exception(result.exc_info[1])) |
| 238 | + |
| 239 | + # Assert |
| 240 | + assert result.exit_code == 0 |
| 241 | + assert config_path.read_text() == dedent( |
| 242 | + """ |
| 243 | + [project] |
| 244 | + version = "0.2.0" |
| 245 | +
|
| 246 | + [tool.bumpversion] |
| 247 | + current_version = "0.2.0" |
| 248 | + allow_dirty = true |
| 249 | + commit = true |
| 250 | +
|
| 251 | + [[tool.bumpversion.files]] |
| 252 | + filename = "pyproject.toml" |
| 253 | + search = "version = \\"{current_version}\\"" |
| 254 | + replace = "version = \\"{new_version}\\"" |
| 255 | + """ |
| 256 | + ) |
0 commit comments