Skip to content

Commit f8f0278

Browse files
committed
Added tests for logging branches
1 parent ac6cdd0 commit f8f0278

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

bumpversion/scm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
4949

5050
try:
5151
subprocess.run([*cls._COMMIT_COMMAND, f.name, *extra_args], env=env, capture_output=True, check=True)
52-
except subprocess.CalledProcessError as exc:
52+
except subprocess.CalledProcessError as exc: # pragma: no-coverage
5353
err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}"
5454
logger.exception(err_msg)
5555
raise exc

tests/test_scm.py

+64
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,67 @@ def test_commit_and_tag_from_below_scm_root(repo: str, scm_command: str, scm_cla
143143
assert tag_info.distance_to_latest_tag == 0
144144
assert tag_info.current_version == "30.1.0"
145145
assert tag_info.dirty is False
146+
147+
148+
# write tests for no-commit, no-tag and dry-run
149+
@pytest.mark.parametrize(
150+
["repo", "scm_command", "scm_class"],
151+
[
152+
param("git_repo", "git", scm.Git, id="git"),
153+
param("hg_repo", "hg", scm.Mercurial, id="hg"),
154+
],
155+
)
156+
@pytest.mark.parametrize(
157+
["commit", "tag", "dry_run", "should_commit", "should_tag"],
158+
[
159+
param(True, True, True, False, False, id="dry-run-stops-commit-and-tag"),
160+
param(True, False, False, True, False, id="commit-no-tag"),
161+
param(False, True, False, False, False, id="no-commit-stops-tag"),
162+
],
163+
)
164+
def test_commit_tag_dry_run_interactions(
165+
repo: str,
166+
scm_command: str,
167+
scm_class: scm.SourceCodeManager,
168+
commit: bool,
169+
tag: bool,
170+
dry_run: bool,
171+
should_commit: bool,
172+
should_tag: bool,
173+
caplog: LogCaptureFixture,
174+
request,
175+
):
176+
"""Combinations of commit, tag, dry-run and should produce the expected results."""
177+
# Arrange
178+
repo_path: Path = request.getfixturevalue(repo)
179+
version_path = repo_path / "VERSION"
180+
version_path.write_text("30.0.3")
181+
182+
overrides = {"current_version": "30.0.3", "commit": commit, "tag": tag, "files": [{"filename": str(version_path)}]}
183+
context = {
184+
"current_version": "30.0.3",
185+
"new_version": "30.1.0",
186+
}
187+
with inside_dir(repo_path):
188+
conf, version_config, current_version = get_config_data(overrides)
189+
subprocess.run([scm_command, "add", "VERSION"], check=True, capture_output=True)
190+
subprocess.run([scm_command, "commit", "-m", "initial commit"], check=True, capture_output=True)
191+
version_path.write_text("30.1.0")
192+
# Act
193+
scm_class.commit_to_scm(files=[version_path], config=conf, context=context, dry_run=dry_run)
194+
scm_class.tag_in_scm(config=conf, context=context, dry_run=dry_run)
195+
196+
# Assert
197+
if commit and dry_run:
198+
assert "Would commit" in caplog.text
199+
elif should_commit:
200+
assert "Committing " in caplog.text
201+
else:
202+
assert "Would not commit" in caplog.text
203+
204+
if tag and dry_run:
205+
assert "Would tag" in caplog.text
206+
elif should_tag:
207+
assert "Tagging " in caplog.text
208+
else:
209+
assert "Would not tag" in caplog.text

0 commit comments

Comments
 (0)