Skip to content

Commit 23be62d

Browse files
committed
Updated tests for bad version parts
1 parent 1e3ebc5 commit 23be62d

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

tests/test_cli.py

+70-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ def test_dirty_work_dir_raises_error(repo: str, scm_command: str, request):
153153
assert "working directory is not clean" in result.output
154154

155155

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.."""
158158
# Arrange
159159
config_path = tmp_path / "pyproject.toml"
160160
toml_path = fixtures_path / "basic_cfg.toml"
@@ -193,6 +193,45 @@ def test_listing_outputs_correctly_and_stops(tmp_path: Path, fixtures_path: Path
193193
}
194194

195195

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+
196235
def test_non_scm_operations_if_scm_not_installed(tmp_path: Path, monkeypatch):
197236
"""Everything works except SCM commands if the SCM is unusable."""
198237
# Arrange
@@ -209,3 +248,32 @@ def test_non_scm_operations_if_scm_not_installed(tmp_path: Path, monkeypatch):
209248

210249
# Assert
211250
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

Comments
 (0)