Skip to content

Commit 692ae9e

Browse files
committed
tests: Added project ID inference test
1 parent 036362e commit 692ae9e

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
import pytest
19+
20+
from google.cloud import aiplatform
21+
from google.cloud.aiplatform.compat.types import pipeline_state as gca_pipeline_state
22+
from tests.system.aiplatform import e2e_base
23+
24+
25+
@pytest.mark.usefixtures("prepare_staging_bucket", "delete_staging_bucket")
26+
class TestProjectIDInference(e2e_base.TestEndToEnd):
27+
28+
_temp_prefix = "temp-vertex-sdk-project-id-inference"
29+
30+
def test_project_id_inference(self, shared_state):
31+
# Collection of resources generated by this test, to be deleted during teardown
32+
shared_state["resources"] = []
33+
34+
aiplatform.init(
35+
location=e2e_base._LOCATION,
36+
staging_bucket=shared_state["staging_bucket_name"],
37+
)
38+
39+
worker_pool_specs = [
40+
{
41+
"machine_spec": {"machine_type": "n1-standard-2",},
42+
"replica_count": 1,
43+
"container_spec": {
44+
"image_uri": "python:3.9",
45+
"command": [
46+
"sh",
47+
"-exc",
48+
"""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=.
49+
"$0" "$@"
50+
""",
51+
"python3",
52+
"-c",
53+
"""
54+
from google.cloud import aiplatform
55+
# Not initializing the Vertex SDK explicitly
56+
# Checking teh project ID
57+
print(aiplatform.initializer.global_config.project)
58+
assert not aiplatform.initializer.global_config.project.endswith("-tp")
59+
# Testing ability to list resources
60+
endpoints = aiplatform.Endpoint.list()
61+
print(endpoints)
62+
""",
63+
],
64+
"args": [],
65+
},
66+
}
67+
]
68+
69+
custom_job = aiplatform.CustomJob(
70+
display_name=self._make_display_name("custom"),
71+
worker_pool_specs=worker_pool_specs,
72+
)
73+
custom_job.run(
74+
enable_web_access=True, sync=False,
75+
)
76+
77+
shared_state["resources"].append(custom_job)
78+
79+
in_progress_done_check = custom_job.done()
80+
custom_job.wait_for_resource_creation()
81+
82+
completion_done_check = custom_job.done()
83+
84+
assert (
85+
custom_job.state
86+
== gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED
87+
)
88+
89+
# Check done() method works correctly
90+
assert in_progress_done_check is False
91+
assert completion_done_check is True

0 commit comments

Comments
 (0)