From 58e56fc59e954fe9937a47c5d460acb34b6f8afb Mon Sep 17 00:00:00 2001 From: nnegrey Date: Fri, 14 Feb 2020 13:32:36 -0700 Subject: [PATCH 1/2] datalabeling: ensure all tests use test endpoint --- datalabeling/manage_dataset.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/datalabeling/manage_dataset.py b/datalabeling/manage_dataset.py index a6318bfb3380..8e4c0cb81cd9 100644 --- a/datalabeling/manage_dataset.py +++ b/datalabeling/manage_dataset.py @@ -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) @@ -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) @@ -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) From 3970b7cc5d9a2804484cd2c266a5e8f8950cffb2 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Wed, 18 Mar 2020 09:49:33 -0600 Subject: [PATCH 2/2] requires an input csv for text input, slight print statement cleanup --- datalabeling/create_instruction.py | 4 ++-- datalabeling/label_text.py | 6 +++--- datalabeling/label_text_test.py | 2 +- datalabeling/manage_dataset.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/datalabeling/create_instruction.py b/datalabeling/create_instruction.py index f722bc57a9f5..c60f55d6e4a5 100644 --- a/datalabeling/create_instruction.py +++ b/datalabeling/create_instruction.py @@ -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:') @@ -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 diff --git a/datalabeling/label_text.py b/datalabeling/label_text.py index e6056ef19c01..70b112d6d530 100644 --- a/datalabeling/label_text.py +++ b/datalabeling/label_text.py @@ -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 ) diff --git a/datalabeling/label_text_test.py b/datalabeling/label_text_test.py index 4894c38304ce..e65fc1874788 100644 --- a/datalabeling/label_text_test.py +++ b/datalabeling/label_text_test.py @@ -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') diff --git a/datalabeling/manage_dataset.py b/datalabeling/manage_dataset.py index 8e4c0cb81cd9..6bb5a4c5e263 100644 --- a/datalabeling/manage_dataset.py +++ b/datalabeling/manage_dataset.py @@ -35,7 +35,7 @@ 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' ) @@ -43,12 +43,12 @@ def create_dataset(project_id): # 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]