@@ -90,17 +90,6 @@ def test__get_active_conda_env_prefix():
90
90
assert call_arg == "CONDA_PREFIX"
91
91
92
92
93
- def test__get_studio_image_uri ():
94
- with patch ("os.getenv" ) as getenv_patch :
95
- getenv_patch .return_value = "some-sagemaker-studio-image-ecr-uri"
96
-
97
- result = RuntimeEnvironmentManager ()._get_studio_image_uri ()
98
-
99
- assert result == "some-sagemaker-studio-image-ecr-uri"
100
- call_arg = getenv_patch .call_args [0 ][0 ]
101
- assert call_arg == "SAGEMAKER_INTERNAL_IMAGE_URI"
102
-
103
-
104
93
@patch (
105
94
"sagemaker.remote_function.runtime_environment.runtime_environment_manager._log_error" , Mock ()
106
95
)
@@ -117,7 +106,14 @@ def test__get_studio_image_uri():
117
106
".RuntimeEnvironmentManager._get_active_conda_env_name" ,
118
107
return_value = "test_env" ,
119
108
)
120
- def test_snapshot_from_active_conda_env_when_name_available (conda_default_env , stub_conda_exe ):
109
+ @patch (
110
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
111
+ ".RuntimeEnvironmentManager._get_active_conda_env_prefix" ,
112
+ return_value = "/some/conda/env/prefix" ,
113
+ )
114
+ def test_snapshot_from_active_conda_env_when_name_available (
115
+ conda_env_prefix , conda_default_env , stub_conda_exe
116
+ ):
121
117
expected_result = os .path .join (os .getcwd (), "env_snapshot.yml" )
122
118
with patch ("subprocess.Popen" ) as popen :
123
119
popen .return_value .wait .return_value = 0
@@ -128,7 +124,7 @@ def test_snapshot_from_active_conda_env_when_name_available(conda_default_env, s
128
124
call_args = popen .call_args [0 ][0 ]
129
125
assert call_args is not None
130
126
expected_cmd = (
131
- f"{ stub_conda_exe .return_value } env export -n { conda_default_env .return_value } "
127
+ f"{ stub_conda_exe .return_value } env export -p { conda_env_prefix .return_value } "
132
128
f"--no-builds > { expected_result } "
133
129
)
134
130
assert call_args == expected_cmd
@@ -189,81 +185,7 @@ def test_snapshot_from_active_conda_env_when_prefix_available(
189
185
".RuntimeEnvironmentManager._get_active_conda_env_prefix" ,
190
186
return_value = None ,
191
187
)
192
- @patch (
193
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
194
- ".RuntimeEnvironmentManager._get_studio_image_uri" ,
195
- return_value = None ,
196
- )
197
- def test_snapshot_auto_capture_non_studio_no_active_conda_env (
198
- no_studio_image_uri , no_conda_env_prefix , no_conda_env_name
199
- ):
200
- with pytest .raises (ValueError ):
201
- RuntimeEnvironmentManager ().snapshot ("auto_capture" )
202
-
203
-
204
- @patch (
205
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager._log_error" , Mock ()
206
- )
207
- @patch (
208
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager._log_output" , Mock ()
209
- )
210
- @patch (
211
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
212
- ".RuntimeEnvironmentManager._get_conda_exe" ,
213
- return_value = "some-exe" ,
214
- )
215
- @patch (
216
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
217
- ".RuntimeEnvironmentManager._get_active_conda_env_name" ,
218
- return_value = None ,
219
- )
220
- @patch (
221
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
222
- ".RuntimeEnvironmentManager._get_active_conda_env_prefix" ,
223
- return_value = None ,
224
- )
225
- @patch (
226
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
227
- ".RuntimeEnvironmentManager._get_studio_image_uri" ,
228
- return_value = "some-image-uri" ,
229
- )
230
- @patch (
231
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
232
- ".RuntimeEnvironmentManager._get_which_python" ,
233
- return_value = "/some/prefix/bin/python" ,
234
- )
235
- @patch (
236
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
237
- ".RuntimeEnvironmentManager._get_conda_envs_list" ,
238
- return_value = "something something /some/prefix\n something /someother/prefix\n \n " ,
239
- )
240
- def test_snapshot_auto_capture_in_studio_no_active_conda_env (
241
- ouptut_conda_env_list ,
242
- output_which_python ,
243
- some_studio_image_uri ,
244
- no_conda_env_prefix ,
245
- no_conda_env_name ,
246
- stub_conda_exe ,
247
- ):
248
- expected_result = os .path .join (os .getcwd (), "env_snapshot.yml" )
249
- with patch ("subprocess.Popen" ) as popen :
250
- popen .return_value .wait .return_value = 0
251
-
252
- result = RuntimeEnvironmentManager ().snapshot ("auto_capture" )
253
- assert result == expected_result
254
-
255
- call_args = popen .call_args [0 ][0 ]
256
- assert call_args is not None
257
- expected_cmd = f"{ stub_conda_exe .return_value } env export -p /some/prefix --no-builds > { expected_result } "
258
- assert call_args == expected_cmd
259
-
260
-
261
- @patch (
262
- "sagemaker.remote_function.runtime_environment.runtime_environment_manager"
263
- ".RuntimeEnvironmentManager._get_active_conda_env_name" ,
264
- return_value = None ,
265
- )
266
- def test_snapshot_from_active_conda_env_error (conda_default_env ):
188
+ def test_snapshot_auto_capture_no_active_conda_env (no_conda_env_prefix , no_conda_env_name ):
267
189
with pytest .raises (ValueError ):
268
190
RuntimeEnvironmentManager ().snapshot ("auto_capture" )
269
191
0 commit comments