1
- import logging
2
1
from pathlib import Path
3
2
4
3
import pytest
5
4
from click import UsageError
6
- from pytest import LogCaptureFixture , param
7
5
8
6
from bumpversion import exceptions
9
7
from bumpversion .utils import get_context
@@ -76,153 +74,6 @@ def test_serialize_with_environment_var():
76
74
del os .environ ["BUILD_NUMBER" ]
77
75
78
76
79
- def test_serialize_with_newlines ():
80
- overrides = {
81
- "current_version" : "MAJOR=31\n MINOR=0\n PATCH=3\n " ,
82
- "parse" : r"MAJOR=(?P<major>\d+)\nMINOR=(?P<minor>\d+)\nPATCH=(?P<patch>\d+)\n" ,
83
- "serialize" : ["MAJOR={major}\n MINOR={minor}\n PATCH={patch}\n " ],
84
- }
85
- conf , version_config , current_version = get_config_data (overrides )
86
- new_version = current_version .bump ("major" )
87
- assert version_config .serialize (new_version , get_context (conf )) == "MAJOR=32\n MINOR=0\n PATCH=0\n "
88
-
89
-
90
- @pytest .mark .parametrize (
91
- ["bump_type" , "expected" ],
92
- [
93
- param ("patch" , "0.9.1" , id = "patch" ),
94
- param ("minor" , "0.10" , id = "minor" ),
95
- param ("major" , "1" , id = "major" ),
96
- ],
97
- )
98
- def test_serialize_three_part (bump_type : str , expected : str ):
99
- overrides = {
100
- "current_version" : "0.9" ,
101
- "parse" : r"(?P<major>\d+)(\.(?P<minor>\d+)(\.(?P<patch>\d+))?)?" ,
102
- "serialize" : ["{major}.{minor}.{patch}" , "{major}.{minor}" , "{major}" ],
103
- }
104
- conf , version_config , current_version = get_config_data (overrides )
105
-
106
- new_version = current_version .bump (bump_type )
107
- assert version_config .serialize (new_version , get_context (conf )) == expected
108
-
109
-
110
- @pytest .mark .parametrize (
111
- ["initial" , "bump_type" , "expected" ],
112
- [
113
- param ("1.5.dev" , "release" , "1.5" , id = "release" ),
114
- param ("1.5" , "minor" , "1.6.dev" , id = "minor" ),
115
- ],
116
- )
117
- def test_bump_non_numeric_parts (initial : str , bump_type : str , expected : str ):
118
- overrides = {
119
- "current_version" : initial ,
120
- "parse" : r"(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<release>[a-z]+))?" ,
121
- "serialize" : ["{major}.{minor}.{release}" , "{major}.{minor}" ],
122
- "parts" : {
123
- "release" : {
124
- "optional_value" : "gamma" ,
125
- "values" : ["dev" , "gamma" ],
126
- },
127
- },
128
- }
129
- conf , version_config , current_version = get_config_data (overrides )
130
-
131
- new_version = current_version .bump (bump_type )
132
- assert version_config .serialize (new_version , get_context (conf )) == expected
133
-
134
-
135
- @pytest .mark .parametrize (
136
- ["initial" , "bump_type" , "expected" ],
137
- [
138
- param ("1.alpha" , "release" , "1.beta" , id = "alpha-to-beta-release" ),
139
- param ("1.beta" , "release" , "1" , id = "beta-to-release" ),
140
- ],
141
- )
142
- def test_optional_value (initial : str , bump_type : str , expected : str ):
143
- overrides = {
144
- "current_version" : initial ,
145
- "parse" : r"(?P<num>\d+)(\.(?P<release>.*))?(\.)?" ,
146
- "serialize" : ["{num}.{release}" , "{num}" ],
147
- "parts" : {
148
- "release" : {
149
- "optional_value" : "gamma" ,
150
- "values" : ["alpha" , "beta" , "gamma" ],
151
- },
152
- },
153
- }
154
- conf , version_config , current_version = get_config_data (overrides )
155
-
156
- new_version = current_version .bump (bump_type )
157
- assert version_config .serialize (new_version , get_context (conf )) == expected
158
-
159
-
160
- @pytest .mark .parametrize (
161
- ["initial" , "bump_type" , "expected" ],
162
- [
163
- param ("1.0a" , "prerel" , "1.0b" , id = "a-to-b-release" ),
164
- param ("1.0b" , "prerelversion" , "1.0b1" , id = "prerelease-version" ),
165
- param ("1.0b1" , "prerelversion" , "1.0b2" , id = "prerelease-version2" ),
166
- param ("1.0b2" , "prerel" , "1.0c" , id = "b2-to-c-release" ),
167
- param ("1.0c" , "prerel" , "1.0rc" , id = "c-to-rc-release" ),
168
- param ("1.0rc" , "prerel" , "1.0" , id = "rc-to-d-release" ),
169
- param ("1.0" , "minor" , "1.1dev" , id = "minor-release" ),
170
- param ("1.1dev" , "prerel" , "1.1a" , id = "dev-to-a-release" ),
171
- ],
172
- )
173
- def test_python_pre_release_release_post_release (initial : str , bump_type : str , expected : str ):
174
- # adapted from http://legacy.python.org/dev/peps/pep-0386/#the-new-versioning-algorithm
175
- overrides = {
176
- "current_version" : initial ,
177
- "parse" : r"""^
178
- (?P<major>\d+)\.(?P<minor>\d+) # minimum 'N.N'
179
- (?:
180
- (?P<prerel>[abc]|rc|dev) # 'a' = alpha, 'b' = beta
181
- # 'c' or 'rc' = release candidate
182
- (?:
183
- (?P<prerelversion>\d+(?:\.\d+)*)
184
- )?
185
- )?
186
- (?P<postdev>(\.post(?P<post>\d+))?(\.dev(?P<dev>\d+))?)?""" ,
187
- "serialize" : [
188
- "{major}.{minor}{prerel}{prerelversion}" ,
189
- "{major}.{minor}{prerel}" ,
190
- "{major}.{minor}" ,
191
- ],
192
- "parts" : {
193
- "prerel" : {
194
- "optional_value" : "d" ,
195
- "values" : ["dev" , "a" , "b" , "c" , "rc" , "d" ],
196
- },
197
- },
198
- }
199
- conf , version_config , current_version = get_config_data (overrides )
200
-
201
- new_version = current_version .bump (bump_type )
202
- assert version_config .serialize (new_version , get_context (conf )) == expected
203
-
204
-
205
- @pytest .mark .parametrize (
206
- ["initial" , "bump_type" , "expected" ],
207
- [
208
- param ("0.9.4" , "major" , "1.1.0" , id = "first-value-1" ),
209
- ],
210
- )
211
- def test_part_first_value (initial : str , bump_type : str , expected : str ):
212
- overrides = {
213
- "current_version" : initial ,
214
- "parts" : {
215
- "minor" : {
216
- "first_value" : "1" ,
217
- },
218
- },
219
- }
220
- conf , version_config , current_version = get_config_data (overrides )
221
-
222
- new_version = current_version .bump (bump_type )
223
- assert version_config .serialize (new_version , get_context (conf )) == expected
224
-
225
-
226
77
def test_version_part_invalid_regex_exit (tmp_path : Path ) -> None :
227
78
"""A version part with an invalid regex should raise an exception."""
228
79
# Arrange
@@ -233,67 +84,3 @@ def test_version_part_invalid_regex_exit(tmp_path: Path) -> None:
233
84
with inside_dir (tmp_path ):
234
85
with pytest .raises (UsageError ):
235
86
get_config_data (overrides )
236
-
237
-
238
- def test_part_does_not_revert_to_zero_if_optional (tmp_path : Path ) -> None :
239
- """A non-numeric part with the optional value should not revert to zero."""
240
- # From https://github.com/c4urself/bump2version/issues/248
241
- # Arrange
242
- overrides = {
243
- "current_version" : "0.3.1" ,
244
- "parse" : r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>\D+)(?P<build>\d*))?" ,
245
- "serialize" : [
246
- "{major}.{minor}.{patch}{release}{build}" ,
247
- "{major}.{minor}.{patch}{release}" ,
248
- "{major}.{minor}.{patch}" ,
249
- ],
250
- "parts" : {
251
- "release" : {
252
- "optional_value" : "g" ,
253
- "first_value" : "g" ,
254
- "values" : [
255
- "dev" ,
256
- "a" ,
257
- "b" ,
258
- "g" ,
259
- ],
260
- },
261
- },
262
- }
263
- with inside_dir (tmp_path ):
264
- conf , version_config , current_version = get_config_data (overrides )
265
-
266
- new_version = current_version .bump ("build" )
267
- assert version_config .serialize (new_version , get_context (conf )) == "0.3.1g1"
268
-
269
-
270
- def test_order_of_serialization (tmp_path : Path , caplog : LogCaptureFixture ) -> None :
271
- """The order of serialization should be as specified in the config."""
272
- caplog .set_level (logging .DEBUG )
273
- overrides = {
274
- "current_version" : "3.16.dev1" ,
275
- "parse" : r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<release>[a-z]+)?(?P<patch>\d+)?" ,
276
- "serialize" : [
277
- "{major}.{minor}.{release}{patch}" ,
278
- "{major}.{minor}.{release}" ,
279
- "{major}.{minor}.{patch}" ,
280
- ],
281
- "parts" : {
282
- "release" : {
283
- "optional_value" : "prod" ,
284
- "first_value" : "dev" ,
285
- "values" : [
286
- "dev" ,
287
- "prod" ,
288
- ],
289
- },
290
- },
291
- }
292
- with inside_dir (tmp_path ):
293
- conf , version_config , current_version = get_config_data (overrides )
294
-
295
- new_version = current_version .bump ("release" )
296
- new_version_str = version_config .serialize (new_version , get_context (conf ))
297
- for msg in caplog .messages :
298
- print (msg )
299
- assert new_version_str == "3.16.prod"
0 commit comments