@@ -665,13 +665,15 @@ def test_get_updated_commit_message_with_trailers(
665
665
with mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ):
666
666
cherry_picker = CherryPicker ("origin" , commit , [])
667
667
668
- with mock .patch (
669
- "cherry_picker.cherry_picker.validate_sha" , return_value = True
670
- ), mock .patch .object (
671
- cherry_picker , "get_commit_message" , return_value = commit_message
672
- ), mock .patch (
673
- "cherry_picker.cherry_picker.get_author_info_from_short_sha" ,
674
- return_value = "PR Author <[email protected] >" ,
668
+ with (
669
+ mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ),
670
+ mock .patch .object (
671
+ cherry_picker , "get_commit_message" , return_value = commit_message
672
+ ),
673
+ mock .patch (
674
+ "cherry_picker.cherry_picker.get_author_info_from_short_sha" ,
675
+ return_value = "PR Author <[email protected] >" ,
676
+ ),
675
677
):
676
678
updated_commit_message = cherry_picker .get_updated_commit_message (
677
679
cherry_pick_branch
@@ -914,9 +916,10 @@ class tested_state:
914
916
r"stored in Git config using the following command: "
915
917
r"`git config --local --remove-section cherry-picker`"
916
918
)
917
- with mock .patch (
918
- "cherry_picker.cherry_picker.validate_sha" , return_value = True
919
- ), pytest .raises (InvalidRepoException , match = expected_msg_regexp ):
919
+ with (
920
+ mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ),
921
+ pytest .raises (InvalidRepoException , match = expected_msg_regexp ),
922
+ ):
920
923
CherryPicker ("origin" , "xxx" , [])
921
924
922
925
@@ -932,9 +935,11 @@ def test_push_to_remote_interactive(tmp_git_repo_dir):
932
935
with mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ):
933
936
cherry_picker = CherryPicker ("origin" , "xxx" , [])
934
937
935
- with mock .patch .object (cherry_picker , "run_cmd" ), mock .patch .object (
936
- cherry_picker , "open_pr"
937
- ), mock .patch .object (cherry_picker , "get_pr_url" , return_value = "https://pr_url" ):
938
+ with (
939
+ mock .patch .object (cherry_picker , "run_cmd" ),
940
+ mock .patch .object (cherry_picker , "open_pr" ),
941
+ mock .patch .object (cherry_picker , "get_pr_url" , return_value = "https://pr_url" ),
942
+ ):
938
943
cherry_picker .push_to_remote ("main" , "backport-branch-test" )
939
944
assert get_state () == WORKFLOW_STATES .PR_OPENING
940
945
@@ -944,8 +949,9 @@ def test_push_to_remote_botflow(tmp_git_repo_dir, monkeypatch):
944
949
with mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ):
945
950
cherry_picker = CherryPicker ("origin" , "xxx" , [])
946
951
947
- with mock .patch .object (cherry_picker , "run_cmd" ), mock .patch .object (
948
- cherry_picker , "create_gh_pr"
952
+ with (
953
+ mock .patch .object (cherry_picker , "run_cmd" ),
954
+ mock .patch .object (cherry_picker , "create_gh_pr" ),
949
955
):
950
956
cherry_picker .push_to_remote ("main" , "backport-branch-test" )
951
957
assert get_state () == WORKFLOW_STATES .PR_CREATING
@@ -956,8 +962,9 @@ def test_push_to_remote_no_auto_pr(tmp_git_repo_dir, monkeypatch):
956
962
with mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ):
957
963
cherry_picker = CherryPicker ("origin" , "xxx" , [], auto_pr = False )
958
964
959
- with mock .patch .object (cherry_picker , "run_cmd" ), mock .patch .object (
960
- cherry_picker , "create_gh_pr"
965
+ with (
966
+ mock .patch .object (cherry_picker , "run_cmd" ),
967
+ mock .patch .object (cherry_picker , "create_gh_pr" ),
961
968
):
962
969
cherry_picker .push_to_remote ("main" , "backport-branch-test" )
963
970
assert get_state () == WORKFLOW_STATES .PUSHED_TO_REMOTE
@@ -995,10 +1002,13 @@ def test_backport_cherry_pick_fail(
995
1002
pr_remote , scm_revision , cherry_pick_target_branches
996
1003
)
997
1004
998
- with pytest .raises (CherryPickException ), mock .patch .object (
999
- cherry_picker , "checkout_branch"
1000
- ), mock .patch .object (cherry_picker , "fetch_upstream" ), mock .patch .object (
1001
- cherry_picker , "cherry_pick" , side_effect = CherryPickException
1005
+ with (
1006
+ pytest .raises (CherryPickException ),
1007
+ mock .patch .object (cherry_picker , "checkout_branch" ),
1008
+ mock .patch .object (cherry_picker , "fetch_upstream" ),
1009
+ mock .patch .object (
1010
+ cherry_picker , "cherry_pick" , side_effect = CherryPickException
1011
+ ),
1002
1012
):
1003
1013
cherry_picker .backport ()
1004
1014
@@ -1027,13 +1037,16 @@ def test_backport_cherry_pick_crash_ignored(
1027
1037
pr_remote , scm_revision , cherry_pick_target_branches
1028
1038
)
1029
1039
1030
- with mock .patch .object (cherry_picker , "checkout_branch" ), mock .patch .object (
1031
- cherry_picker , "fetch_upstream"
1032
- ), mock .patch .object (cherry_picker , "cherry_pick" ), mock .patch .object (
1033
- cherry_picker ,
1034
- "amend_commit_message" ,
1035
- side_effect = subprocess .CalledProcessError (
1036
- 1 , ("git" , "commit" , "-am" , "new commit message" )
1040
+ with (
1041
+ mock .patch .object (cherry_picker , "checkout_branch" ),
1042
+ mock .patch .object (cherry_picker , "fetch_upstream" ),
1043
+ mock .patch .object (cherry_picker , "cherry_pick" ),
1044
+ mock .patch .object (
1045
+ cherry_picker ,
1046
+ "amend_commit_message" ,
1047
+ side_effect = subprocess .CalledProcessError (
1048
+ 1 , ("git" , "commit" , "-am" , "new commit message" )
1049
+ ),
1037
1050
),
1038
1051
):
1039
1052
cherry_picker .backport ()
@@ -1067,9 +1080,10 @@ def test_backport_cherry_pick_branch_already_exists(
1067
1080
)
1068
1081
git_branch (backport_branch_name )
1069
1082
1070
- with mock .patch .object (cherry_picker , "fetch_upstream" ), pytest .raises (
1071
- BranchCheckoutException
1072
- ) as exc_info :
1083
+ with (
1084
+ mock .patch .object (cherry_picker , "fetch_upstream" ),
1085
+ pytest .raises (BranchCheckoutException ) as exc_info ,
1086
+ ):
1073
1087
cherry_picker .backport ()
1074
1088
1075
1089
assert exc_info .value .branch_name == backport_branch_name
@@ -1098,10 +1112,12 @@ def test_backport_success(
1098
1112
pr_remote , scm_revision , cherry_pick_target_branches
1099
1113
)
1100
1114
1101
- with mock .patch .object (cherry_picker , "checkout_branch" ), mock .patch .object (
1102
- cherry_picker , "fetch_upstream"
1103
- ), mock .patch .object (
1104
- cherry_picker , "amend_commit_message" , return_value = "commit message"
1115
+ with (
1116
+ mock .patch .object (cherry_picker , "checkout_branch" ),
1117
+ mock .patch .object (cherry_picker , "fetch_upstream" ),
1118
+ mock .patch .object (
1119
+ cherry_picker , "amend_commit_message" , return_value = "commit message"
1120
+ ),
1105
1121
):
1106
1122
cherry_picker .backport ()
1107
1123
@@ -1141,8 +1157,11 @@ def test_backport_pause_and_continue(
1141
1157
pr_remote , scm_revision , cherry_pick_target_branches , push = False
1142
1158
)
1143
1159
1144
- with mock .patch .object (cherry_picker , "fetch_upstream" ), mock .patch .object (
1145
- cherry_picker , "amend_commit_message" , return_value = "commit message"
1160
+ with (
1161
+ mock .patch .object (cherry_picker , "fetch_upstream" ),
1162
+ mock .patch .object (
1163
+ cherry_picker , "amend_commit_message" , return_value = "commit message"
1164
+ ),
1146
1165
):
1147
1166
cherry_picker .backport ()
1148
1167
@@ -1164,26 +1183,26 @@ def test_backport_pause_and_continue(
1164
1183
1165
1184
Co-authored-by: Author Name <[email protected] >"""
1166
1185
1167
- with mock . patch (
1168
- "cherry_picker.cherry_picker.wipe_cfg_vals_from_git_cfg"
1169
- ), mock .patch (
1170
- "cherry_picker.cherry_picker.get_full_sha_from_short" ,
1171
- return_value = "xxxxxxyyyyyy" ,
1172
- ), mock . patch (
1173
- "cherry_picker.cherry_picker.get_base_branch" , return_value = "3.8"
1174
- ), mock .patch (
1175
- "cherry_picker.cherry_picker.get_current_branch" ,
1176
- return_value = "backport-xxx-3.8" ,
1177
- ), mock . patch . object (
1178
- cherry_picker , "amend_commit_message" , return_value = commit_message
1179
- ) as amend_commit_message , mock . patch . object (
1180
- cherry_picker , "get_updated_commit_message" , return_value = commit_message
1181
- ) as get_updated_commit_message , mock .patch .object (
1182
- cherry_picker , "checkout_branch"
1183
- ), mock . patch . object (
1184
- cherry_picker , "fetch_upstream"
1185
- ), mock .patch .object (
1186
- cherry_picker , "cleanup_branch"
1186
+ with (
1187
+ mock . patch ( "cherry_picker.cherry_picker.wipe_cfg_vals_from_git_cfg" ),
1188
+ mock .patch (
1189
+ "cherry_picker.cherry_picker.get_full_sha_from_short" ,
1190
+ return_value = "xxxxxxyyyyyy" ,
1191
+ ),
1192
+ mock . patch ( "cherry_picker.cherry_picker.get_base_branch" , return_value = "3.8" ),
1193
+ mock .patch (
1194
+ "cherry_picker.cherry_picker.get_current_branch" ,
1195
+ return_value = "backport-xxx-3.8" ,
1196
+ ),
1197
+ mock . patch . object (
1198
+ cherry_picker , " amend_commit_message" , return_value = commit_message
1199
+ ) as amend_commit_message ,
1200
+ mock .patch .object (
1201
+ cherry_picker , "get_updated_commit_message" , return_value = commit_message
1202
+ ) as get_updated_commit_message ,
1203
+ mock . patch . object ( cherry_picker , "checkout_branch" ),
1204
+ mock .patch .object (cherry_picker , "fetch_upstream" ),
1205
+ mock . patch . object ( cherry_picker , "cleanup_branch" ),
1187
1206
):
1188
1207
cherry_picker .continue_cherry_pick ()
1189
1208
0 commit comments