|
| 1 | +# Copyright 2024 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 | +import create_custom_job_psci_sample |
| 16 | +from google.cloud import aiplatform_v1beta1 |
| 17 | +import test_constants as constants |
| 18 | + |
| 19 | + |
| 20 | +def test_create_custom_job_psci_sample( |
| 21 | + mock_sdk_init, |
| 22 | + mock_get_job_service_client_v1beta1, |
| 23 | + mock_get_create_custom_job_request_v1beta1, |
| 24 | + mock_create_custom_job_v1beta1, |
| 25 | +): |
| 26 | + """Custom training job sample with PSC-I through aiplatform_v1beta1.""" |
| 27 | + create_custom_job_psci_sample.create_custom_job_psci_sample( |
| 28 | + project=constants.PROJECT, |
| 29 | + location=constants.LOCATION, |
| 30 | + bucket=constants.STAGING_BUCKET, |
| 31 | + display_name=constants.DISPLAY_NAME, |
| 32 | + machine_type=constants.MACHINE_TYPE, |
| 33 | + replica_count=1, |
| 34 | + image_uri=constants.TRAIN_IMAGE, |
| 35 | + network_attachment_name=constants.NETWORK_ATTACHMENT_NAME, |
| 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_job_service_client_v1beta1.assert_called_once_with( |
| 45 | + client_options={ |
| 46 | + "api_endpoint": f"{constants.LOCATION}-aiplatform.googleapis.com" |
| 47 | + } |
| 48 | + ) |
| 49 | + |
| 50 | + mock_get_create_custom_job_request_v1beta1.assert_called_once_with( |
| 51 | + parent=f"projects/{constants.PROJECT}/locations/{constants.LOCATION}", |
| 52 | + custom_job=aiplatform_v1beta1.CustomJob( |
| 53 | + display_name=constants.DISPLAY_NAME, |
| 54 | + job_spec=aiplatform_v1beta1.CustomJobSpec( |
| 55 | + worker_pool_specs=[ |
| 56 | + aiplatform_v1beta1.WorkerPoolSpec( |
| 57 | + machine_spec=aiplatform_v1beta1.MachineSpec( |
| 58 | + machine_type=constants.MACHINE_TYPE, |
| 59 | + ), |
| 60 | + replica_count=constants.REPLICA_COUNT, |
| 61 | + container_spec=aiplatform_v1beta1.ContainerSpec( |
| 62 | + image_uri=constants.TRAIN_IMAGE, |
| 63 | + ), |
| 64 | + ) |
| 65 | + ], |
| 66 | + psc_interface_config=aiplatform_v1beta1.PscInterfaceConfig( |
| 67 | + network_attachment=constants.NETWORK_ATTACHMENT_NAME, |
| 68 | + ), |
| 69 | + ), |
| 70 | + ), |
| 71 | + ) |
| 72 | + |
| 73 | + request = aiplatform_v1beta1.CreateCustomJobRequest( |
| 74 | + mock_get_create_custom_job_request_v1beta1.return_value |
| 75 | + ) |
| 76 | + |
| 77 | + mock_create_custom_job_v1beta1.assert_called_once_with(request=request) |
0 commit comments