11
11
from bumpversion .exceptions import ConfigurationError , VersionNotFoundError
12
12
from bumpversion .files import ConfiguredFile
13
13
from bumpversion .scm .git import Git
14
- from bumpversion .scm .models import SCMInfo , SCMConfig
14
+ from bumpversion .scm .models import SCMConfig , SCMInfo
15
15
from bumpversion .utils import run_command
16
16
from tests .conftest import get_config_data , inside_dir
17
17
@@ -25,7 +25,7 @@ class TestGetNextVersion:
25
25
"""Tests for the get_next_version function."""
26
26
27
27
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 ."""
29
29
# Arrange
30
30
with inside_dir (tmp_path ):
31
31
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):
54
54
assert actual_next_version == expected_next_version
55
55
56
56
def test_passing_no_arguments_raises_error (self ):
57
+ """If no arguments are provided, an error should be raised."""
57
58
# Arrange
58
59
current_version = MagicMock ()
59
60
config = MagicMock ()
@@ -73,6 +74,7 @@ class TestDoBump:
73
74
def test_passing_version_part_increments_part (
74
75
self , mock_update_config_file , mock_modify_files , scm_config : SCMConfig
75
76
):
77
+ """If a version part is provided, and no new version, it should increment that part."""
76
78
# Arrange
77
79
version_part = "major"
78
80
new_version = None
@@ -104,6 +106,7 @@ def test_passing_version_part_increments_part(
104
106
@patch ("bumpversion.files.modify_files" )
105
107
@patch ("bumpversion.bump.update_config_file" )
106
108
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."""
107
110
# Arrange
108
111
version_part = None
109
112
new_version = "2.0.0"
@@ -136,6 +139,7 @@ def test_passing_new_version_sets_version(self, mock_update_config_file, mock_mo
136
139
def test_doesnt_commit_if_modify_error (
137
140
self , mock_update_config_file , mock_commit_and_tag , tmp_path : Path , fixtures_path : Path
138
141
):
142
+ """If there is an error modifying a file, the commit should not happen."""
139
143
from bumpversion import config
140
144
141
145
# Arrange
@@ -164,7 +168,6 @@ def test_doesnt_commit_if_modify_error(
164
168
@patch ("bumpversion.bump.update_config_file" )
165
169
def test_when_new_equals_current_nothing_happens (self , mock_update_config_file , mock_modify_files , tmp_path : Path ):
166
170
"""When the new version is the same as the current version, nothing should happen."""
167
-
168
171
# Arrange
169
172
version_part = None
170
173
new_version = "1.2.3"
@@ -179,6 +182,7 @@ def test_when_new_equals_current_nothing_happens(self, mock_update_config_file,
179
182
mock_update_config_file .assert_not_called ()
180
183
181
184
def test_passing_no_arguments_raises_error (self , scm_config : SCMConfig ):
185
+ """If no arguments are provided, an error should be raised."""
182
186
# Arrange
183
187
version_part = None
184
188
new_version = None
@@ -249,40 +253,61 @@ def test_excludes_files_with_exclude_bumps(
249
253
assert {f .file_change .filename for f in mock_modify_files .call_args [0 ][0 ]} == {"foo.txt" , "bar.txt" }
250
254
251
255
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."""
260
258
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 ()
262
271
272
+ # Act
273
+ bump .commit_and_tag (config , None , [], mock_context , False )
263
274
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
274
277
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 ]
275
287
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" }
286
311
287
312
288
313
def test_key_path_required_for_toml_change (tmp_path : Path , caplog ):
0 commit comments