Skip to content

Commit acb82a8

Browse files
author
Qian Chen
committed
test
1 parent 2e31e3f commit acb82a8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/sagemaker_mxnet_serving_container/handler_service.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def __init__(self):
4444

4545
@staticmethod
4646
def _user_module_transformer(model_dir=environment.model_dir):
47-
user_module = importlib.import_module(environment.Environment().module_name)
47+
try:
48+
user_module = importlib.import_module(environment.Environment().module_name)
49+
except ModuleNotFoundError as e:
50+
logging.error("import_module exception: {}".format(e))
51+
raise ValueError('import_module exception: {}'.format(e))
4852

4953
if hasattr(user_module, 'transform_fn'):
5054
return Transformer(default_inference_handler=DefaultMXNetInferenceHandler())

test/unit/test_handler_service.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,14 @@ def test_user_module_unsupported(import_module, env):
103103

104104
import_module.assert_called_once_with(MODULE_NAME)
105105
e.match('Unsupported model type')
106+
107+
108+
@patch('sagemaker_inference.environment.Environment')
109+
def test_user_module_notfound(env):
110+
env.return_value.module_name = MODULE_NAME
111+
112+
with pytest.raises(ValueError) as e:
113+
HandlerService._user_module_transformer()
114+
115+
importlib.import_module.assert_called_once_with(MODULE_NAME)
116+
e.match('import_module exception')

0 commit comments

Comments
 (0)