@@ -149,20 +149,20 @@ def tmp_git_repo_dir(tmpdir, cd, git_init, git_commit, git_config):
149
149
150
150
151
151
@mock .patch ("subprocess.check_output" )
152
- def test_get_base_branch (subprocess_check_output ):
152
+ def test_get_base_branch (subprocess_check_output , config ):
153
153
# The format of cherry-pick branches we create are::
154
154
# backport-{SHA}-{base_branch}
155
155
subprocess_check_output .return_value = b"22a594a0047d7706537ff2ac676cdc0f1dcb329c"
156
156
cherry_pick_branch = "backport-22a594a-2.7"
157
- result = get_base_branch (cherry_pick_branch )
157
+ result = get_base_branch (cherry_pick_branch , config = config )
158
158
assert result == "2.7"
159
159
160
160
161
161
@mock .patch ("subprocess.check_output" )
162
- def test_get_base_branch_which_has_dashes (subprocess_check_output ):
162
+ def test_get_base_branch_which_has_dashes (subprocess_check_output , config ):
163
163
subprocess_check_output .return_value = b"22a594a0047d7706537ff2ac676cdc0f1dcb329c"
164
164
cherry_pick_branch = "backport-22a594a-baseprefix-2.7-basesuffix"
165
- result = get_base_branch (cherry_pick_branch )
165
+ result = get_base_branch (cherry_pick_branch , config = config )
166
166
assert result == "baseprefix-2.7-basesuffix"
167
167
168
168
@@ -171,14 +171,14 @@ def test_get_base_branch_which_has_dashes(subprocess_check_output):
171
171
[
172
172
"backport-22a594a" , # Not enough fields
173
173
"prefix-22a594a-2.7" , # Not the prefix we were expecting
174
- "backport-22a594a-base " , # No version info in the base branch
174
+ "backport-22a594a-" , # No base branch
175
175
],
176
176
)
177
177
@mock .patch ("subprocess.check_output" )
178
- def test_get_base_branch_invalid (subprocess_check_output , cherry_pick_branch ):
178
+ def test_get_base_branch_invalid (subprocess_check_output , cherry_pick_branch , config ):
179
179
subprocess_check_output .return_value = b"22a594a0047d7706537ff2ac676cdc0f1dcb329c"
180
180
with pytest .raises (ValueError ):
181
- get_base_branch (cherry_pick_branch )
181
+ get_base_branch (cherry_pick_branch , config = config )
182
182
183
183
184
184
@mock .patch ("subprocess.check_output" )
@@ -206,18 +206,33 @@ def test_get_author_info_from_short_sha(subprocess_check_output):
206
206
207
207
208
208
@pytest .mark .parametrize (
209
- "input_branches,sorted_branches" ,
209
+ "input_branches,sorted_branches,require_version " ,
210
210
[
211
- (["3.1" , "2.7" , "3.10" , "3.6" ], ["3.10" , "3.6" , "3.1" , "2.7" ]),
211
+ (["3.1" , "2.7" , "3.10" , "3.6" ], ["3.10" , "3.6" , "3.1" , "2.7" ], True ),
212
212
(
213
213
["stable-3.1" , "lts-2.7" , "3.10-other" , "smth3.6else" ],
214
214
["3.10-other" , "smth3.6else" , "stable-3.1" , "lts-2.7" ],
215
+ True ,
216
+ ),
217
+ (["3.1" , "2.7" , "3.10" , "3.6" ], ["3.10" , "3.6" , "3.1" , "2.7" ], False ),
218
+ (
219
+ ["stable-3.1" , "lts-2.7" , "3.10-other" , "smth3.6else" ],
220
+ ["3.10-other" , "smth3.6else" , "stable-3.1" , "lts-2.7" ],
221
+ False ,
222
+ ),
223
+ (
224
+ ["3.7" , "3.10" , "2.7" , "foo" , "stable" , "branch" ],
225
+ ["3.10" , "3.7" , "2.7" , "branch" , "foo" , "stable" ],
226
+ False ,
215
227
),
216
228
],
217
229
)
218
230
@mock .patch ("os.path.exists" )
219
- def test_sorted_branch (os_path_exists , config , input_branches , sorted_branches ):
231
+ def test_sorted_branch (
232
+ os_path_exists , config , input_branches , sorted_branches , require_version
233
+ ):
220
234
os_path_exists .return_value = True
235
+ config ["require_version_in_branch_name" ] = require_version
221
236
cp = CherryPicker (
222
237
"origin" ,
223
238
"22a594a0047d7706537ff2ac676cdc0f1dcb329c" ,
@@ -227,6 +242,21 @@ def test_sorted_branch(os_path_exists, config, input_branches, sorted_branches):
227
242
assert cp .sorted_branches == sorted_branches
228
243
229
244
245
+ @mock .patch ("os.path.exists" )
246
+ def test_invalid_branch_empty_string (os_path_exists , config ):
247
+ os_path_exists .return_value = True
248
+ # already tested for require_version_in_branch_name=True below
249
+ config ["require_version_in_branch_name" ] = False
250
+ cp = CherryPicker (
251
+ "origin" ,
252
+ "22a594a0047d7706537ff2ac676cdc0f1dcb329c" ,
253
+ ["3.1" , "2.7" , "3.10" , "3.6" , "" ],
254
+ config = config ,
255
+ )
256
+ with pytest .raises (ValueError , match = r"^Branch name is an empty string\.$" ):
257
+ cp .sorted_branches
258
+
259
+
230
260
@pytest .mark .parametrize (
231
261
"input_branches" ,
232
262
[
@@ -460,6 +490,7 @@ def test_load_full_config(tmp_git_repo_dir, git_add, git_commit):
460
490
"team" : "python" ,
461
491
"fix_commit_msg" : True ,
462
492
"default_branch" : "devel" ,
493
+ "require_version_in_branch_name" : True ,
463
494
},
464
495
)
465
496
@@ -483,6 +514,7 @@ def test_load_partial_config(tmp_git_repo_dir, git_add, git_commit):
483
514
"team" : "python" ,
484
515
"fix_commit_msg" : True ,
485
516
"default_branch" : "main" ,
517
+ "require_version_in_branch_name" : True ,
486
518
},
487
519
)
488
520
@@ -511,6 +543,7 @@ def test_load_config_no_head_sha(tmp_git_repo_dir, git_add, git_commit):
511
543
"team" : "python" ,
512
544
"fix_commit_msg" : True ,
513
545
"default_branch" : "devel" ,
546
+ "require_version_in_branch_name" : True ,
514
547
},
515
548
)
516
549
0 commit comments