14
14
15
15
import pytest
16
16
import os
17
+ from pathlib import Path
17
18
import subprocess
18
19
from mock import patch , ANY
19
20
34
35
35
36
@patch ("subprocess.check_call" )
36
37
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
38
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
37
39
@patch ("os.path.isfile" , return_value = True )
38
40
@patch ("os.path.isdir" , return_value = True )
39
41
@patch ("os.path.exists" , return_value = True )
40
- def test_git_clone_repo_succeed (exists , isdir , isfile , mkdtemp , check_call ):
42
+ def test_git_clone_repo_succeed (exists , isdir , isfile , tempdir , mkdtemp , check_call ):
41
43
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
42
44
entry_point = "entry_point"
43
45
source_dir = "source_dir"
@@ -88,7 +90,8 @@ def test_git_clone_repo_git_argument_wrong_format():
88
90
),
89
91
)
90
92
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
91
- def test_git_clone_repo_clone_fail (mkdtemp , check_call ):
93
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
94
+ def test_git_clone_repo_clone_fail (tempdir , mkdtemp , check_call ):
92
95
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
93
96
entry_point = "entry_point"
94
97
source_dir = "source_dir"
@@ -103,7 +106,8 @@ def test_git_clone_repo_clone_fail(mkdtemp, check_call):
103
106
side_effect = [True , subprocess .CalledProcessError (returncode = 1 , cmd = "git checkout banana" )],
104
107
)
105
108
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
106
- def test_git_clone_repo_branch_not_exist (mkdtemp , check_call ):
109
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
110
+ def test_git_clone_repo_branch_not_exist (tempdir , mkdtemp , check_call ):
107
111
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
108
112
entry_point = "entry_point"
109
113
source_dir = "source_dir"
@@ -122,7 +126,8 @@ def test_git_clone_repo_branch_not_exist(mkdtemp, check_call):
122
126
],
123
127
)
124
128
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
125
- def test_git_clone_repo_commit_not_exist (mkdtemp , check_call ):
129
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
130
+ def test_git_clone_repo_commit_not_exist (tempdir , mkdtemp , check_call ):
126
131
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
127
132
entry_point = "entry_point"
128
133
source_dir = "source_dir"
@@ -134,10 +139,11 @@ def test_git_clone_repo_commit_not_exist(mkdtemp, check_call):
134
139
135
140
@patch ("subprocess.check_call" )
136
141
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
142
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
137
143
@patch ("os.path.isfile" , return_value = False )
138
144
@patch ("os.path.isdir" , return_value = True )
139
145
@patch ("os.path.exists" , return_value = True )
140
- def test_git_clone_repo_entry_point_not_exist (exists , isdir , isfile , mkdtemp , heck_call ):
146
+ def test_git_clone_repo_entry_point_not_exist (exists , isdir , isfile , tempdir , mkdtemp , heck_call ):
141
147
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
142
148
entry_point = "entry_point_that_does_not_exist"
143
149
source_dir = "source_dir"
@@ -149,10 +155,11 @@ def test_git_clone_repo_entry_point_not_exist(exists, isdir, isfile, mkdtemp, he
149
155
150
156
@patch ("subprocess.check_call" )
151
157
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
158
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
152
159
@patch ("os.path.isfile" , return_value = True )
153
160
@patch ("os.path.isdir" , return_value = False )
154
161
@patch ("os.path.exists" , return_value = True )
155
- def test_git_clone_repo_source_dir_not_exist (exists , isdir , isfile , mkdtemp , check_call ):
162
+ def test_git_clone_repo_source_dir_not_exist (exists , isdir , isfile , tempdir , mkdtemp , check_call ):
156
163
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
157
164
entry_point = "entry_point"
158
165
source_dir = "source_dir_that_does_not_exist"
@@ -164,10 +171,11 @@ def test_git_clone_repo_source_dir_not_exist(exists, isdir, isfile, mkdtemp, che
164
171
165
172
@patch ("subprocess.check_call" )
166
173
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
174
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
167
175
@patch ("os.path.isfile" , return_value = True )
168
176
@patch ("os.path.isdir" , return_value = True )
169
177
@patch ("os.path.exists" , side_effect = [True , False ])
170
- def test_git_clone_repo_dependencies_not_exist (exists , isdir , isfile , mkdtemp , check_call ):
178
+ def test_git_clone_repo_dependencies_not_exist (exists , isdir , isfile , tempdir , mkdtemp , check_call ):
171
179
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
172
180
entry_point = "entry_point"
173
181
source_dir = "source_dir"
@@ -179,8 +187,9 @@ def test_git_clone_repo_dependencies_not_exist(exists, isdir, isfile, mkdtemp, c
179
187
180
188
@patch ("subprocess.check_call" )
181
189
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
190
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
182
191
@patch ("os.path.isfile" , return_value = True )
183
- def test_git_clone_repo_with_username_password_no_2fa (isfile , mkdtemp , check_call ):
192
+ def test_git_clone_repo_with_username_password_no_2fa (isfile , tempdir , mkdtemp , check_call ):
184
193
git_config = {
185
194
"repo" : PRIVATE_GIT_REPO ,
186
195
"branch" : PRIVATE_BRANCH ,
@@ -210,8 +219,9 @@ def test_git_clone_repo_with_username_password_no_2fa(isfile, mkdtemp, check_cal
210
219
211
220
@patch ("subprocess.check_call" )
212
221
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
222
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
213
223
@patch ("os.path.isfile" , return_value = True )
214
- def test_git_clone_repo_with_token_no_2fa (isfile , mkdtemp , check_call ):
224
+ def test_git_clone_repo_with_token_no_2fa (isfile , tempdir , mkdtemp , check_call ):
215
225
git_config = {
216
226
"repo" : PRIVATE_GIT_REPO ,
217
227
"branch" : PRIVATE_BRANCH ,
@@ -236,8 +246,9 @@ def test_git_clone_repo_with_token_no_2fa(isfile, mkdtemp, check_call):
236
246
237
247
@patch ("subprocess.check_call" )
238
248
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
249
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
239
250
@patch ("os.path.isfile" , return_value = True )
240
- def test_git_clone_repo_with_token_2fa (isfile , mkdtemp , check_call ):
251
+ def test_git_clone_repo_with_token_2fa (isfile , tempdirm , mkdtemp , check_call ):
241
252
git_config = {
242
253
"repo" : PRIVATE_GIT_REPO ,
243
254
"branch" : PRIVATE_BRANCH ,
@@ -264,8 +275,10 @@ def test_git_clone_repo_with_token_2fa(isfile, mkdtemp, check_call):
264
275
@patch ("subprocess.check_call" )
265
276
@patch ("os.chmod" )
266
277
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
278
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
267
279
@patch ("os.path.isfile" , return_value = True )
268
- def test_git_clone_repo_ssh (isfile , mkdtemp , chmod , check_call ):
280
+ def test_git_clone_repo_ssh (isfile , tempdir , mkdtemp , chmod , check_call ):
281
+ Path (REPO_DIR ).mkdir (parents = True , exist_ok = True )
269
282
git_config = {"repo" : PRIVATE_GIT_REPO_SSH , "branch" : PRIVATE_BRANCH , "commit" : PRIVATE_COMMIT }
270
283
entry_point = "entry_point"
271
284
ret = git_utils .git_clone_repo (git_config , entry_point )
@@ -277,8 +290,9 @@ def test_git_clone_repo_ssh(isfile, mkdtemp, chmod, check_call):
277
290
278
291
@patch ("subprocess.check_call" )
279
292
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
293
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
280
294
@patch ("os.path.isfile" , return_value = True )
281
- def test_git_clone_repo_with_token_no_2fa_unnecessary_creds_provided (isfile , mkdtemp , check_call ):
295
+ def test_git_clone_repo_with_token_no_2fa_unnecessary_creds_provided (isfile , tempdir , mkdtemp , check_call ):
282
296
git_config = {
283
297
"repo" : PRIVATE_GIT_REPO ,
284
298
"branch" : PRIVATE_BRANCH ,
@@ -309,8 +323,9 @@ def test_git_clone_repo_with_token_no_2fa_unnecessary_creds_provided(isfile, mkd
309
323
310
324
@patch ("subprocess.check_call" )
311
325
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
326
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
312
327
@patch ("os.path.isfile" , return_value = True )
313
- def test_git_clone_repo_with_token_2fa_unnecessary_creds_provided (isfile , mkdtemp , check_call ):
328
+ def test_git_clone_repo_with_token_2fa_unnecessary_creds_provided (isfile , tempdir , mkdtemp , check_call ):
314
329
git_config = {
315
330
"repo" : PRIVATE_GIT_REPO ,
316
331
"branch" : PRIVATE_BRANCH ,
@@ -346,7 +361,8 @@ def test_git_clone_repo_with_token_2fa_unnecessary_creds_provided(isfile, mkdtem
346
361
),
347
362
)
348
363
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
349
- def test_git_clone_repo_with_username_and_password_wrong_creds (mkdtemp , check_call ):
364
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
365
+ def test_git_clone_repo_with_username_and_password_wrong_creds (tempdir , mkdtemp , check_call ):
350
366
git_config = {
351
367
"repo" : PRIVATE_GIT_REPO ,
352
368
"branch" : PRIVATE_BRANCH ,
@@ -370,7 +386,8 @@ def test_git_clone_repo_with_username_and_password_wrong_creds(mkdtemp, check_ca
370
386
),
371
387
)
372
388
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
373
- def test_git_clone_repo_with_token_wrong_creds (mkdtemp , check_call ):
389
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
390
+ def test_git_clone_repo_with_token_wrong_creds (tempdir , mkdtemp , check_call ):
374
391
git_config = {
375
392
"repo" : PRIVATE_GIT_REPO ,
376
393
"branch" : PRIVATE_BRANCH ,
@@ -393,7 +410,8 @@ def test_git_clone_repo_with_token_wrong_creds(mkdtemp, check_call):
393
410
),
394
411
)
395
412
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
396
- def test_git_clone_repo_with_and_token_2fa_wrong_creds (mkdtemp , check_call ):
413
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
414
+ def test_git_clone_repo_with_and_token_2fa_wrong_creds (tempdir , mkdtemp , check_call ):
397
415
git_config = {
398
416
"repo" : PRIVATE_GIT_REPO ,
399
417
"branch" : PRIVATE_BRANCH ,
@@ -411,8 +429,9 @@ def test_git_clone_repo_with_and_token_2fa_wrong_creds(mkdtemp, check_call):
411
429
412
430
@patch ("subprocess.check_call" )
413
431
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
432
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
414
433
@patch ("os.path.isfile" , return_value = True )
415
- def test_git_clone_repo_codecommit_https_with_username_and_password (isfile , mkdtemp , check_call ):
434
+ def test_git_clone_repo_codecommit_https_with_username_and_password (isfile , tempdir , mkdtemp , check_call ):
416
435
git_config = {
417
436
"repo" : CODECOMMIT_REPO ,
418
437
"branch" : CODECOMMIT_BRANCH ,
@@ -445,7 +464,9 @@ def test_git_clone_repo_codecommit_https_with_username_and_password(isfile, mkdt
445
464
),
446
465
)
447
466
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
448
- def test_git_clone_repo_codecommit_ssh_passphrase_required (mkdtemp , check_call ):
467
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
468
+ def test_git_clone_repo_codecommit_ssh_passphrase_required (tempdir , mkdtemp , check_call ):
469
+ Path (REPO_DIR ).mkdir (parents = True , exist_ok = True )
449
470
git_config = {"repo" : CODECOMMIT_REPO_SSH , "branch" : CODECOMMIT_BRANCH }
450
471
entry_point = "entry_point"
451
472
with pytest .raises (subprocess .CalledProcessError ) as error :
@@ -460,7 +481,8 @@ def test_git_clone_repo_codecommit_ssh_passphrase_required(mkdtemp, check_call):
460
481
),
461
482
)
462
483
@patch ("tempfile.mkdtemp" , return_value = REPO_DIR )
463
- def test_git_clone_repo_codecommit_https_creds_not_stored_locally (mkdtemp , check_call ):
484
+ @patch ("tempfile.TemporaryDirectory.__enter__" , return_value = REPO_DIR )
485
+ def test_git_clone_repo_codecommit_https_creds_not_stored_locally (tempdir , mkdtemp , check_call ):
464
486
git_config = {"repo" : CODECOMMIT_REPO , "branch" : CODECOMMIT_BRANCH }
465
487
entry_point = "entry_point"
466
488
with pytest .raises (subprocess .CalledProcessError ) as error :
0 commit comments