|
| 1 | +# Copyright 2025 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 | +# http://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 | +# pylint: disable=protected-access,bad-continuation,missing-function-docstring |
| 16 | + |
| 17 | +from tests.unit.vertexai.genai.replays import pytest_helper |
| 18 | +from vertexai._genai import types |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | +METADATA_SCHEMA_URI = ( |
| 23 | + "gs://google-cloud-aiplatform/schema/dataset/metadata/multimodal_1.0.0.yaml" |
| 24 | +) |
| 25 | +BIGQUERY_TABLE_NAME = "vertex-sdk-dev.multimodal_dataset.test-table" |
| 26 | + |
| 27 | + |
| 28 | +def test_create_dataset(client): |
| 29 | + create_dataset_operation = client.datasets._create_multimodal_dataset( |
| 30 | + name="projects/vertex-sdk-dev/locations/us-central1", |
| 31 | + display_name="test-display-name", |
| 32 | + metadata_schema_uri=METADATA_SCHEMA_URI, |
| 33 | + metadata={ |
| 34 | + "inputConfig": { |
| 35 | + "bigquerySource": {"uri": f"bq://{BIGQUERY_TABLE_NAME}"}, |
| 36 | + }, |
| 37 | + }, |
| 38 | + ) |
| 39 | + assert isinstance(create_dataset_operation, types.MultimodalDatasetOperation) |
| 40 | + assert create_dataset_operation |
| 41 | + |
| 42 | + |
| 43 | +def test_create_dataset_from_bigquery(client): |
| 44 | + dataset = client.datasets.create_multimodal_dataset_from_bigquery( |
| 45 | + multimodal_dataset=types.MultimodalDataset( |
| 46 | + display_name="test-from-bigquery", |
| 47 | + bigquery_uri=BIGQUERY_TABLE_NAME, |
| 48 | + ) |
| 49 | + ) |
| 50 | + assert isinstance(dataset, types.MultimodalDataset) |
| 51 | + assert dataset.display_name == "test-from-bigquery" |
| 52 | + |
| 53 | + |
| 54 | +pytestmark = pytest_helper.setup( |
| 55 | + file=__file__, |
| 56 | + globals_for_file=globals(), |
| 57 | +) |
| 58 | + |
| 59 | +pytest_plugins = ("pytest_asyncio",) |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.asyncio |
| 63 | +async def test_create_dataset_async(client): |
| 64 | + create_dataset_operation = await client.aio.datasets._create_multimodal_dataset( |
| 65 | + name="projects/vertex-sdk-dev/locations/us-central1", |
| 66 | + display_name="test-display-name", |
| 67 | + metadata_schema_uri=METADATA_SCHEMA_URI, |
| 68 | + metadata={ |
| 69 | + "inputConfig": { |
| 70 | + "bigquerySource": {"uri": f"bq://{BIGQUERY_TABLE_NAME}"}, |
| 71 | + }, |
| 72 | + }, |
| 73 | + ) |
| 74 | + assert isinstance(create_dataset_operation, types.MultimodalDatasetOperation) |
| 75 | + assert create_dataset_operation |
| 76 | + |
| 77 | + |
| 78 | +@pytest.mark.asyncio |
| 79 | +async def test_create_dataset_from_bigquery_async(client): |
| 80 | + dataset = await client.aio.datasets.create_multimodal_dataset_from_bigquery( |
| 81 | + multimodal_dataset=types.MultimodalDataset( |
| 82 | + display_name="test-from-bigquery", |
| 83 | + bigquery_uri=BIGQUERY_TABLE_NAME, |
| 84 | + ) |
| 85 | + ) |
| 86 | + assert isinstance(dataset, types.MultimodalDataset) |
| 87 | + assert dataset.display_name == "test-from-bigquery" |
| 88 | + |
| 89 | + |
| 90 | +@pytest.mark.asyncio |
| 91 | +async def test_create_dataset_from_bigquery_async_with_timeout(client): |
| 92 | + dataset = await client.aio.datasets.create_multimodal_dataset_from_bigquery( |
| 93 | + config=types.CreateMultimodalDatasetConfig(timeout=120), |
| 94 | + multimodal_dataset=types.MultimodalDataset( |
| 95 | + display_name="test-from-bigquery", |
| 96 | + bigquery_uri=BIGQUERY_TABLE_NAME, |
| 97 | + ), |
| 98 | + ) |
| 99 | + assert isinstance(dataset, types.MultimodalDataset) |
| 100 | + assert dataset.display_name == "test-from-bigquery" |
0 commit comments