Skip to content

Commit a90c3d7

Browse files
committed
change: add debug level message and additional unit test for sdk default
1 parent 8d61a36 commit a90c3d7

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/sagemaker/config/config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def load_sagemaker_config(additional_config_paths: List[str] = None, s3_resource
110110
else:
111111
try:
112112
config_from_file = _load_config_from_file(file_path)
113-
except ValueError:
113+
except ValueError as error:
114114
if file_path not in (
115115
_DEFAULT_ADMIN_CONFIG_FILE_PATH,
116116
_DEFAULT_USER_CONFIG_FILE_PATH,
@@ -119,6 +119,8 @@ def load_sagemaker_config(additional_config_paths: List[str] = None, s3_resource
119119
# If there are no files in the Default config file locations, don't throw
120120
# Exceptions.
121121
raise
122+
else:
123+
logger.debug(error)
122124
if config_from_file:
123125
validate_sagemaker_config(config_from_file)
124126
merge_dicts(merged_config, config_from_file)

tests/unit/sagemaker/config/test_config.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import pytest
1717
import yaml
18+
import logging
1819
from mock import Mock, MagicMock
1920

2021
from sagemaker.config.config import (
@@ -246,6 +247,7 @@ def test_merge_of_s3_default_config_file_and_regular_config_file(
246247
def test_logging_when_overriden_admin_and_user_configs_are_found(get_data_dir, caplog):
247248
# Should log info message stating defaults were fetched since both exist
248249
logger.propagate = True
250+
249251
os.environ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE"] = get_data_dir
250252
os.environ["SAGEMAKER_USER_CONFIG_OVERRIDE"] = get_data_dir
251253
load_sagemaker_config()
@@ -258,12 +260,51 @@ def test_logging_when_overriden_admin_and_user_configs_are_found(get_data_dir, c
258260
"Not applying SDK defaults from location: {}".format(_DEFAULT_USER_CONFIG_FILE_PATH)
259261
not in caplog.text
260262
)
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
261301

262302

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):
264304
# Should log info message stating sdk defaults were not applied
265305
# for admin and user config since both are missing from default location
266306
logger.propagate = True
307+
caplog.set_level(logging.DEBUG, logger=logger.name)
267308
load_sagemaker_config()
268309
assert (
269310
"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):
273314
"Not applying SDK defaults from location: {}".format(_DEFAULT_USER_CONFIG_FILE_PATH)
274315
in caplog.text
275316
)
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
276320

277321

278322
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
292336
not in caplog.text
293337
)
294338
del os.environ["SAGEMAKER_USER_CONFIG_OVERRIDE"]
339+
logger.propagate = False
295340

296341

297342
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
313358
)
314359
del os.environ["SAGEMAKER_USER_CONFIG_OVERRIDE"]
315360
del os.environ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE"]
361+
logger.propagate = False
316362

317363

318364
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):
330376
"Not applying SDK defaults from location: {}".format(_DEFAULT_USER_CONFIG_FILE_PATH)
331377
in caplog.text
332378
)
379+
logger.propagate = False

0 commit comments

Comments
 (0)