15
15
import os
16
16
import pytest
17
17
import yaml
18
+ import logging
18
19
from mock import Mock , MagicMock
19
20
20
21
from sagemaker .config .config import (
@@ -246,6 +247,7 @@ def test_merge_of_s3_default_config_file_and_regular_config_file(
246
247
def test_logging_when_overriden_admin_and_user_configs_are_found (get_data_dir , caplog ):
247
248
# Should log info message stating defaults were fetched since both exist
248
249
logger .propagate = True
250
+
249
251
os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ] = get_data_dir
250
252
os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ] = get_data_dir
251
253
load_sagemaker_config ()
@@ -258,12 +260,51 @@ def test_logging_when_overriden_admin_and_user_configs_are_found(get_data_dir, c
258
260
"Not applying SDK defaults from location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH )
259
261
not in caplog .text
260
262
)
263
+ del os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ]
264
+ del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
265
+ logger .propagate = False
266
+
267
+ def test_logging_when_overriden_admin_is_found_and_default_user_config_not_found (get_data_dir , caplog ):
268
+ logger .propagate = True
269
+ caplog .set_level (logging .DEBUG , logger = logger .name )
270
+ os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ] = get_data_dir
271
+ load_sagemaker_config ()
272
+ assert "Fetched defaults config from location: {}" .format (get_data_dir ) in caplog .text
273
+ assert (
274
+ "Not applying SDK defaults from location: {}" .format (
275
+ _DEFAULT_USER_CONFIG_FILE_PATH )
276
+ in caplog .text
277
+ )
278
+ assert "Unable to load the config file from the location: {}" .format (
279
+ _DEFAULT_USER_CONFIG_FILE_PATH
280
+ ) in caplog .text
281
+ del os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ]
282
+ logger .propagate = False
283
+
284
+
285
+ def test_logging_when_default_admin_not_found_and_overriden_user_config_is_found (get_data_dir , caplog ):
286
+ logger .propagate = True
287
+ caplog .set_level (logging .DEBUG , logger = logger .name )
288
+ os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ] = get_data_dir
289
+ load_sagemaker_config ()
290
+ assert "Fetched defaults config from location: {}" .format (get_data_dir ) in caplog .text
291
+ assert (
292
+ "Not applying SDK defaults from location: {}" .format (
293
+ _DEFAULT_ADMIN_CONFIG_FILE_PATH )
294
+ in caplog .text
295
+ )
296
+ assert "Unable to load the config file from the location: {}" .format (
297
+ _DEFAULT_ADMIN_CONFIG_FILE_PATH
298
+ ) in caplog .text
299
+ del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
300
+ logger .propagate = False
261
301
262
302
263
- def test_logging_when_default_admin_and_user_config_not_found (caplog ):
303
+ def test_logging_when_default_admin_and_default_user_config_not_found (caplog ):
264
304
# Should log info message stating sdk defaults were not applied
265
305
# for admin and user config since both are missing from default location
266
306
logger .propagate = True
307
+ caplog .set_level (logging .DEBUG , logger = logger .name )
267
308
load_sagemaker_config ()
268
309
assert (
269
310
"Not applying SDK defaults from location: {}" .format (_DEFAULT_ADMIN_CONFIG_FILE_PATH )
@@ -273,6 +314,9 @@ def test_logging_when_default_admin_and_user_config_not_found(caplog):
273
314
"Not applying SDK defaults from location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH )
274
315
in caplog .text
275
316
)
317
+ assert "Unable to load the config file from the location: {}" .format (_DEFAULT_ADMIN_CONFIG_FILE_PATH ) in caplog .text
318
+ assert "Unable to load the config file from the location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH ) in caplog .text
319
+ logger .propagate = False
276
320
277
321
278
322
def test_logging_when_default_admin_and_overriden_user_config_not_found (get_data_dir , caplog ):
@@ -292,6 +336,7 @@ def test_logging_when_default_admin_and_overriden_user_config_not_found(get_data
292
336
not in caplog .text
293
337
)
294
338
del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
339
+ logger .propagate = False
295
340
296
341
297
342
def test_logging_when_overriden_admin_and_overridden_user_config_not_found (get_data_dir , caplog ):
@@ -313,6 +358,7 @@ def test_logging_when_overriden_admin_and_overridden_user_config_not_found(get_d
313
358
)
314
359
del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
315
360
del os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ]
361
+ logger .propagate = False
316
362
317
363
318
364
def test_logging_with_additional_configs_and_none_are_found (caplog ):
@@ -330,3 +376,4 @@ def test_logging_with_additional_configs_and_none_are_found(caplog):
330
376
"Not applying SDK defaults from location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH )
331
377
in caplog .text
332
378
)
379
+ logger .propagate = False
0 commit comments