|
3 | 3 | from pathlib import Path
|
4 | 4 |
|
5 | 5 | import pytest
|
| 6 | +from pytest import param |
6 | 7 |
|
7 | 8 | from bumpversion import scm
|
8 | 9 | from bumpversion.exceptions import DirtyWorkingDirectoryError
|
9 |
| -from tests.conftest import inside_dir |
10 |
| - |
11 |
| - |
12 |
| -@pytest.fixture |
13 |
| -def git_repo(tmp_path: Path) -> Path: |
14 |
| - """Generate a simple temporary git repo and return the path.""" |
15 |
| - subprocess.run(["git", "init"], cwd=tmp_path) |
16 |
| - return tmp_path |
17 |
| - |
18 |
| - |
19 |
| -@pytest.fixture |
20 |
| -def hg_repo(tmp_path: Path) -> Path: |
21 |
| - """Generate a simple temporary mercurial repo and return the path.""" |
22 |
| - subprocess.run(["hg", "init"], cwd=tmp_path) |
23 |
| - return tmp_path |
| 10 | +from tests.conftest import get_config_data, inside_dir |
24 | 11 |
|
25 | 12 |
|
26 | 13 | def test_git_is_usable(git_repo: Path) -> None:
|
@@ -88,3 +75,43 @@ def test_hg_is_usable(hg_repo: Path) -> None:
|
88 | 75 | """Should return false if it is not a mercurial repo."""
|
89 | 76 | with inside_dir(hg_repo):
|
90 | 77 | assert scm.Mercurial.is_usable()
|
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.parametrize( |
| 81 | + ["repo", "scm_command", "scm_class"], |
| 82 | + [ |
| 83 | + param("git_repo", "git", scm.Git, id="git"), |
| 84 | + param("hg_repo", "hg", scm.Mercurial, id="hg"), |
| 85 | + ], |
| 86 | +) |
| 87 | +def test_commit_and_tag_from_below_scm_root(repo: str, scm_command: str, scm_class: scm.SourceCodeManager, request): |
| 88 | + # Arrange |
| 89 | + repo_path: Path = request.getfixturevalue(repo) |
| 90 | + version_path = repo_path / "VERSION" |
| 91 | + version_path.write_text("30.0.3") |
| 92 | + sub_dir_path = repo_path / "subdir" |
| 93 | + sub_dir_path.mkdir(exist_ok=True) |
| 94 | + |
| 95 | + overrides = {"current_version": "30.0.3", "commit": True, "tag": True, "files": [{"filename": str(version_path)}]} |
| 96 | + context = { |
| 97 | + "current_version": "30.0.3", |
| 98 | + "new_version": "30.1.0", |
| 99 | + } |
| 100 | + with inside_dir(repo_path): |
| 101 | + conf, version_config, current_version = get_config_data(overrides) |
| 102 | + subprocess.run([scm_command, "add", "VERSION"], check=True, capture_output=True) |
| 103 | + subprocess.run([scm_command, "commit", "-m", "initial commit"], check=True, capture_output=True) |
| 104 | + with inside_dir(sub_dir_path): |
| 105 | + version_path.write_text("30.1.0") |
| 106 | + |
| 107 | + # Act |
| 108 | + scm_class.commit_to_scm(files=[version_path], config=conf, context=context) |
| 109 | + scm_class.tag_in_scm(config=conf, context=context) |
| 110 | + |
| 111 | + # Assert |
| 112 | + tag_info = scm_class.latest_tag_info("v*") |
| 113 | + if scm_command == "git": |
| 114 | + assert tag_info.commit_sha is not None |
| 115 | + assert tag_info.distance_to_latest_tag == 0 |
| 116 | + assert tag_info.current_version == "30.1.0" |
| 117 | + assert tag_info.dirty is False |
0 commit comments