10
10
get_full_sha_from_short , get_author_info_from_short_sha , \
11
11
CherryPicker , InvalidRepoException , \
12
12
normalize_commit_message , DEFAULT_CONFIG , \
13
- get_sha1_from , find_config , load_config
13
+ get_sha1_from , find_config , load_config , validate_sha
14
14
15
15
16
16
@pytest .fixture
@@ -116,16 +116,22 @@ def test_get_cherry_pick_branch(os_path_exists, config):
116
116
assert cp .get_cherry_pick_branch ("3.6" ) == "backport-22a594a-3.6"
117
117
118
118
119
- @mock .patch ('os.path.exists' )
120
- @mock .patch ('subprocess.check_output' )
121
- def test_get_pr_url (subprocess_check_output , os_path_exists , config ):
122
- os_path_exists .return_value = True
123
- subprocess_check_output .return_value = b'https://github.com/mock_user/cpython.git'
119
+ def test_get_pr_url (config ):
124
120
branches = ["3.6" ]
125
121
cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
126
122
branches , config = config )
127
- assert cp .get_pr_url ("3.6" , cp .get_cherry_pick_branch ("3.6" )) \
128
- == "https://github.com/python/cpython/compare/3.6...mock_user:backport-22a594a-3.6?expand=1"
123
+ backport_target_branch = cp .get_cherry_pick_branch ("3.6" )
124
+ expected_pr_url = (
125
+ 'https://github.com/python/cpython/compare/'
126
+ '3.6...mock_user:backport-22a594a-3.6?expand=1'
127
+ )
128
+ with mock .patch (
129
+ 'subprocess.check_output' ,
130
+ return_value = b'https://github.com/mock_user/cpython.git' ,
131
+ ):
132
+ actual_pr_url = cp .get_pr_url ("3.6" , backport_target_branch )
133
+
134
+ assert actual_pr_url == expected_pr_url
129
135
130
136
131
137
@pytest .mark .parametrize ('url' , [
@@ -137,42 +143,44 @@ def test_get_pr_url(subprocess_check_output, os_path_exists, config):
137
143
b'https://github.com/mock_user/cpython' ,
138
144
])
139
145
def test_username (url , config ):
146
+ branches = ["3.6" ]
147
+ cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
148
+ branches , config = config )
140
149
with mock .patch ('subprocess.check_output' , return_value = url ):
141
- branches = ["3.6" ]
142
- cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
143
- branches , config = config )
144
150
assert cp .username == 'mock_user'
145
151
146
152
147
- @mock .patch ('os.path.exists' )
148
- @mock .patch ('subprocess.check_output' )
149
- def test_get_updated_commit_message (subprocess_check_output , os_path_exists ,
150
- config ):
151
- os_path_exists .return_value = True
152
- subprocess_check_output .return_value = b'bpo-123: Fix Spam Module (#113)'
153
+ def test_get_updated_commit_message (config ):
153
154
branches = ["3.6" ]
154
155
cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
155
156
branches , config = config )
156
- assert cp .get_commit_message ('22a594a0047d7706537ff2ac676cdc0f1dcb329c' ) \
157
- == 'bpo-123: Fix Spam Module (GH-113)'
157
+ with mock .patch (
158
+ 'subprocess.check_output' ,
159
+ return_value = b'bpo-123: Fix Spam Module (#113)' ,
160
+ ):
161
+ actual_commit_message = (
162
+ cp .get_commit_message ('22a594a0047d7706537ff2ac676cdc0f1dcb329c' )
163
+ )
164
+ assert actual_commit_message == 'bpo-123: Fix Spam Module (GH-113)'
158
165
159
166
160
- @mock .patch ('os.path.exists' )
161
- @mock .patch ('subprocess.check_output' )
162
- def test_get_updated_commit_message_without_links_replacement (
163
- subprocess_check_output , os_path_exists , config ):
164
- os_path_exists .return_value = True
165
- subprocess_check_output .return_value = b'bpo-123: Fix Spam Module (#113)'
167
+ def test_get_updated_commit_message_without_links_replacement (config ):
166
168
config ['fix_commit_msg' ] = False
167
169
branches = ["3.6" ]
168
170
cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
169
171
branches , config = config )
170
- assert cp .get_commit_message ('22a594a0047d7706537ff2ac676cdc0f1dcb329c' ) \
171
- == 'bpo-123: Fix Spam Module (#113)'
172
+ with mock .patch (
173
+ 'subprocess.check_output' ,
174
+ return_value = b'bpo-123: Fix Spam Module (#113)' ,
175
+ ):
176
+ actual_commit_message = (
177
+ cp .get_commit_message ('22a594a0047d7706537ff2ac676cdc0f1dcb329c' )
178
+ )
179
+ assert actual_commit_message == 'bpo-123: Fix Spam Module (#113)'
172
180
173
181
174
182
@mock .patch ('subprocess.check_output' )
175
- def test_is_cpython_repo (subprocess_check_output , config ):
183
+ def test_is_cpython_repo (subprocess_check_output ):
176
184
subprocess_check_output .return_value = """commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f
177
185
Author: Guido van Rossum <guido@python.org>
178
186
Date: Thu Aug 9 14:25:15 1990 +0000
@@ -181,8 +189,7 @@ def test_is_cpython_repo(subprocess_check_output, config):
181
189
182
190
"""
183
191
# should not raise an exception
184
- CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
185
- ["3.6" ], config = config )
192
+ validate_sha ('22a594a0047d7706537ff2ac676cdc0f1dcb329c' )
186
193
187
194
188
195
def test_is_not_cpython_repo ():
@@ -240,6 +247,8 @@ def test_load_full_config(tmpdir, cd):
240
247
241
248
242
249
def test_load_partial_config (tmpdir , cd ):
250
+ cd (tmpdir )
251
+ subprocess .run ('git init .' .split (), check = True )
243
252
relative_config_path = '.cherry_picker.toml'
244
253
cfg = tmpdir .join (relative_config_path )
245
254
cfg .write ('''\
0 commit comments