@@ -153,8 +153,8 @@ def test_dirty_work_dir_raises_error(repo: str, scm_command: str, request):
153
153
assert "working directory is not clean" in result .output
154
154
155
155
156
- def test_listing_outputs_correctly_and_stops (tmp_path : Path , fixtures_path : Path ):
157
- """The --list option should list the configuration and nothing else ."""
156
+ def test_listing_with_version_part (tmp_path : Path , fixtures_path : Path ):
157
+ """The --list option should list the configuration with new_version. ."""
158
158
# Arrange
159
159
config_path = tmp_path / "pyproject.toml"
160
160
toml_path = fixtures_path / "basic_cfg.toml"
@@ -193,6 +193,45 @@ def test_listing_outputs_correctly_and_stops(tmp_path: Path, fixtures_path: Path
193
193
}
194
194
195
195
196
+ def test_listing_without_version_part (tmp_path : Path , fixtures_path : Path ):
197
+ """The --list option should list the configuration without new_version."""
198
+ # Arrange
199
+ config_path = tmp_path / "pyproject.toml"
200
+ toml_path = fixtures_path / "basic_cfg.toml"
201
+ shutil .copy (toml_path , config_path )
202
+ runner : CliRunner = CliRunner ()
203
+
204
+ with inside_dir (tmp_path ):
205
+ result : Result = runner .invoke (cli .cli , ["--list" ])
206
+
207
+ if result .exit_code != 0 :
208
+ print (result .output )
209
+ print (result .exception )
210
+
211
+ assert result .exit_code == 0
212
+ assert set (result .output .splitlines (keepends = False )) == {
213
+ "current_version=1.0.0" ,
214
+ "parse=(?P<major>\\ d+)\\ .(?P<minor>\\ d+)\\ .(?P<patch>\\ d+)(\\ -(?P<release>[a-z]+))?" ,
215
+ "serialize=['{major}.{minor}.{patch}-{release}', '{major}.{minor}.{patch}']" ,
216
+ "search={current_version}" ,
217
+ "replace={new_version}" ,
218
+ "tag=True" ,
219
+ "sign_tags=False" ,
220
+ "tag_name=v{new_version}" ,
221
+ "tag_message=Bump version: {current_version} → {new_version}" ,
222
+ "allow_dirty=False" ,
223
+ "commit=True" ,
224
+ "message=Bump version: {current_version} → {new_version}" ,
225
+ "commit_args=None" ,
226
+ "files=[{'filename': 'setup.py', 'glob': None, 'parse': None, 'serialize': "
227
+ "None, 'search': None, 'replace': None}, {'filename': "
228
+ "'bumpversion/__init__.py', 'glob': None, 'parse': None, 'serialize': None, "
229
+ "'search': None, 'replace': None}, {'filename': 'CHANGELOG.md', 'glob': None, "
230
+ "'parse': None, 'serialize': None, 'search': '**unreleased**', 'replace': "
231
+ "'**unreleased**\\ n**v{new_version}**'}]" ,
232
+ }
233
+
234
+
196
235
def test_non_scm_operations_if_scm_not_installed (tmp_path : Path , monkeypatch ):
197
236
"""Everything works except SCM commands if the SCM is unusable."""
198
237
# Arrange
@@ -209,3 +248,32 @@ def test_non_scm_operations_if_scm_not_installed(tmp_path: Path, monkeypatch):
209
248
210
249
# Assert
211
250
assert version_path .read_text () == "32.0.0"
251
+
252
+
253
+ @pytest .mark .parametrize (
254
+ ["version_part" ],
255
+ [
256
+ param ("charlie" , id = "bad_version_part" ),
257
+ param ("" , id = "missing_version_part" ),
258
+ ],
259
+ )
260
+ def test_detects_bad_or_missing_version_part (version_part : str , tmp_path : Path , monkeypatch ):
261
+ """It properly detects bad or missing version part."""
262
+ # Arrange
263
+ monkeypatch .setenv ("PATH" , "" )
264
+
265
+ with inside_dir (tmp_path ):
266
+ version_path = tmp_path / "VERSION"
267
+ version_path .write_text ("31.0.3" )
268
+
269
+ runner : CliRunner = CliRunner ()
270
+ args = ["--current-version" , "31.0.3" ]
271
+ if version_part :
272
+ args .append (version_part )
273
+ args .append ("VERSION" )
274
+ # Act
275
+ result = runner .invoke (cli .cli , args )
276
+
277
+ # Assert
278
+ assert result .exception is not None
279
+ assert "Unknown version part:" in result .stdout
0 commit comments