Skip to content

Commit

Permalink
tests: Added project ID inference test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Mar 16, 2022
1 parent 036362e commit 91373a0
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions tests/system/aiplatform/test_project_id_inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-

# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import pytest

from google.cloud import aiplatform
from google.cloud.aiplatform.compat.types import pipeline_state as gca_pipeline_state
from tests.system.aiplatform import e2e_base


@pytest.mark.usefixtures("prepare_staging_bucket", "delete_staging_bucket")
class TestProjectIDInference(e2e_base.TestEndToEnd):

_temp_prefix = "temp-vertex-sdk-project-id-inference"

def test_project_id_inference(self, shared_state):
# Collection of resources generated by this test, to be deleted during teardown
shared_state["resources"] = []

aiplatform.init(
# project=e2e_base._PROJECT,
# location=e2e_base._LOCATION,
staging_bucket=shared_state["staging_bucket_name"],
)

worker_pool_specs = [
{
"machine_spec": {"machine_type": "n1-standard-2",},
"replica_count": 1,
"container_spec": {
"image_uri": "python:3.9",
"command": [
"sh",
"-exc",
"""python3 -m pip install git+https://github.com/Ark-kun/python-aiplatform@fix--Fixed-getitng-project-ID-when-running-on-Vertex-AI#egg=google-cloud-aiplatform&subdirectory=.
"$0" "$@"
""",
"python3",
"-c",
"""
from google.cloud import aiplatform
# Not initializing the Vertex SDK explicitly
# Checking teh project ID
print(aiplatform.initializer.global_config.project)
assert not aiplatform.initializer.global_config.project.endswith("-tp")
# Testing ability to list resources
endpoints = aiplatform.Endpoint.list()
print(endpoints)
""",
],
"args": [],
},
}
]

custom_job = aiplatform.CustomJob(
display_name=self._make_display_name("custom"),
worker_pool_specs=worker_pool_specs,
)
custom_job.run(
enable_web_access=True, sync=False,
)

shared_state["resources"].append(custom_job)

in_progress_done_check = custom_job.done()
custom_job.wait_for_resource_creation()

completion_done_check = custom_job.done()

assert (
custom_job.state
== gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED
)

# Check done() method works correctly
assert in_progress_done_check is False
assert completion_done_check is True

0 comments on commit 91373a0

Please sign in to comment.