4
4
import traceback
5
5
from pathlib import Path
6
6
7
- from click .testing import CliRunner , Result
7
+ from click .testing import Result
8
8
9
9
from bumpversion import cli
10
10
from tests .conftest import inside_dir
@@ -41,15 +41,14 @@ class TestReplaceCLI:
41
41
class TestDefaultReplacesVersion :
42
42
"""Test the default behavior of the replace subcommand."""
43
43
44
- def test_default_affects_all_configured_files (self , mocker , tmp_path , fixtures_path ):
44
+ def test_default_affects_all_configured_files (self , mocker , tmp_path , fixtures_path , runner ):
45
45
"""The replace subcommand should replace the version in all configured files."""
46
46
# Arrange
47
47
toml_path = fixtures_path / "basic_cfg.toml"
48
48
config_path = tmp_path / "pyproject.toml"
49
49
shutil .copy (toml_path , config_path )
50
50
51
51
mocked_modify_files = mocker .patch ("bumpversion.cli.modify_files" )
52
- runner : CliRunner = CliRunner ()
53
52
with inside_dir (tmp_path ):
54
53
result : Result = runner .invoke (cli .cli , ["replace" , "--new-version" , "1.1.0" ])
55
54
@@ -66,15 +65,14 @@ def test_default_affects_all_configured_files(self, mocker, tmp_path, fixtures_p
66
65
actual_filenames = {f .file_change .filename for f in configured_files }
67
66
assert actual_filenames == {"setup.py" , "CHANGELOG.md" , "bumpversion/__init__.py" }
68
67
69
- def test_can_limit_to_specific_files (self , mocker , git_repo , fixtures_path ):
68
+ def test_can_limit_to_specific_files (self , mocker , git_repo , fixtures_path , runner ):
70
69
"""The replace subcommand should set the files to only the specified files."""
71
70
# Arrange
72
71
toml_path = fixtures_path / "basic_cfg.toml"
73
72
config_path = git_repo / "pyproject.toml"
74
73
shutil .copy (toml_path , config_path )
75
74
76
75
mocked_modify_files = mocker .patch ("bumpversion.cli.modify_files" )
77
- runner : CliRunner = CliRunner ()
78
76
with inside_dir (git_repo ):
79
77
result : Result = runner .invoke (cli .cli , ["replace" , "--no-configured-files" , "VERSION" ])
80
78
@@ -93,15 +91,14 @@ def test_can_limit_to_specific_files(self, mocker, git_repo, fixtures_path):
93
91
class TestOptions :
94
92
"""Test the options of the replace subcommand."""
95
93
96
- def test_missing_newversion_is_set_to_none (self , mocker , tmp_path , fixtures_path ):
94
+ def test_missing_newversion_is_set_to_none (self , mocker , tmp_path , fixtures_path , runner ):
97
95
"""The replace subcommand should set new_version to None in the context."""
98
96
# Arrange
99
97
toml_path = fixtures_path / "basic_cfg.toml"
100
98
config_path = tmp_path / "pyproject.toml"
101
99
shutil .copy (toml_path , config_path )
102
100
103
101
mocked_modify_files = mocker .patch ("bumpversion.cli.modify_files" )
104
- runner : CliRunner = CliRunner ()
105
102
with inside_dir (tmp_path ):
106
103
result : Result = runner .invoke (cli .cli , ["replace" ])
107
104
@@ -115,7 +112,7 @@ def test_missing_newversion_is_set_to_none(self, mocker, tmp_path, fixtures_path
115
112
call_args = mocked_modify_files .call_args [0 ]
116
113
assert call_args [2 ] is None
117
114
118
- def test_ignores_missing_files_with_option (self , mocker , tmp_path , fixtures_path ):
115
+ def test_ignores_missing_files_with_option (self , mocker , tmp_path , fixtures_path , runner ):
119
116
"""The replace subcommand should ignore missing."""
120
117
121
118
config_file = tmp_path / ".bumpversion.toml"
@@ -129,7 +126,6 @@ def test_ignores_missing_files_with_option(self, mocker, tmp_path, fixtures_path
129
126
)
130
127
131
128
# Act
132
- runner : CliRunner = CliRunner ()
133
129
with inside_dir (tmp_path ):
134
130
result : Result = runner .invoke (
135
131
cli .cli ,
@@ -154,7 +150,7 @@ def test_ignores_missing_files_with_option(self, mocker, tmp_path, fixtures_path
154
150
class TestSearchInputs :
155
151
"""Test the search inputs of the replace subcommand."""
156
152
157
- def test_accepts_plain_string (self , tmp_path , fixtures_path ):
153
+ def test_accepts_plain_string (self , tmp_path , fixtures_path , runner ):
158
154
"""Replace should not worry if the search values have version info."""
159
155
from tomlkit import dumps
160
156
@@ -164,7 +160,6 @@ def test_accepts_plain_string(self, tmp_path, fixtures_path):
164
160
doc_path = tmp_path / "docs.yaml"
165
161
doc_path .write_text ("url: https://github.com/sampleuser/workflows/main/.github/update_mailmap.py" )
166
162
167
- runner : CliRunner = CliRunner ()
168
163
with inside_dir (tmp_path ):
169
164
result : Result = runner .invoke (
170
165
cli .cli ,
@@ -186,7 +181,7 @@ def test_accepts_plain_string(self, tmp_path, fixtures_path):
186
181
187
182
assert result .exit_code == 0
188
183
189
- def test_unintentional_valid_regex_still_found (self , tmp_path : Path , caplog ) -> None :
184
+ def test_unintentional_valid_regex_still_found (self , tmp_path : Path , caplog , runner ) -> None :
190
185
"""A search string not meant to be a regex (but is) is still found and replaced correctly."""
191
186
# Arrange
192
187
search = "(unreleased)"
@@ -209,7 +204,6 @@ def test_unintentional_valid_regex_still_found(self, tmp_path: Path, caplog) ->
209
204
)
210
205
211
206
# Act
212
- runner : CliRunner = CliRunner ()
213
207
with inside_dir (tmp_path ):
214
208
result : Result = runner .invoke (
215
209
cli .cli ,
@@ -241,7 +235,7 @@ def test_unintentional_valid_regex_still_found(self, tmp_path: Path, caplog) ->
241
235
class TestReplaceInputs :
242
236
"""Test the replace inputs of the replace subcommand."""
243
237
244
- def test_accepts_empty_string (self , tmp_path , fixtures_path ):
238
+ def test_accepts_empty_string (self , tmp_path , fixtures_path , runner ):
245
239
"""Replace should be able to replace strings with an empty string."""
246
240
from tomlkit import dumps
247
241
@@ -251,7 +245,6 @@ def test_accepts_empty_string(self, tmp_path, fixtures_path):
251
245
doc_path = tmp_path / "docs.yaml"
252
246
doc_path .write_text ("We should censor profanity\n \n " )
253
247
254
- runner : CliRunner = CliRunner ()
255
248
with inside_dir (tmp_path ):
256
249
result : Result = runner .invoke (
257
250
cli .cli ,
@@ -275,7 +268,7 @@ def test_accepts_empty_string(self, tmp_path, fixtures_path):
275
268
assert result .exit_code == 0
276
269
assert doc_path .read_text () == "We should censor \n \n "
277
270
278
- def test_accepts_plain_string (self , tmp_path , fixtures_path ):
271
+ def test_accepts_plain_string (self , tmp_path , fixtures_path , runner ):
279
272
"""Replace should not worry if the replace values have version info."""
280
273
from tomlkit import dumps
281
274
@@ -285,7 +278,6 @@ def test_accepts_plain_string(self, tmp_path, fixtures_path):
285
278
doc_path = tmp_path / "docs.yaml"
286
279
doc_path .write_text ("url: https://github.com/sampleuser/workflows/v2.17.7/.github/update_mailmap.py" )
287
280
288
- runner : CliRunner = CliRunner ()
289
281
with inside_dir (tmp_path ):
290
282
result : Result = runner .invoke (
291
283
cli .cli ,
0 commit comments