|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from unittest.mock import ANY |
| 16 | + |
| 17 | +import create_hyperparameter_tuning_job_sample |
| 18 | + |
| 19 | +import test_constants as constants |
| 20 | + |
| 21 | + |
| 22 | +def test_create_hyperparameter_tuning_job_sample( |
| 23 | + mock_sdk_init, |
| 24 | + mock_custom_job, |
| 25 | + mock_get_custom_job, |
| 26 | + mock_get_hyperparameter_tuning_job, |
| 27 | + mock_run_hyperparameter_tuning_job, |
| 28 | +): |
| 29 | + |
| 30 | + create_hyperparameter_tuning_job_sample.create_hyperparameter_tuning_job_sample( |
| 31 | + project=constants.PROJECT, |
| 32 | + location=constants.LOCATION, |
| 33 | + staging_bucket=constants.STAGING_BUCKET, |
| 34 | + display_name=constants.HYPERPARAMETER_TUNING_JOB_DISPLAY_NAME, |
| 35 | + container_uri=constants.CONTAINER_URI, |
| 36 | + ) |
| 37 | + |
| 38 | + mock_sdk_init.assert_called_once_with( |
| 39 | + project=constants.PROJECT, |
| 40 | + location=constants.LOCATION, |
| 41 | + staging_bucket=constants.STAGING_BUCKET, |
| 42 | + ) |
| 43 | + |
| 44 | + mock_get_custom_job.assert_called_once_with( |
| 45 | + display_name=constants.CUSTOM_JOB_DISPLAY_NAME, |
| 46 | + worker_pool_specs=constants.CUSTOM_JOB_WORKER_POOL_SPECS, |
| 47 | + ) |
| 48 | + |
| 49 | + mock_get_hyperparameter_tuning_job.assert_called_once_with( |
| 50 | + display_name=constants.HYPERPARAMETER_TUNING_JOB_DISPLAY_NAME, |
| 51 | + custom_job=mock_custom_job, |
| 52 | + metric_spec=constants.HYPERPARAMETER_TUNING_JOB_METRIC_SPEC, |
| 53 | + parameter_spec=ANY, |
| 54 | + max_trial_count=constants.HYPERPARAMETER_TUNING_JOB_MAX_TRIAL_COUNT, |
| 55 | + parallel_trial_count=constants.HYPERPARAMETER_TUNING_JOB_PARALLEL_TRIAL_COUNT, |
| 56 | + labels=constants.HYPERPARAMETER_TUNING_JOB_LABELS, |
| 57 | + ) |
| 58 | + |
| 59 | + mock_run_hyperparameter_tuning_job.assert_called_once() |
0 commit comments