Skip to content

Commit d4014b0

Browse files
nnegreyleahecole
andauthored
datalabeling: ensure all tests use test endpoint (#2918)
* datalabeling: ensure all tests use test endpoint * requires an input csv for text input, slight print statement cleanup Co-authored-by: Leah E. Cole <[email protected]>
1 parent a9e0a0c commit d4014b0

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

datalabeling/create_instruction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):
5353

5454
# The format of the resource name:
5555
# project_id/{project_id}/instruction/{instruction_id}
56-
print('The instruction resource name: {}\n'.format(result.name))
56+
print('The instruction resource name: {}'.format(result.name))
5757
print('Display name: {}'.format(result.display_name))
5858
print('Description: {}'.format(result.description))
5959
print('Create time:')
@@ -62,7 +62,7 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):
6262
print('Data type: {}'.format(
6363
datalabeling.enums.DataType(result.data_type).name))
6464
print('Pdf instruction:')
65-
print('\tGcs file uri: {}'.format(
65+
print('\tGcs file uri: {}\n'.format(
6666
result.pdf_instruction.gcs_file_uri))
6767

6868
return result

datalabeling/label_text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def label_text(dataset_resource_name, instruction_resource_name,
4747
annotation_spec_set=annotation_spec_set_resource_name)
4848

4949
response = client.label_text(
50-
dataset_resource_name,
51-
basic_config,
52-
feature,
50+
parent=dataset_resource_name,
51+
basic_config=basic_config,
52+
feature=feature,
5353
text_entity_extraction_config=config
5454
)
5555

datalabeling/label_text_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import pytest
2727

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

3131

3232
@pytest.fixture(scope='function')

datalabeling/manage_dataset.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ def create_dataset(project_id):
3535
formatted_project_name = client.project_path(project_id)
3636

3737
dataset = datalabeling.types.Dataset(
38-
display_name='YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME',
38+
display_name='YOUR_DATASET_SET_DISPLAY_NAME',
3939
description='YOUR_DESCRIPTION'
4040
)
4141

4242
response = client.create_dataset(formatted_project_name, dataset)
4343

4444
# The format of resource name:
4545
# project_id/{project_id}/datasets/{dataset_id}
46-
print('The dataset resource name: {}\n'.format(response.name))
46+
print('The dataset resource name: {}'.format(response.name))
4747
print('Display name: {}'.format(response.display_name))
4848
print('Description: {}'.format(response.description))
4949
print('Create time:')
5050
print('\tseconds: {}'.format(response.create_time.seconds))
51-
print('\tnanos: {}'.format(response.create_time.nanos))
51+
print('\tnanos: {}\n'.format(response.create_time.nanos))
5252

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

6370
formatted_project_name = client.project_path(project_id)
6471

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

8498
response = client.get_dataset(dataset_resource_name)
8599

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

101122
response = client.delete_dataset(dataset_resource_name)
102123

0 commit comments

Comments
 (0)