Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datalabeling: ensure all tests use test endpoint #2918

Merged
merged 6 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datalabeling/create_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):

# The format of the resource name:
# project_id/{project_id}/instruction/{instruction_id}
print('The instruction resource name: {}\n'.format(result.name))
print('The instruction resource name: {}'.format(result.name))
print('Display name: {}'.format(result.display_name))
print('Description: {}'.format(result.description))
print('Create time:')
Expand All @@ -62,7 +62,7 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):
print('Data type: {}'.format(
datalabeling.enums.DataType(result.data_type).name))
print('Pdf instruction:')
print('\tGcs file uri: {}'.format(
print('\tGcs file uri: {}\n'.format(
result.pdf_instruction.gcs_file_uri))

return result
Expand Down
6 changes: 3 additions & 3 deletions datalabeling/label_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def label_text(dataset_resource_name, instruction_resource_name,
annotation_spec_set=annotation_spec_set_resource_name)

response = client.label_text(
dataset_resource_name,
basic_config,
feature,
parent=dataset_resource_name,
basic_config=basic_config,
feature=feature,
text_entity_extraction_config=config
)

Expand Down
2 changes: 1 addition & 1 deletion datalabeling/label_text_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pytest

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
INPUT_GCS_URI = 'gs://cloud-samples-data/datalabeling/text/text_dataset.csv'
INPUT_GCS_URI = 'gs://cloud-samples-data/datalabeling/text/input.csv'


@pytest.fixture(scope='function')
Expand Down
27 changes: 24 additions & 3 deletions datalabeling/manage_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ def create_dataset(project_id):
formatted_project_name = client.project_path(project_id)

dataset = datalabeling.types.Dataset(
display_name='YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME',
display_name='YOUR_DATASET_SET_DISPLAY_NAME',
description='YOUR_DESCRIPTION'
)

response = client.create_dataset(formatted_project_name, dataset)

# The format of resource name:
# project_id/{project_id}/datasets/{dataset_id}
print('The dataset resource name: {}\n'.format(response.name))
print('The dataset resource name: {}'.format(response.name))
print('Display name: {}'.format(response.display_name))
print('Description: {}'.format(response.description))
print('Create time:')
print('\tseconds: {}'.format(response.create_time.seconds))
print('\tnanos: {}'.format(response.create_time.nanos))
print('\tnanos: {}\n'.format(response.create_time.nanos))

return response
# [END datalabeling_create_dataset_beta]
Expand All @@ -59,6 +59,13 @@ def list_datasets(project_id):
"""Lists datasets for the given Google Cloud project."""
from google.cloud import datalabeling_v1beta1 as datalabeling
client = datalabeling.DataLabelingServiceClient()
# [END datalabeling_list_datasets_beta]
# If provided, use a provided test endpoint - this will prevent tests on
# this snippet from triggering any action by a real human
if 'DATALABELING_ENDPOINT' in os.environ:
opts = ClientOptions(api_endpoint=os.getenv('DATALABELING_ENDPOINT'))
client = datalabeling.DataLabelingServiceClient(client_options=opts)
# [START datalabeling_list_datasets_beta]

formatted_project_name = client.project_path(project_id)

Expand All @@ -80,6 +87,13 @@ def get_dataset(dataset_resource_name):
"""Gets a dataset for the given Google Cloud project."""
from google.cloud import datalabeling_v1beta1 as datalabeling
client = datalabeling.DataLabelingServiceClient()
# [END datalabeling_get_dataset_beta]
# If provided, use a provided test endpoint - this will prevent tests on
# this snippet from triggering any action by a real human
if 'DATALABELING_ENDPOINT' in os.environ:
opts = ClientOptions(api_endpoint=os.getenv('DATALABELING_ENDPOINT'))
client = datalabeling.DataLabelingServiceClient(client_options=opts)
# [START datalabeling_get_dataset_beta]

response = client.get_dataset(dataset_resource_name)

Expand All @@ -97,6 +111,13 @@ def delete_dataset(dataset_resource_name):
"""Deletes a dataset for the given Google Cloud project."""
from google.cloud import datalabeling_v1beta1 as datalabeling
client = datalabeling.DataLabelingServiceClient()
# [END datalabeling_delete_dataset_beta]
# If provided, use a provided test endpoint - this will prevent tests on
# this snippet from triggering any action by a real human
if 'DATALABELING_ENDPOINT' in os.environ:
opts = ClientOptions(api_endpoint=os.getenv('DATALABELING_ENDPOINT'))
client = datalabeling.DataLabelingServiceClient(client_options=opts)
# [START datalabeling_delete_dataset_beta]

response = client.delete_dataset(dataset_resource_name)

Expand Down