34
34
@patch ("sagemaker_pytorch_serving_container.torchserve._install_requirements" )
35
35
@patch ("os.path.exists" , return_value = True )
36
36
@patch ("sagemaker_pytorch_serving_container.torchserve._create_torchserve_config_file" )
37
- @patch ("sagemaker_pytorch_serving_container.torchserve._adapt_to_ts_format" )
38
37
def test_start_torchserve_default_service_handler (
39
- adapt ,
40
38
create_config ,
41
39
exists ,
42
40
install_requirements ,
@@ -47,7 +45,6 @@ def test_start_torchserve_default_service_handler(
47
45
):
48
46
torchserve .start_torchserve ()
49
47
50
- adapt .assert_called_once_with (torchserve .DEFAULT_HANDLER_SERVICE )
51
48
create_config .assert_called_once_with ()
52
49
exists .assert_called_once_with (REQUIREMENTS_PATH )
53
50
install_requirements .assert_called_once_with ()
@@ -62,7 +59,7 @@ def test_start_torchserve_default_service_handler(
62
59
"--log-config" ,
63
60
torchserve .DEFAULT_TS_LOG_FILE ,
64
61
"--models" ,
65
- "model.mar "
62
+ "model=/opt/ml/model "
66
63
]
67
64
68
65
subprocess_popen .assert_called_once_with (ts_model_server_cmd )
@@ -76,9 +73,7 @@ def test_start_torchserve_default_service_handler(
76
73
@patch ("sagemaker_pytorch_serving_container.torchserve._install_requirements" )
77
74
@patch ("os.path.exists" , return_value = True )
78
75
@patch ("sagemaker_pytorch_serving_container.torchserve._create_torchserve_config_file" )
79
- @patch ("sagemaker_pytorch_serving_container.torchserve._adapt_to_ts_format" )
80
76
def test_start_torchserve_default_service_handler_multi_model (
81
- adapt ,
82
77
create_config ,
83
78
exists ,
84
79
install_requirements ,
@@ -104,7 +99,7 @@ def test_start_torchserve_default_service_handler_multi_model(
104
99
"--log-config" ,
105
100
torchserve .DEFAULT_TS_LOG_FILE ,
106
101
"--models" ,
107
- "model.mar "
102
+ "model=/opt/ml/model "
108
103
]
109
104
110
105
subprocess_popen .assert_called_once_with (ts_model_server_cmd )
@@ -116,61 +111,13 @@ def test_start_torchserve_default_service_handler_multi_model(
116
111
@patch ("sagemaker_pytorch_serving_container.torchserve._retrieve_ts_server_process" )
117
112
@patch ("sagemaker_pytorch_serving_container.torchserve._add_sigterm_handler" )
118
113
@patch ("sagemaker_pytorch_serving_container.torchserve._create_torchserve_config_file" )
119
- @patch ("sagemaker_pytorch_serving_container.torchserve._adapt_to_ts_format" )
120
114
def test_start_torchserve_custom_handler_service (
121
- adapt , create_config , sigterm , retrieve , subprocess_popen , subprocess_call
115
+ create_config , sigterm , retrieve , subprocess_popen , subprocess_call
122
116
):
123
117
handler_service = Mock ()
124
118
125
119
torchserve .start_torchserve (handler_service )
126
120
127
- adapt .assert_called_once_with (handler_service )
128
-
129
-
130
- @patch ("sagemaker_pytorch_serving_container.torchserve._set_python_path" )
131
- @patch ("subprocess.check_call" )
132
- @patch ("os.makedirs" )
133
- @patch ("os.path.exists" , return_value = False )
134
- def test_adapt_to_ts_format (path_exists , make_dir , subprocess_check_call , set_python_path ):
135
- handler_service = Mock ()
136
-
137
- torchserve ._adapt_to_ts_format (handler_service )
138
-
139
- path_exists .assert_called_once_with (torchserve .DEFAULT_TS_MODEL_DIRECTORY )
140
- make_dir .assert_called_once_with (torchserve .DEFAULT_TS_MODEL_DIRECTORY )
141
-
142
- model_archiver_cmd = [
143
- "torch-model-archiver" ,
144
- "--model-name" ,
145
- torchserve .DEFAULT_TS_MODEL_NAME ,
146
- "--handler" ,
147
- handler_service ,
148
- "--export-path" ,
149
- torchserve .DEFAULT_TS_MODEL_DIRECTORY ,
150
- "--version" ,
151
- "1" ,
152
- "--extra-files" ,
153
- environment .model_dir
154
- ]
155
-
156
- subprocess_check_call .assert_called_once_with (model_archiver_cmd )
157
- set_python_path .assert_called_once_with ()
158
-
159
-
160
- @patch ("sagemaker_pytorch_serving_container.torchserve._set_python_path" )
161
- @patch ("subprocess.check_call" )
162
- @patch ("os.makedirs" )
163
- @patch ("os.path.exists" , return_value = True )
164
- def test_adapt_to_ts_format_existing_path (
165
- path_exists , make_dir , subprocess_check_call , set_python_path
166
- ):
167
- handler_service = Mock ()
168
-
169
- torchserve ._adapt_to_ts_format (handler_service )
170
-
171
- path_exists .assert_called_once_with (torchserve .DEFAULT_TS_MODEL_DIRECTORY )
172
- make_dir .assert_not_called ()
173
-
174
121
175
122
@patch .dict (os .environ , {torchserve .PYTHON_PATH_ENV : PYTHON_PATH }, clear = True )
176
123
def test_set_existing_python_path ():
0 commit comments