Skip to content

Commit 91373a0

Browse files
committed
tests: Added project ID inference test
1 parent 036362e commit 91373a0

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
# project=e2e_base._PROJECT,
36+
# location=e2e_base._LOCATION,
37+
staging_bucket=shared_state["staging_bucket_name"],
38+
)
39+
40+
worker_pool_specs = [
41+
{
42+
"machine_spec": {"machine_type": "n1-standard-2",},
43+
"replica_count": 1,
44+
"container_spec": {
45+
"image_uri": "python:3.9",
46+
"command": [
47+
"sh",
48+
"-exc",
49+
"""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=.
50+
"$0" "$@"
51+
""",
52+
"python3",
53+
"-c",
54+
"""
55+
from google.cloud import aiplatform
56+
# Not initializing the Vertex SDK explicitly
57+
# Checking teh project ID
58+
print(aiplatform.initializer.global_config.project)
59+
assert not aiplatform.initializer.global_config.project.endswith("-tp")
60+
# Testing ability to list resources
61+
endpoints = aiplatform.Endpoint.list()
62+
print(endpoints)
63+
""",
64+
],
65+
"args": [],
66+
},
67+
}
68+
]
69+
70+
custom_job = aiplatform.CustomJob(
71+
display_name=self._make_display_name("custom"),
72+
worker_pool_specs=worker_pool_specs,
73+
)
74+
custom_job.run(
75+
enable_web_access=True, sync=False,
76+
)
77+
78+
shared_state["resources"].append(custom_job)
79+
80+
in_progress_done_check = custom_job.done()
81+
custom_job.wait_for_resource_creation()
82+
83+
completion_done_check = custom_job.done()
84+
85+
assert (
86+
custom_job.state
87+
== gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED
88+
)
89+
90+
# Check done() method works correctly
91+
assert in_progress_done_check is False
92+
assert completion_done_check is True

0 commit comments

Comments
 (0)