26
26
27
27
@patch ('subprocess.check_call' )
28
28
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
29
- @patch ('sagemaker.git_utils._validate_git_config' )
30
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' )
31
29
@patch ('os.path.isfile' , return_value = True )
32
30
@patch ('os.path.isdir' , return_value = True )
33
31
@patch ('os.path.exists' , return_value = True )
34
- def test_git_clone_repo_succeed (exists , isdir , isfile , checkout_branch_and_commit ,
35
- validate_git_config , mkdtemp , check_call ):
32
+ def test_git_clone_repo_succeed (exists , isdir , isfile , mkdtemp , check_call ):
36
33
git_config = {'repo' : GIT_REPO , 'branch' : BRANCH , 'commit' : COMMIT }
37
34
entry_point = 'entry_point'
38
35
source_dir = 'source_dir'
39
36
dependencies = ['foo' , 'bar' ]
40
37
ret = git_utils .git_clone_repo (git_config , entry_point , source_dir , dependencies )
41
- validate_git_config .assert_called_with (git_config )
42
- check_call .assert_called_with (['git' , 'clone' , git_config ['repo' ], REPO_DIR ])
38
+ check_call .assert_any_call (['git' , 'clone' , git_config ['repo' ], REPO_DIR ])
39
+ check_call .assert_any_call (args = ['git' , 'checkout' , BRANCH ], cwd = REPO_DIR )
40
+ check_call .assert_any_call (args = ['git' , 'checkout' , COMMIT ], cwd = REPO_DIR )
43
41
mkdtemp .assert_called_once ()
44
- checkout_branch_and_commit .assert_called_with (git_config , REPO_DIR )
45
42
assert ret ['entry_point' ] == 'entry_point'
46
43
assert ret ['source_dir' ] == '/tmp/repo_dir/source_dir'
47
44
assert ret ['dependencies' ] == ['/tmp/repo_dir/foo' , '/tmp/repo_dir/bar' ]
48
45
49
46
50
47
@patch ('subprocess.check_call' )
51
48
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
52
- @patch ('sagemaker.git_utils._validate_git_config' ,
53
- side_effect = ValueError ('Please provide a repo for git_config.' ))
54
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' )
55
49
@patch ('os.path.isfile' , return_value = True )
56
50
@patch ('os.path.isdir' , return_value = True )
57
51
@patch ('os.path.exists' , return_value = True )
58
- def test_git_clone_repo_repo_not_provided (exists , isdir , isfile , checkout_branch_and_commit ,
59
- validate_git_config , mkdtemp , check_call ):
52
+ def test_git_clone_repo_repo_not_provided (exists , isdir , isfile , mkdtemp , check_call ):
60
53
git_config = {'branch' : BRANCH , 'commit' : COMMIT }
61
54
entry_point = 'entry_point_that_does_not_exist'
62
55
source_dir = 'source_dir'
@@ -69,13 +62,10 @@ def test_git_clone_repo_repo_not_provided(exists, isdir, isfile, checkout_branch
69
62
@patch ('subprocess.check_call' ,
70
63
side_effect = subprocess .CalledProcessError (returncode = 1 , cmd = 'git clone {} {}' .format (GIT_REPO , REPO_DIR )))
71
64
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
72
- @patch ('sagemaker.git_utils._validate_git_config' )
73
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' )
74
65
@patch ('os.path.isfile' , return_value = True )
75
66
@patch ('os.path.isdir' , return_value = True )
76
67
@patch ('os.path.exists' , return_value = True )
77
- def test_git_clone_repo_clone_fail (exists , isdir , isfile , checkout_branch_and_commit ,
78
- validate_git_config , mkdtemp , check_call ):
68
+ def test_git_clone_repo_clone_fail (exists , isdir , isfile , mkdtemp , check_call ):
79
69
git_config = {'repo' : GIT_REPO , 'branch' : BRANCH , 'commit' : COMMIT }
80
70
entry_point = 'entry_point'
81
71
source_dir = 'source_dir'
@@ -85,16 +75,14 @@ def test_git_clone_repo_clone_fail(exists, isdir, isfile, checkout_branch_and_co
85
75
assert 'returned non-zero exit status' in str (error )
86
76
87
77
88
- @patch ('subprocess.check_call' )
78
+ @patch ('subprocess.check_call' ,
79
+ side_effect = [True ,
80
+ subprocess .CalledProcessError (returncode = 1 , cmd = 'git checkout banana' )])
89
81
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
90
- @patch ('sagemaker.git_utils._validate_git_config' )
91
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' ,
92
- side_effect = subprocess .CalledProcessError (returncode = 1 , cmd = 'git checkout {}' .format (BRANCH )))
93
82
@patch ('os.path.isfile' , return_value = True )
94
83
@patch ('os.path.isdir' , return_value = True )
95
84
@patch ('os.path.exists' , return_value = True )
96
- def test_git_clone_repo_branch_not_exist (exists , isdir , isfile , checkout_branch_and_commit ,
97
- validate_git_config , mkdtemp , check_call ):
85
+ def test_git_clone_repo_branch_not_exist (exists , isdir , isfile , mkdtemp , check_call ):
98
86
git_config = {'repo' : GIT_REPO , 'branch' : BRANCH , 'commit' : COMMIT }
99
87
entry_point = 'entry_point'
100
88
source_dir = 'source_dir'
@@ -104,16 +92,14 @@ def test_git_clone_repo_branch_not_exist(exists, isdir, isfile, checkout_branch_
104
92
assert 'returned non-zero exit status' in str (error )
105
93
106
94
107
- @patch ('subprocess.check_call' )
95
+ @patch ('subprocess.check_call' ,
96
+ side_effect = [True , True ,
97
+ subprocess .CalledProcessError (returncode = 1 , cmd = 'git checkout {}' .format (COMMIT ))])
108
98
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
109
- @patch ('sagemaker.git_utils._validate_git_config' )
110
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' ,
111
- side_effect = subprocess .CalledProcessError (returncode = 1 , cmd = 'git checkout {}' .format (COMMIT )))
112
99
@patch ('os.path.isfile' , return_value = True )
113
100
@patch ('os.path.isdir' , return_value = True )
114
101
@patch ('os.path.exists' , return_value = True )
115
- def test_git_clone_repo_commit_not_exist (exists , isdir , isfile , checkout_branch_and_commit ,
116
- validate_git_config , mkdtemp , check_call ):
102
+ def test_git_clone_repo_commit_not_exist (exists , isdir , isfile , mkdtemp , check_call ):
117
103
git_config = {'repo' : GIT_REPO , 'branch' : BRANCH , 'commit' : COMMIT }
118
104
entry_point = 'entry_point'
119
105
source_dir = 'source_dir'
@@ -125,13 +111,10 @@ def test_git_clone_repo_commit_not_exist(exists, isdir, isfile, checkout_branch_
125
111
126
112
@patch ('subprocess.check_call' )
127
113
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
128
- @patch ('sagemaker.git_utils._validate_git_config' )
129
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' )
130
114
@patch ('os.path.isfile' , return_value = False )
131
115
@patch ('os.path.isdir' , return_value = True )
132
116
@patch ('os.path.exists' , return_value = True )
133
- def test_git_clone_repo_entry_point_not_exist (exists , isdir , isfile , checkout_branch_and_commit ,
134
- validate_git_config , mkdtemp , check_call ):
117
+ def test_git_clone_repo_entry_point_not_exist (exists , isdir , isfile , mkdtemp , check_call ):
135
118
git_config = {'repo' : GIT_REPO , 'branch' : BRANCH , 'commit' : COMMIT }
136
119
entry_point = 'entry_point_that_does_not_exist'
137
120
source_dir = 'source_dir'
@@ -143,13 +126,10 @@ def test_git_clone_repo_entry_point_not_exist(exists, isdir, isfile, checkout_br
143
126
144
127
@patch ('subprocess.check_call' )
145
128
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
146
- @patch ('sagemaker.git_utils._validate_git_config' )
147
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' )
148
129
@patch ('os.path.isfile' , return_value = True )
149
130
@patch ('os.path.isdir' , return_value = False )
150
131
@patch ('os.path.exists' , return_value = True )
151
- def test_git_clone_repo_source_dir_not_exist (exists , isdir , isfile , checkout_branch_and_commit ,
152
- validate_git_config , mkdtemp , check_call ):
132
+ def test_git_clone_repo_source_dir_not_exist (exists , isdir , isfile , mkdtemp , check_call ):
153
133
git_config = {'repo' : GIT_REPO , 'branch' : BRANCH , 'commit' : COMMIT }
154
134
entry_point = 'entry_point'
155
135
source_dir = 'source_dir_that_does_not_exist'
@@ -161,13 +141,10 @@ def test_git_clone_repo_source_dir_not_exist(exists, isdir, isfile, checkout_bra
161
141
162
142
@patch ('subprocess.check_call' )
163
143
@patch ('tempfile.mkdtemp' , return_value = REPO_DIR )
164
- @patch ('sagemaker.git_utils._validate_git_config' )
165
- @patch ('sagemaker.git_utils._checkout_branch_and_commit' )
166
144
@patch ('os.path.isfile' , return_value = True )
167
145
@patch ('os.path.isdir' , return_value = True )
168
146
@patch ('os.path.exists' , side_effect = [True , False ])
169
- def test_git_clone_repo_dependencies_not_exist (exists , isdir , isfile , checkout_branch_and_commit ,
170
- validate_git_config , mkdtemp , check_call ):
147
+ def test_git_clone_repo_dependencies_not_exist (exists , isdir , isfile , mkdtemp , check_call ):
171
148
git_config = {'repo' : GIT_REPO , 'branch' : BRANCH , 'commit' : COMMIT }
172
149
entry_point = 'entry_point'
173
150
source_dir = 'source_dir'
0 commit comments