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
33
34
34
35
35
36
@patch ("subprocess.check_call" )
36
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
37
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
37
38
@patch ("os.path.isfile" , return_value = True )
38
39
@patch ("os.path.isdir" , return_value = True )
39
40
@patch ("os.path.exists" , return_value = True )
@@ -87,7 +88,7 @@ def test_git_clone_repo_git_argument_wrong_format():
87
88
returncode = 1 , cmd = "git clone {} {}" .format (PUBLIC_GIT_REPO , REPO_DIR )
88
89
),
89
90
)
90
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
91
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
91
92
def test_git_clone_repo_clone_fail (mkdtemp , check_call ):
92
93
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
93
94
entry_point = "entry_point"
@@ -102,7 +103,7 @@ def test_git_clone_repo_clone_fail(mkdtemp, check_call):
102
103
"subprocess.check_call" ,
103
104
side_effect = [True , subprocess .CalledProcessError (returncode = 1 , cmd = "git checkout banana" )],
104
105
)
105
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
106
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
106
107
def test_git_clone_repo_branch_not_exist (mkdtemp , check_call ):
107
108
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
108
109
entry_point = "entry_point"
@@ -121,7 +122,7 @@ def test_git_clone_repo_branch_not_exist(mkdtemp, check_call):
121
122
subprocess .CalledProcessError (returncode = 1 , cmd = "git checkout {}" .format (PUBLIC_COMMIT )),
122
123
],
123
124
)
124
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
125
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
125
126
def test_git_clone_repo_commit_not_exist (mkdtemp , check_call ):
126
127
git_config = {"repo" : PUBLIC_GIT_REPO , "branch" : PUBLIC_BRANCH , "commit" : PUBLIC_COMMIT }
127
128
entry_point = "entry_point"
@@ -133,7 +134,7 @@ def test_git_clone_repo_commit_not_exist(mkdtemp, check_call):
133
134
134
135
135
136
@patch ("subprocess.check_call" )
136
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
137
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
137
138
@patch ("os.path.isfile" , return_value = False )
138
139
@patch ("os.path.isdir" , return_value = True )
139
140
@patch ("os.path.exists" , return_value = True )
@@ -148,7 +149,7 @@ def test_git_clone_repo_entry_point_not_exist(exists, isdir, isfile, mkdtemp, he
148
149
149
150
150
151
@patch ("subprocess.check_call" )
151
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
152
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
152
153
@patch ("os.path.isfile" , return_value = True )
153
154
@patch ("os.path.isdir" , return_value = False )
154
155
@patch ("os.path.exists" , return_value = True )
@@ -163,7 +164,7 @@ def test_git_clone_repo_source_dir_not_exist(exists, isdir, isfile, mkdtemp, che
163
164
164
165
165
166
@patch ("subprocess.check_call" )
166
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
167
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
167
168
@patch ("os.path.isfile" , return_value = True )
168
169
@patch ("os.path.isdir" , return_value = True )
169
170
@patch ("os.path.exists" , side_effect = [True , False ])
@@ -178,7 +179,7 @@ def test_git_clone_repo_dependencies_not_exist(exists, isdir, isfile, mkdtemp, c
178
179
179
180
180
181
@patch ("subprocess.check_call" )
181
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
182
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
182
183
@patch ("os.path.isfile" , return_value = True )
183
184
def test_git_clone_repo_with_username_password_no_2fa (isfile , mkdtemp , check_call ):
184
185
git_config = {
@@ -209,7 +210,7 @@ def test_git_clone_repo_with_username_password_no_2fa(isfile, mkdtemp, check_cal
209
210
210
211
211
212
@patch ("subprocess.check_call" )
212
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
213
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
213
214
@patch ("os.path.isfile" , return_value = True )
214
215
def test_git_clone_repo_with_token_no_2fa (isfile , mkdtemp , check_call ):
215
216
git_config = {
@@ -235,7 +236,7 @@ def test_git_clone_repo_with_token_no_2fa(isfile, mkdtemp, check_call):
235
236
236
237
237
238
@patch ("subprocess.check_call" )
238
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
239
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
239
240
@patch ("os.path.isfile" , return_value = True )
240
241
def test_git_clone_repo_with_token_2fa (isfile , mkdtemp , check_call ):
241
242
git_config = {
@@ -263,9 +264,10 @@ def test_git_clone_repo_with_token_2fa(isfile, mkdtemp, check_call):
263
264
264
265
@patch ("subprocess.check_call" )
265
266
@patch ("os.chmod" )
266
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
267
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
267
268
@patch ("os.path.isfile" , return_value = True )
268
269
def test_git_clone_repo_ssh (isfile , mkdtemp , chmod , check_call ):
270
+ Path (REPO_DIR ).mkdir (parents = True , exist_ok = True )
269
271
git_config = {"repo" : PRIVATE_GIT_REPO_SSH , "branch" : PRIVATE_BRANCH , "commit" : PRIVATE_COMMIT }
270
272
entry_point = "entry_point"
271
273
ret = git_utils .git_clone_repo (git_config , entry_point )
@@ -276,7 +278,7 @@ def test_git_clone_repo_ssh(isfile, mkdtemp, chmod, check_call):
276
278
277
279
278
280
@patch ("subprocess.check_call" )
279
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
281
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
280
282
@patch ("os.path.isfile" , return_value = True )
281
283
def test_git_clone_repo_with_token_no_2fa_unnecessary_creds_provided (isfile , mkdtemp , check_call ):
282
284
git_config = {
@@ -308,7 +310,7 @@ def test_git_clone_repo_with_token_no_2fa_unnecessary_creds_provided(isfile, mkd
308
310
309
311
310
312
@patch ("subprocess.check_call" )
311
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
313
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
312
314
@patch ("os.path.isfile" , return_value = True )
313
315
def test_git_clone_repo_with_token_2fa_unnecessary_creds_provided (isfile , mkdtemp , check_call ):
314
316
git_config = {
@@ -345,7 +347,7 @@ def test_git_clone_repo_with_token_2fa_unnecessary_creds_provided(isfile, mkdtem
345
347
returncode = 1 , cmd = "git clone {} {}" .format (PRIVATE_GIT_REPO , REPO_DIR )
346
348
),
347
349
)
348
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
350
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
349
351
def test_git_clone_repo_with_username_and_password_wrong_creds (mkdtemp , check_call ):
350
352
git_config = {
351
353
"repo" : PRIVATE_GIT_REPO ,
@@ -369,7 +371,7 @@ def test_git_clone_repo_with_username_and_password_wrong_creds(mkdtemp, check_ca
369
371
returncode = 1 , cmd = "git clone {} {}" .format (PRIVATE_GIT_REPO , REPO_DIR )
370
372
),
371
373
)
372
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
374
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
373
375
def test_git_clone_repo_with_token_wrong_creds (mkdtemp , check_call ):
374
376
git_config = {
375
377
"repo" : PRIVATE_GIT_REPO ,
@@ -392,7 +394,7 @@ def test_git_clone_repo_with_token_wrong_creds(mkdtemp, check_call):
392
394
returncode = 1 , cmd = "git clone {} {}" .format (PRIVATE_GIT_REPO , REPO_DIR )
393
395
),
394
396
)
395
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
397
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
396
398
def test_git_clone_repo_with_and_token_2fa_wrong_creds (mkdtemp , check_call ):
397
399
git_config = {
398
400
"repo" : PRIVATE_GIT_REPO ,
@@ -410,7 +412,7 @@ def test_git_clone_repo_with_and_token_2fa_wrong_creds(mkdtemp, check_call):
410
412
411
413
412
414
@patch ("subprocess.check_call" )
413
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
415
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
414
416
@patch ("os.path.isfile" , return_value = True )
415
417
def test_git_clone_repo_codecommit_https_with_username_and_password (isfile , mkdtemp , check_call ):
416
418
git_config = {
@@ -444,7 +446,7 @@ def test_git_clone_repo_codecommit_https_with_username_and_password(isfile, mkdt
444
446
returncode = 128 , cmd = "git clone {} {}" .format (CODECOMMIT_REPO_SSH , REPO_DIR )
445
447
),
446
448
)
447
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
449
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
448
450
def test_git_clone_repo_codecommit_ssh_passphrase_required (mkdtemp , check_call ):
449
451
git_config = {"repo" : CODECOMMIT_REPO_SSH , "branch" : CODECOMMIT_BRANCH }
450
452
entry_point = "entry_point"
@@ -459,7 +461,7 @@ def test_git_clone_repo_codecommit_ssh_passphrase_required(mkdtemp, check_call):
459
461
returncode = 128 , cmd = "git clone {} {}" .format (CODECOMMIT_REPO , REPO_DIR )
460
462
),
461
463
)
462
- @patch ("tempfile.mkdtemp " , return_value = REPO_DIR )
464
+ @patch ("tempfile.TemporaryDirectory " , return_value = REPO_DIR )
463
465
def test_git_clone_repo_codecommit_https_creds_not_stored_locally (mkdtemp , check_call ):
464
466
git_config = {"repo" : CODECOMMIT_REPO , "branch" : CODECOMMIT_BRANCH }
465
467
entry_point = "entry_point"
0 commit comments