6
6
from pathlib import Path
7
7
8
8
import pytest
9
- from pytest import param , LogCaptureFixture
9
+ from pytest import LogCaptureFixture , param
10
10
11
- from bumpversion import scm
12
- from bumpversion .exceptions import DirtyWorkingDirectoryError , BumpVersionError
11
+ from bumpversion import scm_old
12
+ from bumpversion .exceptions import BumpVersionError , DirtyWorkingDirectoryError
13
13
from bumpversion .ui import setup_logging
14
14
from bumpversion .utils import run_command
15
15
from tests .conftest import get_config_data , inside_dir
@@ -43,7 +43,7 @@ class TestGetVersionFromTag:
43
43
def returns_version_from_pattern (self , tag : str , tag_name : str , parse_pattern : str , expected : str ) -> None :
44
44
"""It properly returns the version from the tag."""
45
45
# Act
46
- version = scm .SourceCodeManager .get_version_from_tag (tag , tag_name , parse_pattern )
46
+ version = scm_old .SourceCodeManager .get_version_from_tag (tag , tag_name , parse_pattern )
47
47
48
48
# Assert
49
49
assert version == expected
@@ -55,7 +55,7 @@ def test_format_and_raise_error_returns_scm_error(self, git_repo: Path) -> None:
55
55
run_command (["git" , "add" , "newfile.txt" ])
56
56
except subprocess .CalledProcessError as e :
57
57
with pytest .raises (BumpVersionError ) as bump_error :
58
- scm .Git .format_and_raise_error (e )
58
+ scm_old .Git .format_and_raise_error (e )
59
59
assert bump_error .value .message == (
60
60
"Failed to run `git add newfile.txt`: return code 128, output: "
61
61
"fatal: pathspec 'newfile.txt' did not match any files\n "
@@ -71,29 +71,29 @@ class TestIsUsable:
71
71
def test_recognizes_a_git_repo (self , git_repo : Path ) -> None :
72
72
"""Should return true if git is available, and it is a git repo."""
73
73
with inside_dir (git_repo ):
74
- assert scm .Git .is_usable ()
74
+ assert scm_old .Git .is_usable ()
75
75
76
76
def test_recognizes_not_a_git_repo (self , tmp_path : Path ) -> None :
77
77
"""Should return false if it is not a git repo."""
78
78
with inside_dir (tmp_path ):
79
- assert not scm .Git .is_usable ()
79
+ assert not scm_old .Git .is_usable ()
80
80
81
81
class TestAssertNonDirty :
82
82
"""Tests for the Git.assert_nondirty() function."""
83
83
84
84
def test_does_nothing_when_not_dirty (self , git_repo : Path ) -> None :
85
85
"""If the git repo is clean, assert_nondirty should do nothing."""
86
86
with inside_dir (git_repo ):
87
- scm .Git .assert_nondirty ()
87
+ scm_old .Git .assert_nondirty ()
88
88
89
89
def test_raises_error_when_dirty (self , git_repo : Path ) -> None :
90
90
"""If the git repo has modified files, assert_nondirty should return false."""
91
91
readme = git_repo .joinpath ("readme.md" )
92
92
readme .touch ()
93
93
with pytest .raises (DirtyWorkingDirectoryError ):
94
94
with inside_dir (git_repo ):
95
- subprocess .run (["git" , "add" , "readme.md" ])
96
- scm .Git .assert_nondirty ()
95
+ subprocess .run (["git" , "add" , "readme.md" ], check = False )
96
+ scm_old .Git .assert_nondirty ()
97
97
98
98
class TestLatestTagInfo :
99
99
"""Test for the Git.latest_tag_info() function."""
@@ -107,8 +107,8 @@ def test_an_empty_repo_only_fills_tool_info(self, git_repo: Path) -> None:
107
107
tag_prefix = "app/"
108
108
parse_pattern = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)"
109
109
tag_name = f"{ tag_prefix } {{new_version}}"
110
- expected = scm .SCMInfo (
111
- tool = scm .Git ,
110
+ expected = scm_old .SCMInfo (
111
+ tool = scm_old .Git ,
112
112
commit_sha = None ,
113
113
distance_to_latest_tag = 0 ,
114
114
current_version = None ,
@@ -118,7 +118,7 @@ def test_an_empty_repo_only_fills_tool_info(self, git_repo: Path) -> None:
118
118
dirty = None ,
119
119
)
120
120
with inside_dir (git_repo ):
121
- latest_tag_info = scm .Git .latest_tag_info (tag_name , parse_pattern = parse_pattern )
121
+ latest_tag_info = scm_old .Git .latest_tag_info (tag_name , parse_pattern = parse_pattern )
122
122
assert latest_tag_info == expected
123
123
124
124
def test_returns_commit_and_tag_info (self , git_repo : Path ) -> None :
@@ -133,7 +133,7 @@ def test_returns_commit_and_tag_info(self, git_repo: Path) -> None:
133
133
subprocess .run (["git" , "add" , "readme.md" ])
134
134
subprocess .run (["git" , "commit" , "-m" , "first" ])
135
135
subprocess .run (["git" , "tag" , f"{ tag_prefix } 0.1.0" ])
136
- tag_info = scm .Git .latest_tag_info (tag_name , parse_pattern = parse_pattern )
136
+ tag_info = scm_old .Git .latest_tag_info (tag_name , parse_pattern = parse_pattern )
137
137
assert tag_info .commit_sha is not None
138
138
assert tag_info .current_version == "0.1.0"
139
139
assert tag_info .current_tag == f"{ tag_prefix } 0.1.0"
@@ -165,7 +165,7 @@ def test_git_detects_existing_tag(git_repo: Path, caplog: LogCaptureFixture) ->
165
165
subprocess .run (["git" , "tag" , "v0.2.0" ])
166
166
167
167
# Act
168
- scm .Git .tag_in_scm (config = conf , context = context )
168
+ scm_old .Git .tag_in_scm (config = conf , context = context )
169
169
170
170
# Assert
171
171
assert "Will not tag" in caplog .text
@@ -174,14 +174,14 @@ def test_git_detects_existing_tag(git_repo: Path, caplog: LogCaptureFixture) ->
174
174
def test_hg_is_not_usable (tmp_path : Path ) -> None :
175
175
"""Should return false if it is not a mercurial repo."""
176
176
with inside_dir (tmp_path ):
177
- assert not scm .Mercurial .is_usable ()
177
+ assert not scm_old .Mercurial .is_usable ()
178
178
179
179
180
180
@pytest .mark .skipif (not shutil .which ("hg" ), reason = "Mercurial is not available." )
181
181
def test_hg_is_usable (hg_repo : Path ) -> None :
182
182
"""Should return false if it is not a mercurial repo."""
183
183
with inside_dir (hg_repo ):
184
- assert scm .Mercurial .is_usable ()
184
+ assert scm_old .Mercurial .is_usable ()
185
185
186
186
187
187
@pytest .mark .parametrize (
@@ -190,20 +190,22 @@ def test_hg_is_usable(hg_repo: Path) -> None:
190
190
param (
191
191
"git_repo" ,
192
192
"git" ,
193
- scm .Git ,
193
+ scm_old .Git ,
194
194
id = "git" ,
195
195
marks = pytest .mark .skipif (not shutil .which ("git" ), reason = "Git is not available." ),
196
196
),
197
197
param (
198
198
"hg_repo" ,
199
199
"hg" ,
200
- scm .Mercurial ,
200
+ scm_old .Mercurial ,
201
201
id = "hg" ,
202
202
marks = pytest .mark .skipif (not shutil .which ("hg" ), reason = "Mercurial is not available." ),
203
203
),
204
204
],
205
205
)
206
- def test_commit_and_tag_from_below_scm_root (repo : str , scm_command : str , scm_class : scm .SourceCodeManager , request ):
206
+ def test_commit_and_tag_from_below_scm_root (
207
+ repo : str , scm_command : str , scm_class : scm_old .SourceCodeManager , request
208
+ ):
207
209
# Arrange
208
210
repo_path : Path = request .getfixturevalue (repo )
209
211
version_path = repo_path / "VERSION"
@@ -243,14 +245,14 @@ def test_commit_and_tag_from_below_scm_root(repo: str, scm_command: str, scm_cla
243
245
param (
244
246
"git_repo" ,
245
247
"git" ,
246
- scm .Git ,
248
+ scm_old .Git ,
247
249
id = "git" ,
248
250
marks = pytest .mark .skipif (not shutil .which ("git" ), reason = "Git is not available." ),
249
251
),
250
252
param (
251
253
"hg_repo" ,
252
254
"hg" ,
253
- scm .Mercurial ,
255
+ scm_old .Mercurial ,
254
256
id = "hg" ,
255
257
marks = pytest .mark .skipif (not shutil .which ("hg" ), reason = "Mercurial is not available." ),
256
258
),
@@ -267,7 +269,7 @@ def test_commit_and_tag_from_below_scm_root(repo: str, scm_command: str, scm_cla
267
269
def test_commit_tag_dry_run_interactions (
268
270
repo : str ,
269
271
scm_command : str ,
270
- scm_class : scm .SourceCodeManager ,
272
+ scm_class : scm_old .SourceCodeManager ,
271
273
commit : bool ,
272
274
tag : bool ,
273
275
dry_run : bool ,
0 commit comments