1010 get_full_sha_from_short , get_author_info_from_short_sha , \
1111 CherryPicker , InvalidRepoException , \
1212 normalize_commit_message , DEFAULT_CONFIG , \
13- get_sha1_from , find_config , load_config
13+ get_sha1_from , find_config , load_config , validate_sha
1414
1515
1616@pytest .fixture
@@ -116,16 +116,22 @@ def test_get_cherry_pick_branch(os_path_exists, config):
116116 assert cp .get_cherry_pick_branch ("3.6" ) == "backport-22a594a-3.6"
117117
118118
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 ):
124120 branches = ["3.6" ]
125121 cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
126122 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
129135
130136
131137@pytest .mark .parametrize ('url' , [
@@ -137,42 +143,44 @@ def test_get_pr_url(subprocess_check_output, os_path_exists, config):
137143 b'https://github.com/mock_user/cpython' ,
138144 ])
139145def test_username (url , config ):
146+ branches = ["3.6" ]
147+ cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
148+ branches , config = config )
140149 with mock .patch ('subprocess.check_output' , return_value = url ):
141- branches = ["3.6" ]
142- cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
143- branches , config = config )
144150 assert cp .username == 'mock_user'
145151
146152
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 ):
153154 branches = ["3.6" ]
154155 cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
155156 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)'
158165
159166
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 ):
166168 config ['fix_commit_msg' ] = False
167169 branches = ["3.6" ]
168170 cp = CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
169171 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)'
172180
173181
174182@mock .patch ('subprocess.check_output' )
175- def test_is_cpython_repo (subprocess_check_output , config ):
183+ def test_is_cpython_repo (subprocess_check_output ):
176184 subprocess_check_output .return_value = """commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f
177185Author: Guido van Rossum <[email protected] > 178186Date: Thu Aug 9 14:25:15 1990 +0000
@@ -181,8 +189,7 @@ def test_is_cpython_repo(subprocess_check_output, config):
181189
182190"""
183191 # should not raise an exception
184- CherryPicker ('origin' , '22a594a0047d7706537ff2ac676cdc0f1dcb329c' ,
185- ["3.6" ], config = config )
192+ validate_sha ('22a594a0047d7706537ff2ac676cdc0f1dcb329c' )
186193
187194
188195def test_is_not_cpython_repo ():
@@ -240,6 +247,8 @@ def test_load_full_config(tmpdir, cd):
240247
241248
242249def test_load_partial_config (tmpdir , cd ):
250+ cd (tmpdir )
251+ subprocess .run ('git init .' .split (), check = True )
243252 relative_config_path = '.cherry_picker.toml'
244253 cfg = tmpdir .join (relative_config_path )
245254 cfg .write ('''\
0 commit comments