Skip to content

Commit 4013d86

Browse files
committed
Updated some tests
1 parent ddbe21e commit 4013d86

File tree

10 files changed

+85
-422
lines changed

10 files changed

+85
-422
lines changed

bumpversion/autocast.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def noneify(s: str) -> None:
2828

2929
def listify(s: str) -> list:
3030
"""
31-
Convert a string representation of a list into list of homogeneous basic types.
31+
Convert a string representation of a list into a `list` of homogeneous basic types.
3232
33-
Type of elements in list is determined via first element. Successive elements are
33+
The type of the elements in the list is determined via the first element. Successive elements are
3434
cast to that type.
3535
3636
Args:

tests/test_bump.py

+57-32
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from bumpversion.exceptions import ConfigurationError, VersionNotFoundError
1212
from bumpversion.files import ConfiguredFile
1313
from bumpversion.scm.git import Git
14-
from bumpversion.scm.models import SCMInfo, SCMConfig
14+
from bumpversion.scm.models import SCMConfig, SCMInfo
1515
from bumpversion.utils import run_command
1616
from tests.conftest import get_config_data, inside_dir
1717

@@ -25,7 +25,7 @@ class TestGetNextVersion:
2525
"""Tests for the get_next_version function."""
2626

2727
def test_passing_a_new_version_should_override_a_version_part(self, tmp_path: Path):
28-
"""Passing a new version should return that version."""
28+
"""Passing a new version should return that version, even if a version part is provided."""
2929
# Arrange
3030
with inside_dir(tmp_path):
3131
config, version_config, current_version = get_config_data({"current_version": "0.1.0"})
@@ -54,6 +54,7 @@ def test_passing_version_part_should_increment_part(self):
5454
assert actual_next_version == expected_next_version
5555

5656
def test_passing_no_arguments_raises_error(self):
57+
"""If no arguments are provided, an error should be raised."""
5758
# Arrange
5859
current_version = MagicMock()
5960
config = MagicMock()
@@ -73,6 +74,7 @@ class TestDoBump:
7374
def test_passing_version_part_increments_part(
7475
self, mock_update_config_file, mock_modify_files, scm_config: SCMConfig
7576
):
77+
"""If a version part is provided, and no new version, it should increment that part."""
7678
# Arrange
7779
version_part = "major"
7880
new_version = None
@@ -104,6 +106,7 @@ def test_passing_version_part_increments_part(
104106
@patch("bumpversion.files.modify_files")
105107
@patch("bumpversion.bump.update_config_file")
106108
def test_passing_new_version_sets_version(self, mock_update_config_file, mock_modify_files, scm_config: SCMConfig):
109+
"""If a new version is provided, it should set the version to that new version."""
107110
# Arrange
108111
version_part = None
109112
new_version = "2.0.0"
@@ -136,6 +139,7 @@ def test_passing_new_version_sets_version(self, mock_update_config_file, mock_mo
136139
def test_doesnt_commit_if_modify_error(
137140
self, mock_update_config_file, mock_commit_and_tag, tmp_path: Path, fixtures_path: Path
138141
):
142+
"""If there is an error modifying a file, the commit should not happen."""
139143
from bumpversion import config
140144

141145
# Arrange
@@ -164,7 +168,6 @@ def test_doesnt_commit_if_modify_error(
164168
@patch("bumpversion.bump.update_config_file")
165169
def test_when_new_equals_current_nothing_happens(self, mock_update_config_file, mock_modify_files, tmp_path: Path):
166170
"""When the new version is the same as the current version, nothing should happen."""
167-
168171
# Arrange
169172
version_part = None
170173
new_version = "1.2.3"
@@ -179,6 +182,7 @@ def test_when_new_equals_current_nothing_happens(self, mock_update_config_file,
179182
mock_update_config_file.assert_not_called()
180183

181184
def test_passing_no_arguments_raises_error(self, scm_config: SCMConfig):
185+
"""If no arguments are provided, an error should be raised."""
182186
# Arrange
183187
version_part = None
184188
new_version = None
@@ -249,40 +253,61 @@ def test_excludes_files_with_exclude_bumps(
249253
assert {f.file_change.filename for f in mock_modify_files.call_args[0][0]} == {"foo.txt", "bar.txt"}
250254

251255

252-
def test_commit_and_tag_with_no_tool(scm_config: SCMConfig):
253-
config, _, _ = get_config_data(
254-
{
255-
"current_version": "1.2.3",
256-
}
257-
)
258-
config.scm_info = SCMInfo(scm_config)
259-
mock_context = MagicMock()
256+
class TestCommitAndTag:
257+
"""Tests for the commit_and_tag function."""
260258

261-
bump.commit_and_tag(config, None, [], mock_context, False)
259+
def does_nothing_if_no_scm_tool(self, scm_config: SCMConfig):
260+
"""If there is no SCM tool, nothing should happen."""
261+
# Arrange
262+
config, _, _ = get_config_data(
263+
{
264+
"current_version": "1.2.3",
265+
}
266+
)
267+
config.scm_info = SCMInfo(scm_config)
268+
mock_commit_and_tag = MagicMock()
269+
config.scm_info.commit_and_tag = mock_commit_and_tag
270+
mock_context = MagicMock()
262271

272+
# Act
273+
bump.commit_and_tag(config, None, [], mock_context, False)
263274

264-
def test_commit_and_tag_with_tool(mock_context, scm_config: SCMConfig):
265-
config, version_config, _ = get_config_data(
266-
{"current_version": "1.2.3", "files": [{"filename": "foo.txt"}, {"filename": "bar.txt"}]}
267-
)
268-
config.scm_info = MagicMock(spec=SCMInfo)
269-
config.scm_info.tool = MagicMock(spec=Git)
270-
configured_files = [ConfiguredFile(file_cfg, version_config) for file_cfg in config.files]
271-
bump.commit_and_tag(config, None, configured_files, mock_context, False)
272-
config.scm_info.commit_and_tag.assert_called_once()
273-
assert set(config.scm_info.commit_and_tag.call_args[0][0]) == {"foo.txt", "bar.txt"}
275+
# Assert
276+
assert mock_commit_and_tag.call_count == 0
274277

278+
def test_calls_scm_tool_commit_and_tag_with_files(self, mock_context, scm_config: SCMConfig):
279+
"""When there is an SCM tool, the files should be passed to the SCM tool."""
280+
# Arrange
281+
config, version_config, _ = get_config_data(
282+
{"current_version": "1.2.3", "files": [{"filename": "foo.txt"}, {"filename": "bar.txt"}]}
283+
)
284+
config.scm_info = MagicMock(spec=SCMInfo)
285+
config.scm_info.tool = MagicMock(spec=Git)
286+
configured_files = [ConfiguredFile(file_cfg, version_config) for file_cfg in config.files]
275287

276-
def test_commit_and_tag_with_config_file(mock_context, scm_config: SCMConfig):
277-
config, version_config, current_version = get_config_data(
278-
{"current_version": "1.2.3", "files": [{"filename": "foo.txt"}, {"filename": "bar.txt"}]}
279-
)
280-
config.scm_info = MagicMock(spec=SCMInfo)
281-
config.scm_info.tool = MagicMock(spec=Git)
282-
configured_files = [ConfiguredFile(file_cfg, version_config) for file_cfg in config.files]
283-
bump.commit_and_tag(config, Path("pyproject.toml"), configured_files, mock_context, False)
284-
config.scm_info.commit_and_tag.assert_called_once()
285-
assert set(config.scm_info.commit_and_tag.call_args[0][0]) == {"foo.txt", "bar.txt", "pyproject.toml"}
288+
# Act
289+
bump.commit_and_tag(config, None, configured_files, mock_context, False)
290+
291+
# Assert
292+
config.scm_info.commit_and_tag.assert_called_once()
293+
assert set(config.scm_info.commit_and_tag.call_args[0][0]) == {"foo.txt", "bar.txt"}
294+
295+
def test_includes_config_file_in_files(self, mock_context, scm_config: SCMConfig):
296+
"""If the config file is passed to commit_and_tag, it should be included in the files list."""
297+
# Arrange
298+
config, version_config, _ = get_config_data(
299+
{"current_version": "1.2.3", "files": [{"filename": "foo.txt"}, {"filename": "bar.txt"}]}
300+
)
301+
config.scm_info = MagicMock(spec=SCMInfo)
302+
config.scm_info.tool = MagicMock(spec=Git)
303+
configured_files = [ConfiguredFile(file_cfg, version_config) for file_cfg in config.files]
304+
305+
# Act
306+
bump.commit_and_tag(config, Path("pyproject.toml"), configured_files, mock_context, False)
307+
308+
# Assert
309+
config.scm_info.commit_and_tag.assert_called_once()
310+
assert set(config.scm_info.commit_and_tag.call_args[0][0]) == {"foo.txt", "bar.txt", "pyproject.toml"}
286311

287312

288313
def test_key_path_required_for_toml_change(tmp_path: Path, caplog):

tests/test_cli/test_bump.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from textwrap import dedent
99

1010
import pytest
11-
from pytest import param
12-
1311
from click.testing import Result
12+
from pytest import param
1413

1514
from bumpversion import cli
1615
from tests.conftest import inside_dir

tests/test_config/test_init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestCheckCurrentVersion:
1616

1717
def test_uses_tag_when_missing_current_version(self, scm_config: SCMConfig):
1818
"""When the config does not have a current_version, the last tag is used."""
19-
# Assemble
19+
# Arrange
2020

2121
scm_info = SCMInfo(scm_config)
2222
scm_info.current_version = "1.2.3"

0 commit comments

Comments
 (0)