@@ -174,6 +174,43 @@ def test_stop_tuning_job_no_tuning_job(tuner):
174
174
assert 'No tuning job available' in str (e )
175
175
176
176
177
+ def test_best_tuning_job (tuner ):
178
+ tuning_job_description = {'BestTrainingJob' : {'TrainingJobName' : JOB_NAME }}
179
+
180
+ tuner .estimator .sagemaker_session .sagemaker_client .describe_hyper_parameter_tuning_job = Mock (
181
+ name = 'describe_hyper_parameter_tuning_job' , return_value = tuning_job_description )
182
+
183
+ tuner .latest_tuning_job = _TuningJob (tuner .estimator .sagemaker_session , JOB_NAME )
184
+ best_training_job = tuner .best_training_job ()
185
+
186
+ assert best_training_job == JOB_NAME
187
+ tuner .estimator .sagemaker_session .sagemaker_client .describe_hyper_parameter_tuning_job .assert_called_once_with (
188
+ HyperParameterTuningJobName = JOB_NAME )
189
+
190
+
191
+ def test_best_tuning_job_no_latest_job (tuner ):
192
+ with pytest .raises (Exception ) as e :
193
+ tuner .best_training_job ()
194
+
195
+ assert 'No tuning job available' in str (e )
196
+
197
+
198
+ def test_best_tuning_job_no_best_job (tuner ):
199
+ tuning_job_description = {'BestTrainingJob' : {'Mock' : None }}
200
+
201
+ tuner .estimator .sagemaker_session .sagemaker_client .describe_hyper_parameter_tuning_job = Mock (
202
+ name = 'describe_hyper_parameter_tuning_job' , return_value = tuning_job_description )
203
+
204
+ tuner .latest_tuning_job = _TuningJob (tuner .estimator .sagemaker_session , JOB_NAME )
205
+
206
+ with pytest .raises (Exception ) as e :
207
+ tuner .best_training_job ()
208
+
209
+ tuner .estimator .sagemaker_session .sagemaker_client .describe_hyper_parameter_tuning_job .assert_called_once_with (
210
+ HyperParameterTuningJobName = JOB_NAME )
211
+ assert 'Best training job not available for tuning job:' in str (e )
212
+
213
+
177
214
#################################################################################
178
215
# _ParameterRange Tests
179
216
0 commit comments