From 3d643383e481fa22093756343bdf50eba002b1f8 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 17 Nov 2020 16:12:16 -0800 Subject: [PATCH] feat: add common resource helper paths; expose client transport (#49) * changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * chore(py-library): enable snippet-bot Co-authored-by: Benjamin E. Coe Source-Author: Takashi Matsuo Source-Date: Tue Sep 1 17:14:08 2020 +0000 Source-Repo: googleapis/synthtool Source-Sha: d91dd8aac77f7a9c5506c238038a26fa4f9e361e Source-Link: https://github.com/googleapis/synthtool/commit/d91dd8aac77f7a9c5506c238038a26fa4f9e361e * chore: manual regen Co-authored-by: Bu Sun Kim Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> --- .github/snippet-bot.yml | 0 .kokoro/docs/common.cfg | 2 +- .kokoro/populate-secrets.sh | 43 + .kokoro/release/common.cfg | 50 +- .kokoro/samples/python3.6/common.cfg | 6 + .kokoro/samples/python3.7/common.cfg | 6 + .kokoro/samples/python3.8/common.cfg | 6 + .kokoro/test-samples.sh | 8 +- .kokoro/trampoline.sh | 15 +- CODE_OF_CONDUCT.md | 123 +- CONTRIBUTING.rst | 19 - docs/conf.py | 4 +- docs/datalabeling_v1beta1/types.rst | 1 + .../proto/annotation.proto | 3 + .../proto/annotation_spec_set.proto | 3 + .../proto/data_labeling_service.proto | 4 + .../proto/data_payloads.proto | 3 + .../datalabeling_v1beta1/proto/dataset.proto | 3 + .../proto/evaluation.proto | 3 + .../proto/evaluation_job.proto | 3 + .../proto/human_annotation_config.proto | 3 + .../proto/instruction.proto | 3 + .../proto/operations.proto | 3 + .../data_labeling_service/async_client.py | 273 ++- .../services/data_labeling_service/client.py | 246 +- .../data_labeling_service/transports/base.py | 84 +- .../data_labeling_service/transports/grpc.py | 74 +- .../transports/grpc_asyncio.py | 67 +- .../datalabeling_v1beta1/types/annotation.py | 28 +- .../types/data_payloads.py | 2 +- noxfile.py | 10 +- samples/snippets/noxfile.py | 50 +- scripts/decrypt-secrets.sh | 15 +- .../fixup_datalabeling_v1beta1_keywords.py | 1 + synth.metadata | 16 +- .../test_data_labeling_service.py | 1992 ++++++++++------- 36 files changed, 2075 insertions(+), 1097 deletions(-) create mode 100644 .github/snippet-bot.yml create mode 100755 .kokoro/populate-secrets.sh diff --git a/.github/snippet-bot.yml b/.github/snippet-bot.yml new file mode 100644 index 0000000..e69de29 diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index 3e05863..5875bf6 100644 --- a/.kokoro/docs/common.cfg +++ b/.kokoro/docs/common.cfg @@ -30,7 +30,7 @@ env_vars: { env_vars: { key: "V2_STAGING_BUCKET" - value: "docs-staging-v2-staging" + value: "docs-staging-v2" } # It will upload the docker image after successful builds. diff --git a/.kokoro/populate-secrets.sh b/.kokoro/populate-secrets.sh new file mode 100755 index 0000000..f525142 --- /dev/null +++ b/.kokoro/populate-secrets.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Copyright 2020 Google LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;} +function msg { println "$*" >&2 ;} +function println { printf '%s\n' "$(now) $*" ;} + + +# Populates requested secrets set in SECRET_MANAGER_KEYS from service account: +# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com +SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager" +msg "Creating folder on disk for secrets: ${SECRET_LOCATION}" +mkdir -p ${SECRET_LOCATION} +for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g") +do + msg "Retrieving secret ${key}" + docker run --entrypoint=gcloud \ + --volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \ + gcr.io/google.com/cloudsdktool/cloud-sdk \ + secrets versions access latest \ + --project cloud-devrel-kokoro-resources \ + --secret ${key} > \ + "${SECRET_LOCATION}/${key}" + if [[ $? == 0 ]]; then + msg "Secret written to ${SECRET_LOCATION}/${key}" + else + msg "Error retrieving secret ${key}" + fi +done diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 345151d..29d2d2b 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,42 +23,18 @@ env_vars: { value: "github/python-datalabeling/.kokoro/release.sh" } -# Fetch the token needed for reporting release status to GitHub -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "yoshi-automation-github-key" - } - } -} - -# Fetch PyPI password -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "google_cloud_pypi_password" - } - } -} - -# Fetch magictoken to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "releasetool-magictoken" - } - } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google_cloud_pypi_password" + } + } } -# Fetch api key to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "magic-github-proxy-api-key" - } - } -} +# Tokens needed to report release status back to GitHub +env_vars: { + key: "SECRET_MANAGER_KEYS" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" +} \ No newline at end of file diff --git a/.kokoro/samples/python3.6/common.cfg b/.kokoro/samples/python3.6/common.cfg index 88adae0..995c300 100644 --- a/.kokoro/samples/python3.6/common.cfg +++ b/.kokoro/samples/python3.6/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.6" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py36" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-datalabeling/.kokoro/test-samples.sh" diff --git a/.kokoro/samples/python3.7/common.cfg b/.kokoro/samples/python3.7/common.cfg index f25c414..f0c4a67 100644 --- a/.kokoro/samples/python3.7/common.cfg +++ b/.kokoro/samples/python3.7/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.7" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py37" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-datalabeling/.kokoro/test-samples.sh" diff --git a/.kokoro/samples/python3.8/common.cfg b/.kokoro/samples/python3.8/common.cfg index e0572fe..4391154 100644 --- a/.kokoro/samples/python3.8/common.cfg +++ b/.kokoro/samples/python3.8/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.8" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py38" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-datalabeling/.kokoro/test-samples.sh" diff --git a/.kokoro/test-samples.sh b/.kokoro/test-samples.sh index 973deb9..e39bc8c 100755 --- a/.kokoro/test-samples.sh +++ b/.kokoro/test-samples.sh @@ -28,6 +28,12 @@ if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then git checkout $LATEST_RELEASE fi +# Exit early if samples directory doesn't exist +if [ ! -d "./samples" ]; then + echo "No tests run. `./samples` not found" + exit 0 +fi + # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -101,4 +107,4 @@ cd "$ROOT" # Workaround for Kokoro permissions issue: delete secrets rm testing/{test-env.sh,client-secrets.json,service-account.json} -exit "$RTN" \ No newline at end of file +exit "$RTN" diff --git a/.kokoro/trampoline.sh b/.kokoro/trampoline.sh index e8c4251..f39236e 100755 --- a/.kokoro/trampoline.sh +++ b/.kokoro/trampoline.sh @@ -15,9 +15,14 @@ set -eo pipefail -python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" || ret_code=$? +# Always run the cleanup script, regardless of the success of bouncing into +# the container. +function cleanup() { + chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + echo "cleanup"; +} +trap cleanup EXIT -chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh -${KOKORO_GFILE_DIR}/trampoline_cleanup.sh || true - -exit ${ret_code} +$(dirname $0)/populate-secrets.sh # Secret Manager secrets. +python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b3d1f60..039f436 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,44 +1,95 @@ -# Contributor Code of Conduct +# Code of Conduct -As contributors and maintainers of this project, -and in the interest of fostering an open and welcoming community, -we pledge to respect all people who contribute through reporting issues, -posting feature requests, updating documentation, -submitting pull requests or patches, and other activities. +## Our Pledge -We are committed to making participation in this project -a harassment-free experience for everyone, -regardless of level of experience, gender, gender identity and expression, -sexual orientation, disability, personal appearance, -body size, race, ethnicity, age, religion, or nationality. +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery -* Personal attacks -* Trolling or insulting/derogatory comments -* Public or private harassment -* Publishing other's private information, -such as physical or electronic -addresses, without explicit permission -* Other unethical or unprofessional conduct. +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct. -By adopting this Code of Conduct, -project maintainers commit themselves to fairly and consistently -applying these principles to every aspect of managing this project. -Project maintainers who do not follow or enforce the Code of Conduct -may be permanently removed from the project team. - -This code of conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior -may be reported by opening an issue -or contacting one or more of the project maintainers. - -This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, -available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + + +Reports should be directed to *googleapis-stewards@google.com*, the +Project Steward(s) for *Google Cloud Client Libraries*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out to the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index eb1602f..58d838e 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -80,25 +80,6 @@ We use `nox `__ to instrument our tests. .. nox: https://pypi.org/project/nox/ -Note on Editable Installs / Develop Mode -======================================== - -- As mentioned previously, using ``setuptools`` in `develop mode`_ - or a ``pip`` `editable install`_ is not possible with this - library. This is because this library uses `namespace packages`_. - For context see `Issue #2316`_ and the relevant `PyPA issue`_. - - Since ``editable`` / ``develop`` mode can't be used, packages - need to be installed directly. Hence your changes to the source - tree don't get incorporated into the **already installed** - package. - -.. _namespace packages: https://www.python.org/dev/peps/pep-0420/ -.. _Issue #2316: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2316 -.. _PyPA issue: https://github.com/pypa/packaging-problems/issues/12 -.. _develop mode: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode -.. _editable install: https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs - ***************************************** I'm getting weird errors... Can you help? ***************************************** diff --git a/docs/conf.py b/docs/conf.py index 7f93593..2a50b27 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,7 +29,7 @@ # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.6.3" +needs_sphinx = "1.5.5" # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -39,6 +39,7 @@ "sphinx.ext.autosummary", "sphinx.ext.intersphinx", "sphinx.ext.coverage", + "sphinx.ext.doctest", "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", @@ -348,6 +349,7 @@ "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), "grpc": ("https://grpc.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), } diff --git a/docs/datalabeling_v1beta1/types.rst b/docs/datalabeling_v1beta1/types.rst index 634c148..2722f06 100644 --- a/docs/datalabeling_v1beta1/types.rst +++ b/docs/datalabeling_v1beta1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Datalabeling v1beta1 API .. automodule:: google.cloud.datalabeling_v1beta1.types :members: + :show-inheritance: diff --git a/google/cloud/datalabeling_v1beta1/proto/annotation.proto b/google/cloud/datalabeling_v1beta1/proto/annotation.proto index 4750fdc..7d629b2 100644 --- a/google/cloud/datalabeling_v1beta1/proto/annotation.proto +++ b/google/cloud/datalabeling_v1beta1/proto/annotation.proto @@ -22,9 +22,12 @@ import "google/api/resource.proto"; import "google/cloud/datalabeling/v1beta1/annotation_spec_set.proto"; import "google/protobuf/duration.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Specifies where the annotation comes from (whether it was provided by a // human labeler or a different source). diff --git a/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto b/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto index 71bc12a..eb9b04b 100644 --- a/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto +++ b/google/cloud/datalabeling_v1beta1/proto/annotation_spec_set.proto @@ -20,9 +20,12 @@ package google.cloud.datalabeling.v1beta1; import "google/api/annotations.proto"; import "google/api/resource.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // An AnnotationSpecSet is a collection of label definitions. For example, in // image classification tasks, you define a set of possible labels for images as diff --git a/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto b/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto index 7616bc2..5d0746c 100644 --- a/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto +++ b/google/cloud/datalabeling_v1beta1/proto/data_labeling_service.proto @@ -31,10 +31,14 @@ import "google/longrunning/operations.proto"; import "google/protobuf/empty.proto"; import "google/protobuf/field_mask.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; +// Service for the AI Platform Data Labeling API. service DataLabelingService { option (google.api.default_host) = "datalabeling.googleapis.com"; option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; diff --git a/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto b/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto index 721e200..4aebde4 100644 --- a/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto +++ b/google/cloud/datalabeling_v1beta1/proto/data_payloads.proto @@ -21,9 +21,12 @@ import "google/api/annotations.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Container of information about an image. message ImagePayload { diff --git a/google/cloud/datalabeling_v1beta1/proto/dataset.proto b/google/cloud/datalabeling_v1beta1/proto/dataset.proto index a0bc9a4..cf21b19 100644 --- a/google/cloud/datalabeling_v1beta1/proto/dataset.proto +++ b/google/cloud/datalabeling_v1beta1/proto/dataset.proto @@ -25,9 +25,12 @@ import "google/cloud/datalabeling/v1beta1/data_payloads.proto"; import "google/cloud/datalabeling/v1beta1/human_annotation_config.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; enum DataType { DATA_TYPE_UNSPECIFIED = 0; diff --git a/google/cloud/datalabeling_v1beta1/proto/evaluation.proto b/google/cloud/datalabeling_v1beta1/proto/evaluation.proto index fde0366..18d3719 100644 --- a/google/cloud/datalabeling_v1beta1/proto/evaluation.proto +++ b/google/cloud/datalabeling_v1beta1/proto/evaluation.proto @@ -23,9 +23,12 @@ import "google/cloud/datalabeling/v1beta1/annotation.proto"; import "google/cloud/datalabeling/v1beta1/annotation_spec_set.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Describes an evaluation between a machine learning model's predictions and // ground truth labels. Created when an [EvaluationJob][google.cloud.datalabeling.v1beta1.EvaluationJob] runs successfully. diff --git a/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto b/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto index 49270fe..6f54ad1 100644 --- a/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto +++ b/google/cloud/datalabeling_v1beta1/proto/evaluation_job.proto @@ -25,9 +25,12 @@ import "google/cloud/datalabeling/v1beta1/human_annotation_config.proto"; import "google/protobuf/timestamp.proto"; import "google/rpc/status.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Defines an evaluation job that runs periodically to generate // [Evaluations][google.cloud.datalabeling.v1beta1.Evaluation]. [Creating an evaluation diff --git a/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto b/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto index 5658bb9..a05bd30 100644 --- a/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto +++ b/google/cloud/datalabeling_v1beta1/proto/human_annotation_config.proto @@ -21,9 +21,12 @@ import "google/api/annotations.proto"; import "google/api/field_behavior.proto"; import "google/protobuf/duration.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; enum StringAggregationType { STRING_AGGREGATION_TYPE_UNSPECIFIED = 0; diff --git a/google/cloud/datalabeling_v1beta1/proto/instruction.proto b/google/cloud/datalabeling_v1beta1/proto/instruction.proto index 5083961..15bf695 100644 --- a/google/cloud/datalabeling_v1beta1/proto/instruction.proto +++ b/google/cloud/datalabeling_v1beta1/proto/instruction.proto @@ -22,9 +22,12 @@ import "google/api/resource.proto"; import "google/cloud/datalabeling/v1beta1/dataset.proto"; import "google/protobuf/timestamp.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Instruction of how to perform the labeling task for human operators. // Currently only PDF instruction is supported. diff --git a/google/cloud/datalabeling_v1beta1/proto/operations.proto b/google/cloud/datalabeling_v1beta1/proto/operations.proto index 7f06924..49df6d2 100644 --- a/google/cloud/datalabeling_v1beta1/proto/operations.proto +++ b/google/cloud/datalabeling_v1beta1/proto/operations.proto @@ -24,9 +24,12 @@ import "google/cloud/datalabeling/v1beta1/human_annotation_config.proto"; import "google/protobuf/timestamp.proto"; import "google/rpc/status.proto"; +option csharp_namespace = "Google.Cloud.DataLabeling.V1Beta1"; option go_package = "google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1;datalabeling"; option java_multiple_files = true; option java_package = "com.google.cloud.datalabeling.v1beta1"; +option php_namespace = "Google\\Cloud\\DataLabeling\\V1beta1"; +option ruby_package = "Google::Cloud::DataLabeling::V1beta1"; // Response used for ImportData longrunning operation. message ImportDataOperationResponse { diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py index 5a5c908..569bf03 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py @@ -28,8 +28,8 @@ from google.auth import credentials # type: ignore from google.oauth2 import service_account # type: ignore -from google.api_core import operation -from google.api_core import operation_async +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore from google.cloud.datalabeling_v1beta1.services.data_labeling_service import pagers from google.cloud.datalabeling_v1beta1.types import annotation from google.cloud.datalabeling_v1beta1.types import annotation_spec_set @@ -50,32 +50,91 @@ from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from .transports.base import DataLabelingServiceTransport +from .transports.base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import DataLabelingServiceGrpcAsyncIOTransport from .client import DataLabelingServiceClient class DataLabelingServiceAsyncClient: - """""" + """Service for the AI Platform Data Labeling API.""" _client: DataLabelingServiceClient DEFAULT_ENDPOINT = DataLabelingServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DataLabelingServiceClient.DEFAULT_MTLS_ENDPOINT - instruction_path = staticmethod(DataLabelingServiceClient.instruction_path) - + annotated_dataset_path = staticmethod( + DataLabelingServiceClient.annotated_dataset_path + ) + parse_annotated_dataset_path = staticmethod( + DataLabelingServiceClient.parse_annotated_dataset_path + ) annotation_spec_set_path = staticmethod( DataLabelingServiceClient.annotation_spec_set_path ) - + parse_annotation_spec_set_path = staticmethod( + DataLabelingServiceClient.parse_annotation_spec_set_path + ) + data_item_path = staticmethod(DataLabelingServiceClient.data_item_path) + parse_data_item_path = staticmethod(DataLabelingServiceClient.parse_data_item_path) + dataset_path = staticmethod(DataLabelingServiceClient.dataset_path) + parse_dataset_path = staticmethod(DataLabelingServiceClient.parse_dataset_path) + evaluation_path = staticmethod(DataLabelingServiceClient.evaluation_path) + parse_evaluation_path = staticmethod( + DataLabelingServiceClient.parse_evaluation_path + ) evaluation_job_path = staticmethod(DataLabelingServiceClient.evaluation_job_path) + parse_evaluation_job_path = staticmethod( + DataLabelingServiceClient.parse_evaluation_job_path + ) + example_path = staticmethod(DataLabelingServiceClient.example_path) + parse_example_path = staticmethod(DataLabelingServiceClient.parse_example_path) + instruction_path = staticmethod(DataLabelingServiceClient.instruction_path) + parse_instruction_path = staticmethod( + DataLabelingServiceClient.parse_instruction_path + ) - dataset_path = staticmethod(DataLabelingServiceClient.dataset_path) + common_billing_account_path = staticmethod( + DataLabelingServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + DataLabelingServiceClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(DataLabelingServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + DataLabelingServiceClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + DataLabelingServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + DataLabelingServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(DataLabelingServiceClient.common_project_path) + parse_common_project_path = staticmethod( + DataLabelingServiceClient.parse_common_project_path + ) + + common_location_path = staticmethod(DataLabelingServiceClient.common_location_path) + parse_common_location_path = staticmethod( + DataLabelingServiceClient.parse_common_location_path + ) from_service_account_file = DataLabelingServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> DataLabelingServiceTransport: + """Return the transport used by the client instance. + + Returns: + DataLabelingServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(DataLabelingServiceClient).get_transport_class, type(DataLabelingServiceClient), @@ -87,6 +146,7 @@ def __init__( credentials: credentials.Credentials = None, transport: Union[str, DataLabelingServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the data labeling service client. @@ -102,16 +162,19 @@ def __init__( client_options (ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint, this is the default value for - the environment variable) and "auto" (auto switch to the default - mTLS endpoint if client SSL credentials is present). However, - the ``api_endpoint`` property takes precedence if provided. - (2) The ``client_cert_source`` property is used to provide client - SSL credentials for mutual TLS transport. If not provided, the - default SSL credentials will be used if present. + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -119,7 +182,10 @@ def __init__( """ self._client = DataLabelingServiceClient( - credentials=credentials, transport=transport, client_options=client_options, + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, ) async def create_dataset( @@ -167,7 +233,8 @@ async def create_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, dataset]): + has_flattened_params = any([parent, dataset]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -188,7 +255,7 @@ async def create_dataset( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_dataset, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -241,7 +308,8 @@ async def get_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -268,7 +336,7 @@ async def get_dataset( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -330,7 +398,8 @@ async def list_datasets( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -359,7 +428,7 @@ async def list_datasets( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -410,7 +479,8 @@ async def delete_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -437,7 +507,7 @@ async def delete_dataset( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -502,7 +572,8 @@ async def import_data( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, input_config]): + has_flattened_params = any([name, input_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -523,7 +594,7 @@ async def import_data( rpc = gapic_v1.method_async.wrap_method( self._client._transport.import_data, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -609,9 +680,8 @@ async def export_data( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any( - [name, annotated_dataset, filter, output_config] - ): + has_flattened_params = any([name, annotated_dataset, filter, output_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -644,7 +714,7 @@ async def export_data( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -704,7 +774,8 @@ async def get_data_item( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -731,7 +802,7 @@ async def get_data_item( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -794,7 +865,8 @@ async def list_data_items( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -823,7 +895,7 @@ async def list_data_items( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -885,7 +957,8 @@ async def get_annotated_dataset( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -912,7 +985,7 @@ async def get_annotated_dataset( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -976,7 +1049,8 @@ async def list_annotated_datasets( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1005,7 +1079,7 @@ async def list_annotated_datasets( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1056,7 +1130,7 @@ async def delete_annotated_dataset( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_annotated_dataset, default_timeout=None, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1127,7 +1201,8 @@ async def label_image( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, basic_config, feature]): + has_flattened_params = any([parent, basic_config, feature]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1150,7 +1225,7 @@ async def label_image( rpc = gapic_v1.method_async.wrap_method( self._client._transport.label_image, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1229,7 +1304,8 @@ async def label_video( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, basic_config, feature]): + has_flattened_params = any([parent, basic_config, feature]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1252,7 +1328,7 @@ async def label_video( rpc = gapic_v1.method_async.wrap_method( self._client._transport.label_video, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1331,7 +1407,8 @@ async def label_text( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, basic_config, feature]): + has_flattened_params = any([parent, basic_config, feature]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1354,7 +1431,7 @@ async def label_text( rpc = gapic_v1.method_async.wrap_method( self._client._transport.label_text, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1424,7 +1501,8 @@ async def get_example( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, filter]): + has_flattened_params = any([name, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1453,7 +1531,7 @@ async def get_example( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1516,7 +1594,8 @@ async def list_examples( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1545,7 +1624,7 @@ async def list_examples( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1616,7 +1695,8 @@ async def create_annotation_spec_set( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, annotation_spec_set]): + has_flattened_params = any([parent, annotation_spec_set]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1637,7 +1717,7 @@ async def create_annotation_spec_set( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_annotation_spec_set, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1693,7 +1773,8 @@ async def get_annotation_spec_set( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1720,7 +1801,7 @@ async def get_annotation_spec_set( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1783,7 +1864,8 @@ async def list_annotation_spec_sets( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1812,7 +1894,7 @@ async def list_annotation_spec_sets( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1864,7 +1946,8 @@ async def delete_annotation_spec_set( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1891,7 +1974,7 @@ async def delete_annotation_spec_set( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1954,7 +2037,8 @@ async def create_instruction( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, instruction]): + has_flattened_params = any([parent, instruction]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1975,7 +2059,7 @@ async def create_instruction( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_instruction, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2036,7 +2120,8 @@ async def get_instruction( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2063,7 +2148,7 @@ async def get_instruction( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2126,7 +2211,8 @@ async def list_instructions( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2155,7 +2241,7 @@ async def list_instructions( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2207,7 +2293,8 @@ async def delete_instruction( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2234,7 +2321,7 @@ async def delete_instruction( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2289,7 +2376,8 @@ async def get_evaluation( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2316,7 +2404,7 @@ async def get_evaluation( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2410,7 +2498,8 @@ async def search_evaluations( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2439,7 +2528,7 @@ async def search_evaluations( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2506,7 +2595,8 @@ async def search_example_comparisons( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2525,7 +2615,7 @@ async def search_example_comparisons( rpc = gapic_v1.method_async.wrap_method( self._client._transport.search_example_comparisons, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2594,7 +2684,8 @@ async def create_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, job]): + has_flattened_params = any([parent, job]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2615,7 +2706,7 @@ async def create_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2692,7 +2783,8 @@ async def update_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([evaluation_job, update_mask]): + has_flattened_params = any([evaluation_job, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2713,7 +2805,7 @@ async def update_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2772,7 +2864,8 @@ async def get_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2799,7 +2892,7 @@ async def get_evaluation_job( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2848,7 +2941,8 @@ async def pause_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2867,7 +2961,7 @@ async def pause_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.pause_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2915,7 +3009,8 @@ async def resume_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2934,7 +3029,7 @@ async def resume_evaluation_job( rpc = gapic_v1.method_async.wrap_method( self._client._transport.resume_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2980,7 +3075,8 @@ async def delete_evaluation_job( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3007,7 +3103,7 @@ async def delete_evaluation_job( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3076,7 +3172,8 @@ async def list_evaluation_jobs( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, filter]): + has_flattened_params = any([parent, filter]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3105,7 +3202,7 @@ async def list_evaluation_jobs( ), ), default_timeout=30.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3128,13 +3225,13 @@ async def list_evaluation_jobs( try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( "google-cloud-datalabeling", ).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() __all__ = ("DataLabelingServiceAsyncClient",) diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py index 9359be5..c90d144 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py @@ -16,22 +16,24 @@ # from collections import OrderedDict +from distutils import util import os import re -from typing import Callable, Dict, Sequence, Tuple, Type, Union +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import client_options as client_options_lib # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials # type: ignore from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -from google.api_core import operation -from google.api_core import operation_async +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore from google.cloud.datalabeling_v1beta1.services.data_labeling_service import pagers from google.cloud.datalabeling_v1beta1.types import annotation from google.cloud.datalabeling_v1beta1.types import annotation_spec_set @@ -52,7 +54,7 @@ from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from .transports.base import DataLabelingServiceTransport +from .transports.base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import DataLabelingServiceGrpcTransport from .transports.grpc_asyncio import DataLabelingServiceGrpcAsyncIOTransport @@ -93,7 +95,7 @@ def get_transport_class( class DataLabelingServiceClient(metaclass=DataLabelingServiceClientMeta): - """""" + """Service for the AI Platform Data Labeling API.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): @@ -149,6 +151,33 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> DataLabelingServiceTransport: + """Return the transport used by the client instance. + + Returns: + DataLabelingServiceTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def annotated_dataset_path( + project: str, dataset: str, annotated_dataset: str, + ) -> str: + """Return a fully-qualified annotated_dataset string.""" + return "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( + project=project, dataset=dataset, annotated_dataset=annotated_dataset, + ) + + @staticmethod + def parse_annotated_dataset_path(path: str) -> Dict[str, str]: + """Parse a annotated_dataset path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/annotatedDatasets/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def annotation_spec_set_path(project: str, annotation_spec_set: str,) -> str: """Return a fully-qualified annotation_spec_set string.""" @@ -165,6 +194,22 @@ def parse_annotation_spec_set_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def data_item_path(project: str, dataset: str, data_item: str,) -> str: + """Return a fully-qualified data_item string.""" + return "projects/{project}/datasets/{dataset}/dataItems/{data_item}".format( + project=project, dataset=dataset, data_item=data_item, + ) + + @staticmethod + def parse_data_item_path(path: str) -> Dict[str, str]: + """Parse a data_item path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/dataItems/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def dataset_path(project: str, dataset: str,) -> str: """Return a fully-qualified dataset string.""" @@ -178,6 +223,22 @@ def parse_dataset_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/datasets/(?P.+?)$", path) return m.groupdict() if m else {} + @staticmethod + def evaluation_path(project: str, dataset: str, evaluation: str,) -> str: + """Return a fully-qualified evaluation string.""" + return "projects/{project}/datasets/{dataset}/evaluations/{evaluation}".format( + project=project, dataset=dataset, evaluation=evaluation, + ) + + @staticmethod + def parse_evaluation_path(path: str) -> Dict[str, str]: + """Parse a evaluation path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/evaluations/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def evaluation_job_path(project: str, evaluation_job: str,) -> str: """Return a fully-qualified evaluation_job string.""" @@ -193,6 +254,27 @@ def parse_evaluation_job_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def example_path( + project: str, dataset: str, annotated_dataset: str, example: str, + ) -> str: + """Return a fully-qualified example string.""" + return "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}/examples/{example}".format( + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, + example=example, + ) + + @staticmethod + def parse_example_path(path: str) -> Dict[str, str]: + """Parse a example path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/datasets/(?P.+?)/annotatedDatasets/(?P.+?)/examples/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def instruction_path(project: str, instruction: str,) -> str: """Return a fully-qualified instruction string.""" @@ -208,12 +290,72 @@ def parse_instruction_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, - credentials: credentials.Credentials = None, - transport: Union[str, DataLabelingServiceTransport] = None, - client_options: ClientOptions = None, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, DataLabelingServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the data labeling service client. @@ -226,48 +368,74 @@ def __init__( transport (Union[str, ~.DataLabelingServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. + client_options (client_options_lib.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint, this is the default value for - the environment variable) and "auto" (auto switch to the default - mTLS endpoint if client SSL credentials is present). However, - the ``api_endpoint`` property takes precedence if provided. - (2) The ``client_cert_source`` property is used to provide client - SSL credentials for mutual TLS transport. If not provided, the - default SSL credentials will be used if present. + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport creation failed for any reason. """ if isinstance(client_options, dict): - client_options = ClientOptions.from_dict(client_options) + client_options = client_options_lib.from_dict(client_options) if client_options is None: - client_options = ClientOptions.ClientOptions() + client_options = client_options_lib.ClientOptions() + + # Create SSL credentials for mutual TLS if needed. + use_client_cert = bool( + util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + ) - if client_options.api_endpoint is None: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") + ssl_credentials = None + is_mtls = False + if use_client_cert: + if client_options.client_cert_source: + import grpc # type: ignore + + cert, key = client_options.client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + is_mtls = True + else: + creds = SslCredentials() + is_mtls = creds.is_mtls + ssl_credentials = creds.ssl_credentials if is_mtls else None + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + else: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") if use_mtls_env == "never": - client_options.api_endpoint = self.DEFAULT_ENDPOINT + api_endpoint = self.DEFAULT_ENDPOINT elif use_mtls_env == "always": - client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT + api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - has_client_cert_source = ( - client_options.client_cert_source is not None - or mtls.has_default_client_cert_source() - ) - client_options.api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT - if has_client_cert_source - else self.DEFAULT_ENDPOINT + api_endpoint = ( + self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT ) else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" ) # Save or instantiate the transport. @@ -291,11 +459,11 @@ def __init__( self._transport = Transport( credentials=credentials, credentials_file=client_options.credentials_file, - host=client_options.api_endpoint, + host=api_endpoint, scopes=client_options.scopes, - api_mtls_endpoint=client_options.api_endpoint, - client_cert_source=client_options.client_cert_source, + ssl_channel_credentials=ssl_credentials, quota_project_id=client_options.quota_project_id, + client_info=client_info, ) def create_dataset( @@ -3215,13 +3383,13 @@ def list_evaluation_jobs( try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( "google-cloud-datalabeling", ).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() __all__ = ("DataLabelingServiceClient",) diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py index e38ee72..8b6aaee 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py @@ -19,7 +19,7 @@ import typing import pkg_resources -from google import auth +from google import auth # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -42,13 +42,13 @@ try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( "google-cloud-datalabeling", ).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() class DataLabelingServiceTransport(abc.ABC): @@ -64,6 +64,7 @@ def __init__( credentials_file: typing.Optional[str] = None, scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, quota_project_id: typing.Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. @@ -81,6 +82,11 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -108,13 +114,13 @@ def __init__( self._credentials = credentials # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages() + self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self): + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_dataset: gapic_v1.method.wrap_method( - self.create_dataset, default_timeout=30.0, client_info=_client_info, + self.create_dataset, default_timeout=30.0, client_info=client_info, ), self.get_dataset: gapic_v1.method.wrap_method( self.get_dataset, @@ -127,7 +133,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_datasets: gapic_v1.method.wrap_method( self.list_datasets, @@ -140,7 +146,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_dataset: gapic_v1.method.wrap_method( self.delete_dataset, @@ -153,10 +159,10 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.import_data: gapic_v1.method.wrap_method( - self.import_data, default_timeout=30.0, client_info=_client_info, + self.import_data, default_timeout=30.0, client_info=client_info, ), self.export_data: gapic_v1.method.wrap_method( self.export_data, @@ -169,7 +175,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_data_item: gapic_v1.method.wrap_method( self.get_data_item, @@ -182,7 +188,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_data_items: gapic_v1.method.wrap_method( self.list_data_items, @@ -195,7 +201,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_annotated_dataset: gapic_v1.method.wrap_method( self.get_annotated_dataset, @@ -208,7 +214,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_annotated_datasets: gapic_v1.method.wrap_method( self.list_annotated_datasets, @@ -221,21 +227,21 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_annotated_dataset: gapic_v1.method.wrap_method( self.delete_annotated_dataset, default_timeout=None, - client_info=_client_info, + client_info=client_info, ), self.label_image: gapic_v1.method.wrap_method( - self.label_image, default_timeout=30.0, client_info=_client_info, + self.label_image, default_timeout=30.0, client_info=client_info, ), self.label_video: gapic_v1.method.wrap_method( - self.label_video, default_timeout=30.0, client_info=_client_info, + self.label_video, default_timeout=30.0, client_info=client_info, ), self.label_text: gapic_v1.method.wrap_method( - self.label_text, default_timeout=30.0, client_info=_client_info, + self.label_text, default_timeout=30.0, client_info=client_info, ), self.get_example: gapic_v1.method.wrap_method( self.get_example, @@ -248,7 +254,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_examples: gapic_v1.method.wrap_method( self.list_examples, @@ -261,12 +267,12 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.create_annotation_spec_set: gapic_v1.method.wrap_method( self.create_annotation_spec_set, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_annotation_spec_set: gapic_v1.method.wrap_method( self.get_annotation_spec_set, @@ -279,7 +285,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_annotation_spec_sets: gapic_v1.method.wrap_method( self.list_annotation_spec_sets, @@ -292,7 +298,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_annotation_spec_set: gapic_v1.method.wrap_method( self.delete_annotation_spec_set, @@ -305,10 +311,10 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.create_instruction: gapic_v1.method.wrap_method( - self.create_instruction, default_timeout=30.0, client_info=_client_info, + self.create_instruction, default_timeout=30.0, client_info=client_info, ), self.get_instruction: gapic_v1.method.wrap_method( self.get_instruction, @@ -321,7 +327,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_instructions: gapic_v1.method.wrap_method( self.list_instructions, @@ -334,7 +340,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_instruction: gapic_v1.method.wrap_method( self.delete_instruction, @@ -347,7 +353,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_evaluation: gapic_v1.method.wrap_method( self.get_evaluation, @@ -360,7 +366,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.search_evaluations: gapic_v1.method.wrap_method( self.search_evaluations, @@ -373,22 +379,22 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.search_example_comparisons: gapic_v1.method.wrap_method( self.search_example_comparisons, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.create_evaluation_job: gapic_v1.method.wrap_method( self.create_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.update_evaluation_job: gapic_v1.method.wrap_method( self.update_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.get_evaluation_job: gapic_v1.method.wrap_method( self.get_evaluation_job, @@ -401,17 +407,17 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.pause_evaluation_job: gapic_v1.method.wrap_method( self.pause_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.resume_evaluation_job: gapic_v1.method.wrap_method( self.resume_evaluation_job, default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.delete_evaluation_job: gapic_v1.method.wrap_method( self.delete_evaluation_job, @@ -424,7 +430,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), self.list_evaluation_jobs: gapic_v1.method.wrap_method( self.list_evaluation_jobs, @@ -437,7 +443,7 @@ def _prep_wrapped_messages(self): ), ), default_timeout=30.0, - client_info=_client_info, + client_info=client_info, ), } diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py index 8ab57b5..f242bad 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py @@ -15,15 +15,16 @@ # limitations under the License. # +import warnings from typing import Callable, Dict, Optional, Sequence, Tuple from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 # type: ignore from google import auth # type: ignore from google.auth import credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - import grpc # type: ignore from google.cloud.datalabeling_v1beta1.types import annotation_spec_set @@ -40,12 +41,14 @@ from google.longrunning import operations_pb2 as operations # type: ignore from google.protobuf import empty_pb2 as empty # type: ignore -from .base import DataLabelingServiceTransport +from .base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO class DataLabelingServiceGrpcTransport(DataLabelingServiceTransport): """gRPC backend transport for DataLabelingService. + Service for the AI Platform Data Labeling API. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -66,7 +69,9 @@ def __init__( channel: grpc.Channel = None, api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id: Optional[str] = None + ssl_channel_credentials: grpc.ChannelCredentials = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the transport. @@ -85,16 +90,23 @@ def __init__( ignored if ``channel`` is provided. channel (Optional[grpc.Channel]): A ``Channel`` instance through which to make calls. - api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If - provided, it overrides the ``host`` argument and tries to create + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A - callback to provide client SSL certificate bytes and private key - bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` - is None. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -102,6 +114,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -109,7 +123,13 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: + warnings.warn( + "api_mtls_endpoint and client_cert_source are deprecated", + DeprecationWarning, + ) + host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -140,6 +160,24 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials + else: + host = host if ":" in host else host + ":443" + + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_channel_credentials, + scopes=scopes or self.AUTH_SCOPES, + quota_project_id=quota_project_id, + ) self._stubs = {} # type: Dict[str, Callable] @@ -150,6 +188,7 @@ def __init__( credentials_file=credentials_file, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + client_info=client_info, ) @classmethod @@ -160,7 +199,7 @@ def create_channel( credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, - **kwargs + **kwargs, ) -> grpc.Channel: """Create and return a gRPC channel object. Args: @@ -194,24 +233,13 @@ def create_channel( credentials_file=credentials_file, scopes=scopes, quota_project_id=quota_project_id, - **kwargs + **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Sanity check: Only create a new channel if we do not already - # have one. - if not hasattr(self, "_grpc_channel"): - self._grpc_channel = self.create_channel( - self._host, credentials=self._credentials, - ) - - # Return the channel from cache. return self._grpc_channel @property diff --git a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py index 79fd1cf..223a86f 100644 --- a/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py +++ b/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py @@ -15,10 +15,13 @@ # limitations under the License. # +import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore +from google import auth # type: ignore from google.auth import credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -39,13 +42,15 @@ from google.longrunning import operations_pb2 as operations # type: ignore from google.protobuf import empty_pb2 as empty # type: ignore -from .base import DataLabelingServiceTransport +from .base import DataLabelingServiceTransport, DEFAULT_CLIENT_INFO from .grpc import DataLabelingServiceGrpcTransport class DataLabelingServiceGrpcAsyncIOTransport(DataLabelingServiceTransport): """gRPC AsyncIO backend transport for DataLabelingService. + Service for the AI Platform Data Labeling API. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -108,7 +113,9 @@ def __init__( channel: aio.Channel = None, api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the transport. @@ -128,16 +135,23 @@ def __init__( are passed to :func:`google.auth.default`. channel (Optional[aio.Channel]): A ``Channel`` instance through which to make calls. - api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If - provided, it overrides the ``host`` argument and tries to create + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A - callback to provide client SSL certificate bytes and private key - bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` - is None. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -145,6 +159,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -152,13 +168,24 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: + warnings.warn( + "api_mtls_endpoint and client_cert_source are deprecated", + DeprecationWarning, + ) + host = ( api_mtls_endpoint if ":" in api_mtls_endpoint else api_mtls_endpoint + ":443" ) + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + # Create SSL credentials with client_cert_source or application # default SSL credentials. if client_cert_source: @@ -178,6 +205,24 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials + else: + host = host if ":" in host else host + ":443" + + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_channel_credentials, + scopes=scopes or self.AUTH_SCOPES, + quota_project_id=quota_project_id, + ) # Run the base constructor. super().__init__( @@ -186,6 +231,7 @@ def __init__( credentials_file=credentials_file, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + client_info=client_info, ) self._stubs = {} @@ -197,13 +243,6 @@ def grpc_channel(self) -> aio.Channel: This property caches on the instance; repeated calls return the same channel. """ - # Sanity check: Only create a new channel if we do not already - # have one. - if not hasattr(self, "_grpc_channel"): - self._grpc_channel = self.create_channel( - self._host, credentials=self._credentials, - ) - # Return the channel from cache. return self._grpc_channel diff --git a/google/cloud/datalabeling_v1beta1/types/annotation.py b/google/cloud/datalabeling_v1beta1/types/annotation.py index 6e75d18..c237644 100644 --- a/google/cloud/datalabeling_v1beta1/types/annotation.py +++ b/google/cloud/datalabeling_v1beta1/types/annotation.py @@ -273,7 +273,7 @@ class BoundingPoly(proto.Message): The bounding polygon vertices. """ - vertices = proto.RepeatedField(proto.MESSAGE, number=1, message=Vertex,) + vertices = proto.RepeatedField(proto.MESSAGE, number=1, message="Vertex",) class NormalizedBoundingPoly(proto.Message): @@ -285,7 +285,7 @@ class NormalizedBoundingPoly(proto.Message): """ normalized_vertices = proto.RepeatedField( - proto.MESSAGE, number=1, message=NormalizedVertex, + proto.MESSAGE, number=1, message="NormalizedVertex", ) @@ -303,11 +303,11 @@ class ImageBoundingPolyAnnotation(proto.Message): """ bounding_poly = proto.Field( - proto.MESSAGE, number=2, oneof="bounded_area", message=BoundingPoly, + proto.MESSAGE, number=2, oneof="bounded_area", message="BoundingPoly", ) normalized_bounding_poly = proto.Field( - proto.MESSAGE, number=3, oneof="bounded_area", message=NormalizedBoundingPoly, + proto.MESSAGE, number=3, oneof="bounded_area", message="NormalizedBoundingPoly", ) annotation_spec = proto.Field( @@ -323,7 +323,7 @@ class Polyline(proto.Message): The polyline vertices. """ - vertices = proto.RepeatedField(proto.MESSAGE, number=1, message=Vertex,) + vertices = proto.RepeatedField(proto.MESSAGE, number=1, message="Vertex",) class NormalizedPolyline(proto.Message): @@ -335,7 +335,7 @@ class NormalizedPolyline(proto.Message): """ normalized_vertices = proto.RepeatedField( - proto.MESSAGE, number=1, message=NormalizedVertex, + proto.MESSAGE, number=1, message="NormalizedVertex", ) @@ -351,10 +351,10 @@ class ImagePolylineAnnotation(proto.Message): Label of this polyline. """ - polyline = proto.Field(proto.MESSAGE, number=2, oneof="poly", message=Polyline,) + polyline = proto.Field(proto.MESSAGE, number=2, oneof="poly", message="Polyline",) normalized_polyline = proto.Field( - proto.MESSAGE, number=3, oneof="poly", message=NormalizedPolyline, + proto.MESSAGE, number=3, oneof="poly", message="NormalizedPolyline", ) annotation_spec = proto.Field( @@ -467,7 +467,7 @@ class VideoClassificationAnnotation(proto.Message): Label of the segment specified by time_segment. """ - time_segment = proto.Field(proto.MESSAGE, number=1, message=TimeSegment,) + time_segment = proto.Field(proto.MESSAGE, number=1, message="TimeSegment",) annotation_spec = proto.Field( proto.MESSAGE, number=2, message=annotation_spec_set.AnnotationSpec, @@ -489,11 +489,11 @@ class ObjectTrackingFrame(proto.Message): """ bounding_poly = proto.Field( - proto.MESSAGE, number=1, oneof="bounded_area", message=BoundingPoly, + proto.MESSAGE, number=1, oneof="bounded_area", message="BoundingPoly", ) normalized_bounding_poly = proto.Field( - proto.MESSAGE, number=2, oneof="bounded_area", message=NormalizedBoundingPoly, + proto.MESSAGE, number=2, oneof="bounded_area", message="NormalizedBoundingPoly", ) time_offset = proto.Field(proto.MESSAGE, number=3, message=duration.Duration,) @@ -518,10 +518,10 @@ class VideoObjectTrackingAnnotation(proto.Message): proto.MESSAGE, number=1, message=annotation_spec_set.AnnotationSpec, ) - time_segment = proto.Field(proto.MESSAGE, number=2, message=TimeSegment,) + time_segment = proto.Field(proto.MESSAGE, number=2, message="TimeSegment",) object_tracking_frames = proto.RepeatedField( - proto.MESSAGE, number=3, message=ObjectTrackingFrame, + proto.MESSAGE, number=3, message="ObjectTrackingFrame", ) @@ -540,7 +540,7 @@ class VideoEventAnnotation(proto.Message): proto.MESSAGE, number=1, message=annotation_spec_set.AnnotationSpec, ) - time_segment = proto.Field(proto.MESSAGE, number=2, message=TimeSegment,) + time_segment = proto.Field(proto.MESSAGE, number=2, message="TimeSegment",) class AnnotationMetadata(proto.Message): diff --git a/google/cloud/datalabeling_v1beta1/types/data_payloads.py b/google/cloud/datalabeling_v1beta1/types/data_payloads.py index 6117229..bb58d25 100644 --- a/google/cloud/datalabeling_v1beta1/types/data_payloads.py +++ b/google/cloud/datalabeling_v1beta1/types/data_payloads.py @@ -101,7 +101,7 @@ class VideoPayload(proto.Message): video_uri = proto.Field(proto.STRING, number=2) video_thumbnails = proto.RepeatedField( - proto.MESSAGE, number=3, message=VideoThumbnail, + proto.MESSAGE, number=3, message="VideoThumbnail", ) frame_rate = proto.Field(proto.FLOAT, number=4) diff --git a/noxfile.py b/noxfile.py index 9f35fe6..3515f4e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -28,7 +28,7 @@ DEFAULT_PYTHON_VERSION = "3.8" SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -72,7 +72,9 @@ def default(session): # Install all test dependencies, then install this package in-place. session.install("asyncmock", "pytest-asyncio") - session.install("mock", "pytest", "pytest-cov") + session.install( + "mock", "pytest", "pytest-cov", + ) session.install("-e", ".") # Run py.test against the unit tests. @@ -173,7 +175,9 @@ def docfx(session): """Build the docfx yaml files for this library.""" session.install("-e", ".") - session.install("sphinx", "alabaster", "recommonmark", "sphinx-docfx-yaml") + # sphinx-docfx-yaml supports up to sphinx version 1.5.5. + # https://github.com/docascode/sphinx-docfx-yaml/issues/97 + session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 5660f08..b90eef0 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -37,22 +37,28 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], + 'ignored_versions': ["2.7"], + + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - "envs": {}, + 'envs': {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append(".") + sys.path.append('.') from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -67,12 +73,12 @@ def get_pytest_env_vars(): ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] + env_key = TEST_CONFIG['gcloud_project_env'] # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) + ret.update(TEST_CONFIG['envs']) return ret @@ -81,7 +87,7 @@ def get_pytest_env_vars(): ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) @@ -130,16 +136,29 @@ def _determine_local_import_names(start_dir): @nox.session def lint(session): - session.install("flake8", "flake8-import-order") + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - ".", + "." ] session.run("flake8", *args) +# +# Black +# + +@nox.session +def blacken(session): + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) # # Sample Tests @@ -180,9 +199,9 @@ def py(session): if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip( - "SKIPPED: {} tests are disabled for this sample.".format(session.python) - ) + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) # @@ -199,6 +218,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") diff --git a/scripts/decrypt-secrets.sh b/scripts/decrypt-secrets.sh index ff599eb..21f6d2a 100755 --- a/scripts/decrypt-secrets.sh +++ b/scripts/decrypt-secrets.sh @@ -20,14 +20,27 @@ ROOT=$( dirname "$DIR" ) # Work from the project root. cd $ROOT +# Prevent it from overriding files. +# We recommend that sample authors use their own service account files and cloud project. +# In that case, they are supposed to prepare these files by themselves. +if [[ -f "testing/test-env.sh" ]] || \ + [[ -f "testing/service-account.json" ]] || \ + [[ -f "testing/client-secrets.json" ]]; then + echo "One or more target files exist, aborting." + exit 1 +fi + # Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources. PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}" gcloud secrets versions access latest --secret="python-docs-samples-test-env" \ + --project="${PROJECT_ID}" \ > testing/test-env.sh gcloud secrets versions access latest \ --secret="python-docs-samples-service-account" \ + --project="${PROJECT_ID}" \ > testing/service-account.json gcloud secrets versions access latest \ --secret="python-docs-samples-client-secrets" \ - > testing/client-secrets.json \ No newline at end of file + --project="${PROJECT_ID}" \ + > testing/client-secrets.json diff --git a/scripts/fixup_datalabeling_v1beta1_keywords.py b/scripts/fixup_datalabeling_v1beta1_keywords.py index 9a49fac..ed84f93 100644 --- a/scripts/fixup_datalabeling_v1beta1_keywords.py +++ b/scripts/fixup_datalabeling_v1beta1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/synth.metadata b/synth.metadata index 746af20..a6423e9 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,22 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-datalabeling.git", - "sha": "448682cf313c58ff9c61303d13d72a04b3dc34af" + "remote": "git@github.com:googleapis/python-datalabeling.git", + "sha": "3dac8e068118b5dea339653b0a731461c236c545" + } + }, + { + "git": { + "name": "googleapis", + "remote": "https://github.com/googleapis/googleapis.git", + "sha": "5fdb685a684269e07c10c7518372eb5d7b6bc0a9", + "internalRef": "342906697" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "bd0deaa1113b588d70449535ab9cbf0f2bd0e72f" + "sha": "7fcc405a579d5d53a726ff3da1b7c8c08f0f2d58" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "bd0deaa1113b588d70449535ab9cbf0f2bd0e72f" + "sha": "7fcc405a579d5d53a726ff3da1b7c8c08f0f2d58" } } ], diff --git a/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py b/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py index 7d9aada..8e68492 100644 --- a/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py +++ b/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py @@ -31,7 +31,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.api_core import operation_async +from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.auth import credentials from google.auth.exceptions import MutualTLSChannelError @@ -61,7 +61,7 @@ from google.cloud.datalabeling_v1beta1.types import operations from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import any_pb2 as any # type: ignore +from google.protobuf import any_pb2 as gp_any # type: ignore from google.protobuf import duration_pb2 as duration # type: ignore from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import timestamp_pb2 as timestamp # type: ignore @@ -123,12 +123,12 @@ def test_data_labeling_service_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "datalabeling.googleapis.com:443" + assert client.transport._host == "datalabeling.googleapis.com:443" def test_data_labeling_service_client_get_transport_class(): @@ -188,14 +188,14 @@ def test_data_labeling_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - api_mtls_endpoint="squid.clam.whelk", - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "never"}): + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class() @@ -204,14 +204,14 @@ def test_data_labeling_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "always"}): + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class() @@ -220,90 +220,185 @@ def test_data_labeling_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", and client_cert_source is provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class() + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class() + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + ssl_channel_credentials=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + DataLabelingServiceClient, + transports.DataLabelingServiceGrpcTransport, + "grpc", + "true", + ), + ( + DataLabelingServiceAsyncClient, + transports.DataLabelingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + DataLabelingServiceClient, + transports.DataLabelingServiceGrpcTransport, + "grpc", + "false", + ), + ( + DataLabelingServiceAsyncClient, + transports.DataLabelingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + DataLabelingServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DataLabelingServiceClient), +) +@mock.patch.object( + DataLabelingServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DataLabelingServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_data_labeling_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): options = client_options.ClientOptions( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=client_cert_source_callback, - quota_project_id=None, - ) - - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", and default_client_cert_source is provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): - with mock.patch.object(transport_class, "__init__") as patched: + ssl_channel_creds = mock.Mock() with mock.patch( - "google.auth.transport.mtls.has_default_client_cert_source", - return_value=True, + "grpc.ssl_channel_credentials", return_value=ssl_channel_creds ): patched.return_value = None - client = client_class() + client = client_class(client_options=options) + + if use_client_cert_env == "false": + expected_ssl_channel_creds = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_ssl_channel_creds = ssl_channel_creds + expected_host = client.DEFAULT_MTLS_ENDPOINT + patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, + host=expected_host, scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=expected_ssl_channel_creds, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", but client_cert_source and default_client_cert_source are None. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.mtls.has_default_client_cert_source", - return_value=False, + "google.auth.transport.grpc.SslCredentials.__init__", return_value=None ): - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, - quota_project_id=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class() - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, - quota_project_id="octopus", - ) + with mock.patch( + "google.auth.transport.grpc.SslCredentials.is_mtls", + new_callable=mock.PropertyMock, + ) as is_mtls_mock: + with mock.patch( + "google.auth.transport.grpc.SslCredentials.ssl_credentials", + new_callable=mock.PropertyMock, + ) as ssl_credentials_mock: + if use_client_cert_env == "false": + is_mtls_mock.return_value = False + ssl_credentials_mock.return_value = None + expected_host = client.DEFAULT_ENDPOINT + expected_ssl_channel_creds = None + else: + is_mtls_mock.return_value = True + ssl_credentials_mock.return_value = mock.Mock() + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_ssl_channel_creds = ( + ssl_credentials_mock.return_value + ) + + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + ssl_channel_credentials=expected_ssl_channel_creds, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + ): + with mock.patch( + "google.auth.transport.grpc.SslCredentials.is_mtls", + new_callable=mock.PropertyMock, + ) as is_mtls_mock: + is_mtls_mock.return_value = False + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + ssl_channel_credentials=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) @pytest.mark.parametrize( @@ -334,9 +429,9 @@ def test_data_labeling_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -368,9 +463,9 @@ def test_data_labeling_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -387,9 +482,9 @@ def test_data_labeling_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - api_mtls_endpoint="squid.clam.whelk", - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -405,7 +500,7 @@ def test_create_dataset( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcd_dataset.Dataset( name="name_value", @@ -424,6 +519,7 @@ def test_create_dataset( assert args[0] == data_labeling_service.CreateDatasetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcd_dataset.Dataset) assert response.name == "name_value" @@ -442,19 +538,20 @@ def test_create_dataset_from_dict(): @pytest.mark.asyncio -async def test_create_dataset_async(transport: str = "grpc_asyncio"): +async def test_create_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcd_dataset.Dataset( @@ -472,7 +569,7 @@ async def test_create_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcd_dataset.Dataset) @@ -488,6 +585,11 @@ async def test_create_dataset_async(transport: str = "grpc_asyncio"): assert response.data_item_count == 1584 +@pytest.mark.asyncio +async def test_create_dataset_async_from_dict(): + await test_create_dataset_async(request_type=dict) + + def test_create_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -497,7 +599,7 @@ def test_create_dataset_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: call.return_value = gcd_dataset.Dataset() client.create_dataset(request) @@ -524,9 +626,7 @@ async def test_create_dataset_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcd_dataset.Dataset()) await client.create_dataset(request) @@ -545,7 +645,7 @@ def test_create_dataset_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcd_dataset.Dataset() @@ -585,9 +685,7 @@ async def test_create_dataset_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcd_dataset.Dataset() @@ -636,7 +734,7 @@ def test_get_dataset( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Dataset( name="name_value", @@ -655,6 +753,7 @@ def test_get_dataset( assert args[0] == data_labeling_service.GetDatasetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.Dataset) assert response.name == "name_value" @@ -673,19 +772,20 @@ def test_get_dataset_from_dict(): @pytest.mark.asyncio -async def test_get_dataset_async(transport: str = "grpc_asyncio"): +async def test_get_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.Dataset( @@ -703,7 +803,7 @@ async def test_get_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.Dataset) @@ -719,6 +819,11 @@ async def test_get_dataset_async(transport: str = "grpc_asyncio"): assert response.data_item_count == 1584 +@pytest.mark.asyncio +async def test_get_dataset_async_from_dict(): + await test_get_dataset_async(request_type=dict) + + def test_get_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -728,7 +833,7 @@ def test_get_dataset_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: call.return_value = dataset.Dataset() client.get_dataset(request) @@ -755,9 +860,7 @@ async def test_get_dataset_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.Dataset()) await client.get_dataset(request) @@ -776,7 +879,7 @@ def test_get_dataset_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Dataset() @@ -810,9 +913,7 @@ async def test_get_dataset_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Dataset() @@ -855,7 +956,7 @@ def test_list_datasets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_datasets), "__call__") as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDatasetsResponse( next_page_token="next_page_token_value", @@ -870,6 +971,7 @@ def test_list_datasets( assert args[0] == data_labeling_service.ListDatasetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatasetsPager) assert response.next_page_token == "next_page_token_value" @@ -880,19 +982,20 @@ def test_list_datasets_from_dict(): @pytest.mark.asyncio -async def test_list_datasets_async(transport: str = "grpc_asyncio"): +async def test_list_datasets_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListDatasetsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListDatasetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_datasets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDatasetsResponse( @@ -906,7 +1009,7 @@ async def test_list_datasets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListDatasetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDatasetsAsyncPager) @@ -914,6 +1017,11 @@ async def test_list_datasets_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_datasets_async_from_dict(): + await test_list_datasets_async(request_type=dict) + + def test_list_datasets_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -923,7 +1031,7 @@ def test_list_datasets_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_datasets), "__call__") as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: call.return_value = data_labeling_service.ListDatasetsResponse() client.list_datasets(request) @@ -950,9 +1058,7 @@ async def test_list_datasets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_datasets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDatasetsResponse() ) @@ -973,7 +1079,7 @@ def test_list_datasets_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_datasets), "__call__") as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDatasetsResponse() @@ -1013,9 +1119,7 @@ async def test_list_datasets_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_datasets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDatasetsResponse() @@ -1058,7 +1162,7 @@ def test_list_datasets_pager(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_datasets), "__call__") as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDatasetsResponse( @@ -1094,7 +1198,7 @@ def test_list_datasets_pages(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_datasets), "__call__") as call: + with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDatasetsResponse( @@ -1113,8 +1217,8 @@ def test_list_datasets_pages(): RuntimeError, ) pages = list(client.list_datasets(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -1125,9 +1229,7 @@ async def test_list_datasets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_datasets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_datasets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1164,9 +1266,7 @@ async def test_list_datasets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_datasets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_datasets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1186,10 +1286,10 @@ async def test_list_datasets_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_datasets(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_datasets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_dataset( @@ -1204,7 +1304,7 @@ def test_delete_dataset( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1225,19 +1325,20 @@ def test_delete_dataset_from_dict(): @pytest.mark.asyncio -async def test_delete_dataset_async(transport: str = "grpc_asyncio"): +async def test_delete_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1247,12 +1348,17 @@ async def test_delete_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteDatasetRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_dataset_async_from_dict(): + await test_delete_dataset_async(request_type=dict) + + def test_delete_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1262,7 +1368,7 @@ def test_delete_dataset_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: call.return_value = None client.delete_dataset(request) @@ -1289,9 +1395,7 @@ async def test_delete_dataset_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_dataset(request) @@ -1310,7 +1414,7 @@ def test_delete_dataset_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_dataset), "__call__") as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1344,9 +1448,7 @@ async def test_delete_dataset_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_dataset), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1389,7 +1491,7 @@ def test_import_data( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_data), "__call__") as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1410,19 +1512,20 @@ def test_import_data_from_dict(): @pytest.mark.asyncio -async def test_import_data_async(transport: str = "grpc_asyncio"): +async def test_import_data_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ImportDataRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ImportDataRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1434,12 +1537,17 @@ async def test_import_data_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ImportDataRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_import_data_async_from_dict(): + await test_import_data_async(request_type=dict) + + def test_import_data_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1449,7 +1557,7 @@ def test_import_data_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_data), "__call__") as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.import_data(request) @@ -1476,9 +1584,7 @@ async def test_import_data_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1499,7 +1605,7 @@ def test_import_data_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_data), "__call__") as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1546,9 +1652,7 @@ async def test_import_data_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1606,7 +1710,7 @@ def test_export_data( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_data), "__call__") as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1627,19 +1731,20 @@ def test_export_data_from_dict(): @pytest.mark.asyncio -async def test_export_data_async(transport: str = "grpc_asyncio"): +async def test_export_data_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ExportDataRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ExportDataRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1651,12 +1756,17 @@ async def test_export_data_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ExportDataRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_export_data_async_from_dict(): + await test_export_data_async(request_type=dict) + + def test_export_data_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1666,7 +1776,7 @@ def test_export_data_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_data), "__call__") as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.export_data(request) @@ -1693,9 +1803,7 @@ async def test_export_data_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1716,7 +1824,7 @@ def test_export_data_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_data), "__call__") as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1771,9 +1879,7 @@ async def test_export_data_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_data), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_data), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1839,7 +1945,7 @@ def test_get_data_item( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_data_item), "__call__") as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.DataItem( name="name_value", @@ -1855,6 +1961,7 @@ def test_get_data_item( assert args[0] == data_labeling_service.GetDataItemRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.DataItem) assert response.name == "name_value" @@ -1865,19 +1972,20 @@ def test_get_data_item_from_dict(): @pytest.mark.asyncio -async def test_get_data_item_async(transport: str = "grpc_asyncio"): +async def test_get_data_item_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetDataItemRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetDataItemRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_data_item), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.DataItem(name="name_value",) @@ -1889,7 +1997,7 @@ async def test_get_data_item_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetDataItemRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.DataItem) @@ -1897,6 +2005,11 @@ async def test_get_data_item_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_data_item_async_from_dict(): + await test_get_data_item_async(request_type=dict) + + def test_get_data_item_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1906,7 +2019,7 @@ def test_get_data_item_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_data_item), "__call__") as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: call.return_value = dataset.DataItem() client.get_data_item(request) @@ -1933,9 +2046,7 @@ async def test_get_data_item_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_data_item), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.DataItem()) await client.get_data_item(request) @@ -1954,7 +2065,7 @@ def test_get_data_item_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_data_item), "__call__") as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.DataItem() @@ -1988,9 +2099,7 @@ async def test_get_data_item_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_data_item), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_data_item), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.DataItem() @@ -2033,7 +2142,7 @@ def test_list_data_items( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDataItemsResponse( next_page_token="next_page_token_value", @@ -2048,6 +2157,7 @@ def test_list_data_items( assert args[0] == data_labeling_service.ListDataItemsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDataItemsPager) assert response.next_page_token == "next_page_token_value" @@ -2058,19 +2168,20 @@ def test_list_data_items_from_dict(): @pytest.mark.asyncio -async def test_list_data_items_async(transport: str = "grpc_asyncio"): +async def test_list_data_items_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListDataItemsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListDataItemsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_data_items), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDataItemsResponse( @@ -2084,7 +2195,7 @@ async def test_list_data_items_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListDataItemsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDataItemsAsyncPager) @@ -2092,6 +2203,11 @@ async def test_list_data_items_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_data_items_async_from_dict(): + await test_list_data_items_async(request_type=dict) + + def test_list_data_items_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2101,7 +2217,7 @@ def test_list_data_items_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: call.return_value = data_labeling_service.ListDataItemsResponse() client.list_data_items(request) @@ -2128,9 +2244,7 @@ async def test_list_data_items_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_data_items), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListDataItemsResponse() ) @@ -2151,7 +2265,7 @@ def test_list_data_items_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDataItemsResponse() @@ -2191,9 +2305,7 @@ async def test_list_data_items_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_data_items), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListDataItemsResponse() @@ -2236,7 +2348,7 @@ def test_list_data_items_pager(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDataItemsResponse( @@ -2276,7 +2388,7 @@ def test_list_data_items_pages(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_data_items), "__call__") as call: + with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListDataItemsResponse( @@ -2299,8 +2411,8 @@ def test_list_data_items_pages(): RuntimeError, ) pages = list(client.list_data_items(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -2311,9 +2423,7 @@ async def test_list_data_items_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_data_items), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_data_items), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2354,9 +2464,7 @@ async def test_list_data_items_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_data_items), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_data_items), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2380,10 +2488,10 @@ async def test_list_data_items_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_data_items(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_data_items(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_get_annotated_dataset( @@ -2400,7 +2508,7 @@ def test_get_annotated_dataset( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = dataset.AnnotatedDataset( @@ -2423,6 +2531,7 @@ def test_get_annotated_dataset( assert args[0] == data_labeling_service.GetAnnotatedDatasetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.AnnotatedDataset) assert response.name == "name_value" @@ -2450,18 +2559,21 @@ def test_get_annotated_dataset_from_dict(): @pytest.mark.asyncio -async def test_get_annotated_dataset_async(transport: str = "grpc_asyncio"): +async def test_get_annotated_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetAnnotatedDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetAnnotatedDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2483,7 +2595,7 @@ async def test_get_annotated_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetAnnotatedDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.AnnotatedDataset) @@ -2508,6 +2620,11 @@ async def test_get_annotated_dataset_async(transport: str = "grpc_asyncio"): assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_get_annotated_dataset_async_from_dict(): + await test_get_annotated_dataset_async(request_type=dict) + + def test_get_annotated_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2518,7 +2635,7 @@ def test_get_annotated_dataset_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: call.return_value = dataset.AnnotatedDataset() @@ -2547,7 +2664,7 @@ async def test_get_annotated_dataset_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.AnnotatedDataset() @@ -2570,7 +2687,7 @@ def test_get_annotated_dataset_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = dataset.AnnotatedDataset() @@ -2606,7 +2723,7 @@ async def test_get_annotated_dataset_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotated_dataset), "__call__" + type(client.transport.get_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = dataset.AnnotatedDataset() @@ -2654,7 +2771,7 @@ def test_list_annotated_datasets( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse( @@ -2670,6 +2787,7 @@ def test_list_annotated_datasets( assert args[0] == data_labeling_service.ListAnnotatedDatasetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAnnotatedDatasetsPager) assert response.next_page_token == "next_page_token_value" @@ -2680,18 +2798,21 @@ def test_list_annotated_datasets_from_dict(): @pytest.mark.asyncio -async def test_list_annotated_datasets_async(transport: str = "grpc_asyncio"): +async def test_list_annotated_datasets_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListAnnotatedDatasetsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListAnnotatedDatasetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2706,7 +2827,7 @@ async def test_list_annotated_datasets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListAnnotatedDatasetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAnnotatedDatasetsAsyncPager) @@ -2714,6 +2835,11 @@ async def test_list_annotated_datasets_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_annotated_datasets_async_from_dict(): + await test_list_annotated_datasets_async(request_type=dict) + + def test_list_annotated_datasets_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2724,7 +2850,7 @@ def test_list_annotated_datasets_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2753,7 +2879,7 @@ async def test_list_annotated_datasets_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2776,7 +2902,7 @@ def test_list_annotated_datasets_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2818,7 +2944,7 @@ async def test_list_annotated_datasets_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotatedDatasetsResponse() @@ -2863,7 +2989,7 @@ def test_list_annotated_datasets_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2908,7 +3034,7 @@ def test_list_annotated_datasets_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotated_datasets), "__call__" + type(client.transport.list_annotated_datasets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2935,8 +3061,8 @@ def test_list_annotated_datasets_pages(): RuntimeError, ) pages = list(client.list_annotated_datasets(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -2947,7 +3073,7 @@ async def test_list_annotated_datasets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), + type(client.transport.list_annotated_datasets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2993,7 +3119,7 @@ async def test_list_annotated_datasets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotated_datasets), + type(client.transport.list_annotated_datasets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -3022,10 +3148,10 @@ async def test_list_annotated_datasets_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_annotated_datasets(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_annotated_datasets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_annotated_dataset( @@ -3042,7 +3168,7 @@ def test_delete_annotated_dataset( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -3064,18 +3190,21 @@ def test_delete_annotated_dataset_from_dict(): @pytest.mark.asyncio -async def test_delete_annotated_dataset_async(transport: str = "grpc_asyncio"): +async def test_delete_annotated_dataset_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteAnnotatedDatasetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteAnnotatedDatasetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -3086,12 +3215,17 @@ async def test_delete_annotated_dataset_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteAnnotatedDatasetRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_annotated_dataset_async_from_dict(): + await test_delete_annotated_dataset_async(request_type=dict) + + def test_delete_annotated_dataset_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3102,7 +3236,7 @@ def test_delete_annotated_dataset_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: call.return_value = None @@ -3131,7 +3265,7 @@ async def test_delete_annotated_dataset_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotated_dataset), "__call__" + type(client.transport.delete_annotated_dataset), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -3159,7 +3293,7 @@ def test_label_image( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_image), "__call__") as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -3180,19 +3314,20 @@ def test_label_image_from_dict(): @pytest.mark.asyncio -async def test_label_image_async(transport: str = "grpc_asyncio"): +async def test_label_image_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.LabelImageRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.LabelImageRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_image), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -3204,12 +3339,17 @@ async def test_label_image_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.LabelImageRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_label_image_async_from_dict(): + await test_label_image_async(request_type=dict) + + def test_label_image_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3219,7 +3359,7 @@ def test_label_image_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_image), "__call__") as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.label_image(request) @@ -3246,9 +3386,7 @@ async def test_label_image_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_image), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -3269,7 +3407,7 @@ def test_label_image_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_image), "__call__") as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3323,9 +3461,7 @@ async def test_label_image_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_image), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_image), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3390,7 +3526,7 @@ def test_label_video( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_video), "__call__") as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -3411,19 +3547,20 @@ def test_label_video_from_dict(): @pytest.mark.asyncio -async def test_label_video_async(transport: str = "grpc_asyncio"): +async def test_label_video_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.LabelVideoRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.LabelVideoRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_video), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -3435,12 +3572,17 @@ async def test_label_video_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.LabelVideoRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_label_video_async_from_dict(): + await test_label_video_async(request_type=dict) + + def test_label_video_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3450,7 +3592,7 @@ def test_label_video_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_video), "__call__") as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.label_video(request) @@ -3477,9 +3619,7 @@ async def test_label_video_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_video), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -3500,7 +3640,7 @@ def test_label_video_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_video), "__call__") as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3554,9 +3694,7 @@ async def test_label_video_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_video), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_video), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3621,7 +3759,7 @@ def test_label_text( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_text), "__call__") as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -3642,19 +3780,19 @@ def test_label_text_from_dict(): @pytest.mark.asyncio -async def test_label_text_async(transport: str = "grpc_asyncio"): +async def test_label_text_async( + transport: str = "grpc_asyncio", request_type=data_labeling_service.LabelTextRequest +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.LabelTextRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_text), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -3666,12 +3804,17 @@ async def test_label_text_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.LabelTextRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_label_text_async_from_dict(): + await test_label_text_async(request_type=dict) + + def test_label_text_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3681,7 +3824,7 @@ def test_label_text_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_text), "__call__") as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.label_text(request) @@ -3708,9 +3851,7 @@ async def test_label_text_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_text), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -3731,7 +3872,7 @@ def test_label_text_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.label_text), "__call__") as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3785,9 +3926,7 @@ async def test_label_text_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.label_text), "__call__" - ) as call: + with mock.patch.object(type(client.transport.label_text), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3852,7 +3991,7 @@ def test_get_example( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_example), "__call__") as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Example( name="name_value", @@ -3868,6 +4007,7 @@ def test_get_example( assert args[0] == data_labeling_service.GetExampleRequest() # Establish that the response is the type that we expect. + assert isinstance(response, dataset.Example) assert response.name == "name_value" @@ -3878,19 +4018,20 @@ def test_get_example_from_dict(): @pytest.mark.asyncio -async def test_get_example_async(transport: str = "grpc_asyncio"): +async def test_get_example_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetExampleRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetExampleRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_example), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( dataset.Example(name="name_value",) @@ -3902,7 +4043,7 @@ async def test_get_example_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetExampleRequest() # Establish that the response is the type that we expect. assert isinstance(response, dataset.Example) @@ -3910,6 +4051,11 @@ async def test_get_example_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_example_async_from_dict(): + await test_get_example_async(request_type=dict) + + def test_get_example_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -3919,7 +4065,7 @@ def test_get_example_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_example), "__call__") as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: call.return_value = dataset.Example() client.get_example(request) @@ -3946,9 +4092,7 @@ async def test_get_example_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_example), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.Example()) await client.get_example(request) @@ -3967,7 +4111,7 @@ def test_get_example_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_example), "__call__") as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Example() @@ -4007,9 +4151,7 @@ async def test_get_example_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_example), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_example), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = dataset.Example() @@ -4056,7 +4198,7 @@ def test_list_examples( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListExamplesResponse( next_page_token="next_page_token_value", @@ -4071,6 +4213,7 @@ def test_list_examples( assert args[0] == data_labeling_service.ListExamplesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListExamplesPager) assert response.next_page_token == "next_page_token_value" @@ -4081,19 +4224,20 @@ def test_list_examples_from_dict(): @pytest.mark.asyncio -async def test_list_examples_async(transport: str = "grpc_asyncio"): +async def test_list_examples_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListExamplesRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListExamplesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_examples), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListExamplesResponse( @@ -4107,7 +4251,7 @@ async def test_list_examples_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListExamplesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListExamplesAsyncPager) @@ -4115,6 +4259,11 @@ async def test_list_examples_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_examples_async_from_dict(): + await test_list_examples_async(request_type=dict) + + def test_list_examples_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4124,7 +4273,7 @@ def test_list_examples_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: call.return_value = data_labeling_service.ListExamplesResponse() client.list_examples(request) @@ -4151,9 +4300,7 @@ async def test_list_examples_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_examples), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListExamplesResponse() ) @@ -4174,7 +4321,7 @@ def test_list_examples_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListExamplesResponse() @@ -4214,9 +4361,7 @@ async def test_list_examples_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_examples), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListExamplesResponse() @@ -4259,7 +4404,7 @@ def test_list_examples_pager(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListExamplesResponse( @@ -4295,7 +4440,7 @@ def test_list_examples_pages(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_examples), "__call__") as call: + with mock.patch.object(type(client.transport.list_examples), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( data_labeling_service.ListExamplesResponse( @@ -4314,8 +4459,8 @@ def test_list_examples_pages(): RuntimeError, ) pages = list(client.list_examples(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -4326,9 +4471,7 @@ async def test_list_examples_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_examples), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_examples), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4365,9 +4508,7 @@ async def test_list_examples_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_examples), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_examples), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4387,10 +4528,10 @@ async def test_list_examples_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_examples(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_examples(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_create_annotation_spec_set( @@ -4407,7 +4548,7 @@ def test_create_annotation_spec_set( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_annotation_spec_set.AnnotationSpecSet( @@ -4426,6 +4567,7 @@ def test_create_annotation_spec_set( assert args[0] == data_labeling_service.CreateAnnotationSpecSetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcd_annotation_spec_set.AnnotationSpecSet) assert response.name == "name_value" @@ -4442,18 +4584,21 @@ def test_create_annotation_spec_set_from_dict(): @pytest.mark.asyncio -async def test_create_annotation_spec_set_async(transport: str = "grpc_asyncio"): +async def test_create_annotation_spec_set_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateAnnotationSpecSetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateAnnotationSpecSetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4471,7 +4616,7 @@ async def test_create_annotation_spec_set_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateAnnotationSpecSetRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcd_annotation_spec_set.AnnotationSpecSet) @@ -4485,6 +4630,11 @@ async def test_create_annotation_spec_set_async(transport: str = "grpc_asyncio") assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_create_annotation_spec_set_async_from_dict(): + await test_create_annotation_spec_set_async(request_type=dict) + + def test_create_annotation_spec_set_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4495,7 +4645,7 @@ def test_create_annotation_spec_set_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: call.return_value = gcd_annotation_spec_set.AnnotationSpecSet() @@ -4524,7 +4674,7 @@ async def test_create_annotation_spec_set_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcd_annotation_spec_set.AnnotationSpecSet() @@ -4547,7 +4697,7 @@ def test_create_annotation_spec_set_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_annotation_spec_set.AnnotationSpecSet() @@ -4596,7 +4746,7 @@ async def test_create_annotation_spec_set_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_annotation_spec_set), "__call__" + type(client.transport.create_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_annotation_spec_set.AnnotationSpecSet() @@ -4657,7 +4807,7 @@ def test_get_annotation_spec_set( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec_set.AnnotationSpecSet( @@ -4676,6 +4826,7 @@ def test_get_annotation_spec_set( assert args[0] == data_labeling_service.GetAnnotationSpecSetRequest() # Establish that the response is the type that we expect. + assert isinstance(response, annotation_spec_set.AnnotationSpecSet) assert response.name == "name_value" @@ -4692,18 +4843,21 @@ def test_get_annotation_spec_set_from_dict(): @pytest.mark.asyncio -async def test_get_annotation_spec_set_async(transport: str = "grpc_asyncio"): +async def test_get_annotation_spec_set_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetAnnotationSpecSetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetAnnotationSpecSetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4721,7 +4875,7 @@ async def test_get_annotation_spec_set_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetAnnotationSpecSetRequest() # Establish that the response is the type that we expect. assert isinstance(response, annotation_spec_set.AnnotationSpecSet) @@ -4735,6 +4889,11 @@ async def test_get_annotation_spec_set_async(transport: str = "grpc_asyncio"): assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_get_annotation_spec_set_async_from_dict(): + await test_get_annotation_spec_set_async(request_type=dict) + + def test_get_annotation_spec_set_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4745,7 +4904,7 @@ def test_get_annotation_spec_set_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: call.return_value = annotation_spec_set.AnnotationSpecSet() @@ -4774,7 +4933,7 @@ async def test_get_annotation_spec_set_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( annotation_spec_set.AnnotationSpecSet() @@ -4797,7 +4956,7 @@ def test_get_annotation_spec_set_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec_set.AnnotationSpecSet() @@ -4833,7 +4992,7 @@ async def test_get_annotation_spec_set_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_annotation_spec_set), "__call__" + type(client.transport.get_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec_set.AnnotationSpecSet() @@ -4881,7 +5040,7 @@ def test_list_annotation_spec_sets( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse( @@ -4897,6 +5056,7 @@ def test_list_annotation_spec_sets( assert args[0] == data_labeling_service.ListAnnotationSpecSetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAnnotationSpecSetsPager) assert response.next_page_token == "next_page_token_value" @@ -4907,18 +5067,21 @@ def test_list_annotation_spec_sets_from_dict(): @pytest.mark.asyncio -async def test_list_annotation_spec_sets_async(transport: str = "grpc_asyncio"): +async def test_list_annotation_spec_sets_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListAnnotationSpecSetsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListAnnotationSpecSetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4933,7 +5096,7 @@ async def test_list_annotation_spec_sets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListAnnotationSpecSetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAnnotationSpecSetsAsyncPager) @@ -4941,6 +5104,11 @@ async def test_list_annotation_spec_sets_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_annotation_spec_sets_async_from_dict(): + await test_list_annotation_spec_sets_async(request_type=dict) + + def test_list_annotation_spec_sets_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -4951,7 +5119,7 @@ def test_list_annotation_spec_sets_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse() @@ -4980,7 +5148,7 @@ async def test_list_annotation_spec_sets_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListAnnotationSpecSetsResponse() @@ -5003,7 +5171,7 @@ def test_list_annotation_spec_sets_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse() @@ -5045,7 +5213,7 @@ async def test_list_annotation_spec_sets_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListAnnotationSpecSetsResponse() @@ -5090,7 +5258,7 @@ def test_list_annotation_spec_sets_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -5138,7 +5306,7 @@ def test_list_annotation_spec_sets_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_annotation_spec_sets), "__call__" + type(client.transport.list_annotation_spec_sets), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -5166,8 +5334,8 @@ def test_list_annotation_spec_sets_pages(): RuntimeError, ) pages = list(client.list_annotation_spec_sets(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -5178,7 +5346,7 @@ async def test_list_annotation_spec_sets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), + type(client.transport.list_annotation_spec_sets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -5227,7 +5395,7 @@ async def test_list_annotation_spec_sets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_annotation_spec_sets), + type(client.transport.list_annotation_spec_sets), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -5257,10 +5425,10 @@ async def test_list_annotation_spec_sets_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_annotation_spec_sets(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_annotation_spec_sets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_annotation_spec_set( @@ -5277,7 +5445,7 @@ def test_delete_annotation_spec_set( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5299,18 +5467,21 @@ def test_delete_annotation_spec_set_from_dict(): @pytest.mark.asyncio -async def test_delete_annotation_spec_set_async(transport: str = "grpc_asyncio"): +async def test_delete_annotation_spec_set_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteAnnotationSpecSetRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteAnnotationSpecSetRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -5321,12 +5492,17 @@ async def test_delete_annotation_spec_set_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteAnnotationSpecSetRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_annotation_spec_set_async_from_dict(): + await test_delete_annotation_spec_set_async(request_type=dict) + + def test_delete_annotation_spec_set_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5337,7 +5513,7 @@ def test_delete_annotation_spec_set_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: call.return_value = None @@ -5366,7 +5542,7 @@ async def test_delete_annotation_spec_set_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -5387,7 +5563,7 @@ def test_delete_annotation_spec_set_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5423,7 +5599,7 @@ async def test_delete_annotation_spec_set_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_annotation_spec_set), "__call__" + type(client.transport.delete_annotation_spec_set), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5468,7 +5644,7 @@ def test_create_instruction( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -5490,18 +5666,21 @@ def test_create_instruction_from_dict(): @pytest.mark.asyncio -async def test_create_instruction_async(transport: str = "grpc_asyncio"): +async def test_create_instruction_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateInstructionRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateInstructionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5514,12 +5693,17 @@ async def test_create_instruction_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateInstructionRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_create_instruction_async_from_dict(): + await test_create_instruction_async(request_type=dict) + + def test_create_instruction_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5530,7 +5714,7 @@ def test_create_instruction_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") @@ -5559,7 +5743,7 @@ async def test_create_instruction_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") @@ -5582,7 +5766,7 @@ def test_create_instruction_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -5625,7 +5809,7 @@ async def test_create_instruction_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_instruction), "__call__" + type(client.transport.create_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -5678,7 +5862,7 @@ def test_get_instruction( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instruction), "__call__") as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = instruction.Instruction( name="name_value", @@ -5697,6 +5881,7 @@ def test_get_instruction( assert args[0] == data_labeling_service.GetInstructionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, instruction.Instruction) assert response.name == "name_value" @@ -5715,19 +5900,20 @@ def test_get_instruction_from_dict(): @pytest.mark.asyncio -async def test_get_instruction_async(transport: str = "grpc_asyncio"): +async def test_get_instruction_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetInstructionRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetInstructionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instruction), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( instruction.Instruction( @@ -5745,7 +5931,7 @@ async def test_get_instruction_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetInstructionRequest() # Establish that the response is the type that we expect. assert isinstance(response, instruction.Instruction) @@ -5761,6 +5947,11 @@ async def test_get_instruction_async(transport: str = "grpc_asyncio"): assert response.blocking_resources == ["blocking_resources_value"] +@pytest.mark.asyncio +async def test_get_instruction_async_from_dict(): + await test_get_instruction_async(request_type=dict) + + def test_get_instruction_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5770,7 +5961,7 @@ def test_get_instruction_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instruction), "__call__") as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: call.return_value = instruction.Instruction() client.get_instruction(request) @@ -5797,9 +5988,7 @@ async def test_get_instruction_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instruction), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( instruction.Instruction() ) @@ -5820,7 +6009,7 @@ def test_get_instruction_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instruction), "__call__") as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = instruction.Instruction() @@ -5854,9 +6043,7 @@ async def test_get_instruction_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instruction), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instruction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = instruction.Instruction() @@ -5902,7 +6089,7 @@ def test_list_instructions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListInstructionsResponse( @@ -5918,6 +6105,7 @@ def test_list_instructions( assert args[0] == data_labeling_service.ListInstructionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstructionsPager) assert response.next_page_token == "next_page_token_value" @@ -5928,18 +6116,21 @@ def test_list_instructions_from_dict(): @pytest.mark.asyncio -async def test_list_instructions_async(transport: str = "grpc_asyncio"): +async def test_list_instructions_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListInstructionsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListInstructionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5954,7 +6145,7 @@ async def test_list_instructions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListInstructionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListInstructionsAsyncPager) @@ -5962,6 +6153,11 @@ async def test_list_instructions_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_instructions_async_from_dict(): + await test_list_instructions_async(request_type=dict) + + def test_list_instructions_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -5972,7 +6168,7 @@ def test_list_instructions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: call.return_value = data_labeling_service.ListInstructionsResponse() @@ -6001,7 +6197,7 @@ async def test_list_instructions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListInstructionsResponse() @@ -6024,7 +6220,7 @@ def test_list_instructions_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListInstructionsResponse() @@ -6066,7 +6262,7 @@ async def test_list_instructions_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListInstructionsResponse() @@ -6111,7 +6307,7 @@ def test_list_instructions_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6153,7 +6349,7 @@ def test_list_instructions_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_instructions), "__call__" + type(client.transport.list_instructions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6177,8 +6373,8 @@ def test_list_instructions_pages(): RuntimeError, ) pages = list(client.list_instructions(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -6189,7 +6385,7 @@ async def test_list_instructions_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), + type(client.transport.list_instructions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -6232,7 +6428,7 @@ async def test_list_instructions_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instructions), + type(client.transport.list_instructions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -6258,10 +6454,10 @@ async def test_list_instructions_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_instructions(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_instructions(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_delete_instruction( @@ -6277,7 +6473,7 @@ def test_delete_instruction( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -6299,18 +6495,21 @@ def test_delete_instruction_from_dict(): @pytest.mark.asyncio -async def test_delete_instruction_async(transport: str = "grpc_asyncio"): +async def test_delete_instruction_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteInstructionRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteInstructionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -6321,12 +6520,17 @@ async def test_delete_instruction_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteInstructionRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_instruction_async_from_dict(): + await test_delete_instruction_async(request_type=dict) + + def test_delete_instruction_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -6337,7 +6541,7 @@ def test_delete_instruction_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: call.return_value = None @@ -6366,7 +6570,7 @@ async def test_delete_instruction_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -6387,7 +6591,7 @@ def test_delete_instruction_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -6423,7 +6627,7 @@ async def test_delete_instruction_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_instruction), "__call__" + type(client.transport.delete_instruction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -6467,7 +6671,7 @@ def test_get_evaluation( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_evaluation), "__call__") as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = evaluation.Evaluation( name="name_value", @@ -6484,6 +6688,7 @@ def test_get_evaluation( assert args[0] == data_labeling_service.GetEvaluationRequest() # Establish that the response is the type that we expect. + assert isinstance(response, evaluation.Evaluation) assert response.name == "name_value" @@ -6501,19 +6706,20 @@ def test_get_evaluation_from_dict(): @pytest.mark.asyncio -async def test_get_evaluation_async(transport: str = "grpc_asyncio"): +async def test_get_evaluation_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetEvaluationRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetEvaluationRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation.Evaluation( @@ -6529,7 +6735,7 @@ async def test_get_evaluation_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetEvaluationRequest() # Establish that the response is the type that we expect. assert isinstance(response, evaluation.Evaluation) @@ -6544,6 +6750,11 @@ async def test_get_evaluation_async(transport: str = "grpc_asyncio"): assert response.evaluated_item_count == 2129 +@pytest.mark.asyncio +async def test_get_evaluation_async_from_dict(): + await test_get_evaluation_async(request_type=dict) + + def test_get_evaluation_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -6553,7 +6764,7 @@ def test_get_evaluation_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_evaluation), "__call__") as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: call.return_value = evaluation.Evaluation() client.get_evaluation(request) @@ -6580,9 +6791,7 @@ async def test_get_evaluation_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation.Evaluation() ) @@ -6603,7 +6812,7 @@ def test_get_evaluation_flattened(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_evaluation), "__call__") as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = evaluation.Evaluation() @@ -6637,9 +6846,7 @@ async def test_get_evaluation_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_evaluation), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = evaluation.Evaluation() @@ -6685,7 +6892,7 @@ def test_search_evaluations( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchEvaluationsResponse( @@ -6701,6 +6908,7 @@ def test_search_evaluations( assert args[0] == data_labeling_service.SearchEvaluationsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.SearchEvaluationsPager) assert response.next_page_token == "next_page_token_value" @@ -6711,18 +6919,21 @@ def test_search_evaluations_from_dict(): @pytest.mark.asyncio -async def test_search_evaluations_async(transport: str = "grpc_asyncio"): +async def test_search_evaluations_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.SearchEvaluationsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.SearchEvaluationsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6737,7 +6948,7 @@ async def test_search_evaluations_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.SearchEvaluationsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.SearchEvaluationsAsyncPager) @@ -6745,6 +6956,11 @@ async def test_search_evaluations_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_search_evaluations_async_from_dict(): + await test_search_evaluations_async(request_type=dict) + + def test_search_evaluations_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -6755,7 +6971,7 @@ def test_search_evaluations_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: call.return_value = data_labeling_service.SearchEvaluationsResponse() @@ -6784,7 +7000,7 @@ async def test_search_evaluations_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.SearchEvaluationsResponse() @@ -6807,7 +7023,7 @@ def test_search_evaluations_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchEvaluationsResponse() @@ -6849,7 +7065,7 @@ async def test_search_evaluations_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchEvaluationsResponse() @@ -6894,7 +7110,7 @@ def test_search_evaluations_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6936,7 +7152,7 @@ def test_search_evaluations_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_evaluations), "__call__" + type(client.transport.search_evaluations), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6960,8 +7176,8 @@ def test_search_evaluations_pages(): RuntimeError, ) pages = list(client.search_evaluations(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -6972,7 +7188,7 @@ async def test_search_evaluations_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), + type(client.transport.search_evaluations), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7015,7 +7231,7 @@ async def test_search_evaluations_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_evaluations), + type(client.transport.search_evaluations), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7041,10 +7257,10 @@ async def test_search_evaluations_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.search_evaluations(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.search_evaluations(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_search_example_comparisons( @@ -7061,7 +7277,7 @@ def test_search_example_comparisons( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchExampleComparisonsResponse( @@ -7077,6 +7293,7 @@ def test_search_example_comparisons( assert args[0] == data_labeling_service.SearchExampleComparisonsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.SearchExampleComparisonsPager) assert response.next_page_token == "next_page_token_value" @@ -7087,18 +7304,21 @@ def test_search_example_comparisons_from_dict(): @pytest.mark.asyncio -async def test_search_example_comparisons_async(transport: str = "grpc_asyncio"): +async def test_search_example_comparisons_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.SearchExampleComparisonsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.SearchExampleComparisonsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7113,7 +7333,7 @@ async def test_search_example_comparisons_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.SearchExampleComparisonsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.SearchExampleComparisonsAsyncPager) @@ -7121,6 +7341,11 @@ async def test_search_example_comparisons_async(transport: str = "grpc_asyncio") assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_search_example_comparisons_async_from_dict(): + await test_search_example_comparisons_async(request_type=dict) + + def test_search_example_comparisons_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -7131,7 +7356,7 @@ def test_search_example_comparisons_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: call.return_value = data_labeling_service.SearchExampleComparisonsResponse() @@ -7160,7 +7385,7 @@ async def test_search_example_comparisons_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.SearchExampleComparisonsResponse() @@ -7183,7 +7408,7 @@ def test_search_example_comparisons_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchExampleComparisonsResponse() @@ -7220,7 +7445,7 @@ async def test_search_example_comparisons_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.SearchExampleComparisonsResponse() @@ -7260,7 +7485,7 @@ def test_search_example_comparisons_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -7314,7 +7539,7 @@ def test_search_example_comparisons_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.search_example_comparisons), "__call__" + type(client.transport.search_example_comparisons), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -7344,8 +7569,8 @@ def test_search_example_comparisons_pages(): RuntimeError, ) pages = list(client.search_example_comparisons(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -7356,7 +7581,7 @@ async def test_search_example_comparisons_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), + type(client.transport.search_example_comparisons), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7411,7 +7636,7 @@ async def test_search_example_comparisons_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.search_example_comparisons), + type(client.transport.search_example_comparisons), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -7443,10 +7668,10 @@ async def test_search_example_comparisons_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.search_example_comparisons(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.search_example_comparisons(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_create_evaluation_job( @@ -7463,7 +7688,7 @@ def test_create_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob( @@ -7485,6 +7710,7 @@ def test_create_evaluation_job( assert args[0] == data_labeling_service.CreateEvaluationJobRequest() # Establish that the response is the type that we expect. + assert isinstance(response, evaluation_job.EvaluationJob) assert response.name == "name_value" @@ -7507,18 +7733,21 @@ def test_create_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_create_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_create_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.CreateEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.CreateEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7539,7 +7768,7 @@ async def test_create_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.CreateEvaluationJobRequest() # Establish that the response is the type that we expect. assert isinstance(response, evaluation_job.EvaluationJob) @@ -7559,6 +7788,11 @@ async def test_create_evaluation_job_async(transport: str = "grpc_asyncio"): assert response.label_missing_ground_truth is True +@pytest.mark.asyncio +async def test_create_evaluation_job_async_from_dict(): + await test_create_evaluation_job_async(request_type=dict) + + def test_create_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -7569,7 +7803,7 @@ def test_create_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: call.return_value = evaluation_job.EvaluationJob() @@ -7598,7 +7832,7 @@ async def test_create_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation_job.EvaluationJob() @@ -7621,7 +7855,7 @@ def test_create_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -7663,7 +7897,7 @@ async def test_create_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_evaluation_job), "__call__" + type(client.transport.create_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -7717,7 +7951,7 @@ def test_update_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_evaluation_job.EvaluationJob( @@ -7739,6 +7973,7 @@ def test_update_evaluation_job( assert args[0] == data_labeling_service.UpdateEvaluationJobRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcd_evaluation_job.EvaluationJob) assert response.name == "name_value" @@ -7761,18 +7996,21 @@ def test_update_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_update_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_update_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.UpdateEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.UpdateEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7793,7 +8031,7 @@ async def test_update_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.UpdateEvaluationJobRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcd_evaluation_job.EvaluationJob) @@ -7813,6 +8051,11 @@ async def test_update_evaluation_job_async(transport: str = "grpc_asyncio"): assert response.label_missing_ground_truth is True +@pytest.mark.asyncio +async def test_update_evaluation_job_async_from_dict(): + await test_update_evaluation_job_async(request_type=dict) + + def test_update_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -7823,7 +8066,7 @@ def test_update_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: call.return_value = gcd_evaluation_job.EvaluationJob() @@ -7855,7 +8098,7 @@ async def test_update_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcd_evaluation_job.EvaluationJob() @@ -7881,7 +8124,7 @@ def test_update_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_evaluation_job.EvaluationJob() @@ -7926,7 +8169,7 @@ async def test_update_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_evaluation_job), "__call__" + type(client.transport.update_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcd_evaluation_job.EvaluationJob() @@ -7982,7 +8225,7 @@ def test_get_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob( @@ -8004,6 +8247,7 @@ def test_get_evaluation_job( assert args[0] == data_labeling_service.GetEvaluationJobRequest() # Establish that the response is the type that we expect. + assert isinstance(response, evaluation_job.EvaluationJob) assert response.name == "name_value" @@ -8026,18 +8270,21 @@ def test_get_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_get_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_get_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.GetEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.GetEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -8058,7 +8305,7 @@ async def test_get_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.GetEvaluationJobRequest() # Establish that the response is the type that we expect. assert isinstance(response, evaluation_job.EvaluationJob) @@ -8078,6 +8325,11 @@ async def test_get_evaluation_job_async(transport: str = "grpc_asyncio"): assert response.label_missing_ground_truth is True +@pytest.mark.asyncio +async def test_get_evaluation_job_async_from_dict(): + await test_get_evaluation_job_async(request_type=dict) + + def test_get_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8088,7 +8340,7 @@ def test_get_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: call.return_value = evaluation_job.EvaluationJob() @@ -8117,7 +8369,7 @@ async def test_get_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( evaluation_job.EvaluationJob() @@ -8140,7 +8392,7 @@ def test_get_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -8176,7 +8428,7 @@ async def test_get_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_evaluation_job), "__call__" + type(client.transport.get_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = evaluation_job.EvaluationJob() @@ -8224,7 +8476,7 @@ def test_pause_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8246,18 +8498,21 @@ def test_pause_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_pause_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_pause_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.PauseEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.PauseEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8268,12 +8523,17 @@ async def test_pause_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.PauseEvaluationJobRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_pause_evaluation_job_async_from_dict(): + await test_pause_evaluation_job_async(request_type=dict) + + def test_pause_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8284,7 +8544,7 @@ def test_pause_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: call.return_value = None @@ -8313,7 +8573,7 @@ async def test_pause_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8334,7 +8594,7 @@ def test_pause_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8370,7 +8630,7 @@ async def test_pause_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.pause_evaluation_job), "__call__" + type(client.transport.pause_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8416,7 +8676,7 @@ def test_resume_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8438,18 +8698,21 @@ def test_resume_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_resume_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_resume_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ResumeEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ResumeEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8460,12 +8723,17 @@ async def test_resume_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ResumeEvaluationJobRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_resume_evaluation_job_async_from_dict(): + await test_resume_evaluation_job_async(request_type=dict) + + def test_resume_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8476,7 +8744,7 @@ def test_resume_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: call.return_value = None @@ -8505,7 +8773,7 @@ async def test_resume_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8526,7 +8794,7 @@ def test_resume_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8562,7 +8830,7 @@ async def test_resume_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.resume_evaluation_job), "__call__" + type(client.transport.resume_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8608,7 +8876,7 @@ def test_delete_evaluation_job( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8630,18 +8898,21 @@ def test_delete_evaluation_job_from_dict(): @pytest.mark.asyncio -async def test_delete_evaluation_job_async(transport: str = "grpc_asyncio"): +async def test_delete_evaluation_job_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.DeleteEvaluationJobRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.DeleteEvaluationJobRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8652,12 +8923,17 @@ async def test_delete_evaluation_job_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.DeleteEvaluationJobRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_evaluation_job_async_from_dict(): + await test_delete_evaluation_job_async(request_type=dict) + + def test_delete_evaluation_job_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8668,7 +8944,7 @@ def test_delete_evaluation_job_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: call.return_value = None @@ -8697,7 +8973,7 @@ async def test_delete_evaluation_job_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -8718,7 +8994,7 @@ def test_delete_evaluation_job_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8754,7 +9030,7 @@ async def test_delete_evaluation_job_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_evaluation_job), "__call__" + type(client.transport.delete_evaluation_job), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -8800,7 +9076,7 @@ def test_list_evaluation_jobs( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListEvaluationJobsResponse( @@ -8816,6 +9092,7 @@ def test_list_evaluation_jobs( assert args[0] == data_labeling_service.ListEvaluationJobsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListEvaluationJobsPager) assert response.next_page_token == "next_page_token_value" @@ -8826,18 +9103,21 @@ def test_list_evaluation_jobs_from_dict(): @pytest.mark.asyncio -async def test_list_evaluation_jobs_async(transport: str = "grpc_asyncio"): +async def test_list_evaluation_jobs_async( + transport: str = "grpc_asyncio", + request_type=data_labeling_service.ListEvaluationJobsRequest, +): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = data_labeling_service.ListEvaluationJobsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -8852,7 +9132,7 @@ async def test_list_evaluation_jobs_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == data_labeling_service.ListEvaluationJobsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListEvaluationJobsAsyncPager) @@ -8860,6 +9140,11 @@ async def test_list_evaluation_jobs_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_evaluation_jobs_async_from_dict(): + await test_list_evaluation_jobs_async(request_type=dict) + + def test_list_evaluation_jobs_field_headers(): client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -8870,7 +9155,7 @@ def test_list_evaluation_jobs_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: call.return_value = data_labeling_service.ListEvaluationJobsResponse() @@ -8899,7 +9184,7 @@ async def test_list_evaluation_jobs_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( data_labeling_service.ListEvaluationJobsResponse() @@ -8922,7 +9207,7 @@ def test_list_evaluation_jobs_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListEvaluationJobsResponse() @@ -8964,7 +9249,7 @@ async def test_list_evaluation_jobs_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = data_labeling_service.ListEvaluationJobsResponse() @@ -9009,7 +9294,7 @@ def test_list_evaluation_jobs_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -9055,7 +9340,7 @@ def test_list_evaluation_jobs_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_evaluation_jobs), "__call__" + type(client.transport.list_evaluation_jobs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -9083,8 +9368,8 @@ def test_list_evaluation_jobs_pages(): RuntimeError, ) pages = list(client.list_evaluation_jobs(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -9095,7 +9380,7 @@ async def test_list_evaluation_jobs_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), + type(client.transport.list_evaluation_jobs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -9142,7 +9427,7 @@ async def test_list_evaluation_jobs_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_evaluation_jobs), + type(client.transport.list_evaluation_jobs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -9172,10 +9457,10 @@ async def test_list_evaluation_jobs_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_evaluation_jobs(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_evaluation_jobs(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token def test_credentials_transport_error(): @@ -9214,7 +9499,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = DataLabelingServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -9232,10 +9517,25 @@ def test_transport_get_channel(): assert channel +@pytest.mark.parametrize( + "transport_class", + [ + transports.DataLabelingServiceGrpcTransport, + transports.DataLabelingServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(auth, "default") as adc: + adc.return_value = (credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DataLabelingServiceClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.DataLabelingServiceGrpcTransport,) + assert isinstance(client.transport, transports.DataLabelingServiceGrpcTransport,) def test_data_labeling_service_base_transport_error(): @@ -9324,6 +9624,17 @@ def test_data_labeling_service_base_transport_with_credentials_file(): ) +def test_data_labeling_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(auth, "default") as adc, mock.patch( + "google.cloud.datalabeling_v1beta1.services.data_labeling_service.transports.DataLabelingServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (credentials.AnonymousCredentials(), None) + transport = transports.DataLabelingServiceTransport() + adc.assert_called_once() + + def test_data_labeling_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(auth, "default") as adc: @@ -9356,7 +9667,7 @@ def test_data_labeling_service_host_no_port(): api_endpoint="datalabeling.googleapis.com" ), ) - assert client._transport._host == "datalabeling.googleapis.com:443" + assert client.transport._host == "datalabeling.googleapis.com:443" def test_data_labeling_service_host_with_port(): @@ -9366,192 +9677,126 @@ def test_data_labeling_service_host_with_port(): api_endpoint="datalabeling.googleapis.com:8000" ), ) - assert client._transport._host == "datalabeling.googleapis.com:8000" + assert client.transport._host == "datalabeling.googleapis.com:8000" def test_data_labeling_service_grpc_transport_channel(): channel = grpc.insecure_channel("http://localhost/") - # Check that if channel is provided, mtls endpoint and client_cert_source - # won't be used. - callback = mock.MagicMock() + # Check that channel is used if provided. transport = transports.DataLabelingServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=callback, + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" - assert not callback.called + assert transport._ssl_channel_credentials == None def test_data_labeling_service_grpc_asyncio_transport_channel(): channel = aio.insecure_channel("http://localhost/") - # Check that if channel is provided, mtls endpoint and client_cert_source - # won't be used. - callback = mock.MagicMock() + # Check that channel is used if provided. transport = transports.DataLabelingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=callback, + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" - assert not callback.called - - -@mock.patch("grpc.ssl_channel_credentials", autospec=True) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_data_labeling_service_grpc_transport_channel_mtls_with_client_cert_source( - grpc_create_channel, grpc_ssl_channel_cred -): - # Check that if channel is None, but api_mtls_endpoint and client_cert_source - # are provided, then a mTLS channel will be created. - mock_cred = mock.Mock() - - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - transport = transports.DataLabelingServiceGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel - - -@mock.patch("grpc.ssl_channel_credentials", autospec=True) -@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) -def test_data_labeling_service_grpc_asyncio_transport_channel_mtls_with_client_cert_source( - grpc_create_channel, grpc_ssl_channel_cred -): - # Check that if channel is None, but api_mtls_endpoint and client_cert_source - # are provided, then a mTLS channel will be created. - mock_cred = mock.Mock() - - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - transport = transports.DataLabelingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( - "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] + "transport_class", + [ + transports.DataLabelingServiceGrpcTransport, + transports.DataLabelingServiceGrpcAsyncIOTransport, + ], ) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_data_labeling_service_grpc_transport_channel_mtls_with_adc( - grpc_create_channel, api_mtls_endpoint +def test_data_labeling_service_transport_channel_mtls_with_client_cert_source( + transport_class, ): - # Check that if channel and client_cert_source are None, but api_mtls_endpoint - # is provided, then a mTLS channel will be created with SSL ADC. - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - # Mock google.auth.transport.grpc.SslCredentials class. - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - mock_cred = mock.Mock() - transport = transports.DataLabelingServiceGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint=api_mtls_endpoint, - client_cert_source=None, - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel", autospec=True + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( - "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] + "transport_class", + [ + transports.DataLabelingServiceGrpcTransport, + transports.DataLabelingServiceGrpcAsyncIOTransport, + ], ) -@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) -def test_data_labeling_service_grpc_asyncio_transport_channel_mtls_with_adc( - grpc_create_channel, api_mtls_endpoint -): - # Check that if channel and client_cert_source are None, but api_mtls_endpoint - # is provided, then a mTLS channel will be created with SSL ADC. - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - # Mock google.auth.transport.grpc.SslCredentials class. +def test_data_labeling_service_transport_channel_mtls_with_adc(transport_class): mock_ssl_cred = mock.Mock() with mock.patch.multiple( "google.auth.transport.grpc.SslCredentials", __init__=mock.Mock(return_value=None), ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): - mock_cred = mock.Mock() - transport = transports.DataLabelingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint=api_mtls_endpoint, - client_cert_source=None, - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + with mock.patch.object( + transport_class, "create_channel", autospec=True + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + ) + assert transport.grpc_channel == mock_grpc_channel def test_data_labeling_service_grpc_lro_client(): client = DataLabelingServiceClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -9564,7 +9809,7 @@ def test_data_labeling_service_grpc_lro_async_client(): client = DataLabelingServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -9573,32 +9818,36 @@ def test_data_labeling_service_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_instruction_path(): +def test_annotated_dataset_path(): project = "squid" - instruction = "clam" + dataset = "clam" + annotated_dataset = "whelk" - expected = "projects/{project}/instructions/{instruction}".format( - project=project, instruction=instruction, + expected = "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( + project=project, dataset=dataset, annotated_dataset=annotated_dataset, + ) + actual = DataLabelingServiceClient.annotated_dataset_path( + project, dataset, annotated_dataset ) - actual = DataLabelingServiceClient.instruction_path(project, instruction) assert expected == actual -def test_parse_instruction_path(): +def test_parse_annotated_dataset_path(): expected = { - "project": "whelk", - "instruction": "octopus", + "project": "octopus", + "dataset": "oyster", + "annotated_dataset": "nudibranch", } - path = DataLabelingServiceClient.instruction_path(**expected) + path = DataLabelingServiceClient.annotated_dataset_path(**expected) # Check that the path construction is reversible. - actual = DataLabelingServiceClient.parse_instruction_path(path) + actual = DataLabelingServiceClient.parse_annotated_dataset_path(path) assert expected == actual def test_annotation_spec_set_path(): - project = "squid" - annotation_spec_set = "clam" + project = "cuttlefish" + annotation_spec_set = "mussel" expected = "projects/{project}/annotationSpecSets/{annotation_spec_set}".format( project=project, annotation_spec_set=annotation_spec_set, @@ -9611,8 +9860,8 @@ def test_annotation_spec_set_path(): def test_parse_annotation_spec_set_path(): expected = { - "project": "whelk", - "annotation_spec_set": "octopus", + "project": "winkle", + "annotation_spec_set": "nautilus", } path = DataLabelingServiceClient.annotation_spec_set_path(**expected) @@ -9621,9 +9870,82 @@ def test_parse_annotation_spec_set_path(): assert expected == actual +def test_data_item_path(): + project = "scallop" + dataset = "abalone" + data_item = "squid" + + expected = "projects/{project}/datasets/{dataset}/dataItems/{data_item}".format( + project=project, dataset=dataset, data_item=data_item, + ) + actual = DataLabelingServiceClient.data_item_path(project, dataset, data_item) + assert expected == actual + + +def test_parse_data_item_path(): + expected = { + "project": "clam", + "dataset": "whelk", + "data_item": "octopus", + } + path = DataLabelingServiceClient.data_item_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_data_item_path(path) + assert expected == actual + + +def test_dataset_path(): + project = "oyster" + dataset = "nudibranch" + + expected = "projects/{project}/datasets/{dataset}".format( + project=project, dataset=dataset, + ) + actual = DataLabelingServiceClient.dataset_path(project, dataset) + assert expected == actual + + +def test_parse_dataset_path(): + expected = { + "project": "cuttlefish", + "dataset": "mussel", + } + path = DataLabelingServiceClient.dataset_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_dataset_path(path) + assert expected == actual + + +def test_evaluation_path(): + project = "winkle" + dataset = "nautilus" + evaluation = "scallop" + + expected = "projects/{project}/datasets/{dataset}/evaluations/{evaluation}".format( + project=project, dataset=dataset, evaluation=evaluation, + ) + actual = DataLabelingServiceClient.evaluation_path(project, dataset, evaluation) + assert expected == actual + + +def test_parse_evaluation_path(): + expected = { + "project": "abalone", + "dataset": "squid", + "evaluation": "clam", + } + path = DataLabelingServiceClient.evaluation_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_evaluation_path(path) + assert expected == actual + + def test_evaluation_job_path(): - project = "squid" - evaluation_job = "clam" + project = "whelk" + evaluation_job = "octopus" expected = "projects/{project}/evaluationJobs/{evaluation_job}".format( project=project, evaluation_job=evaluation_job, @@ -9634,8 +9956,8 @@ def test_evaluation_job_path(): def test_parse_evaluation_job_path(): expected = { - "project": "whelk", - "evaluation_job": "octopus", + "project": "oyster", + "evaluation_job": "nudibranch", } path = DataLabelingServiceClient.evaluation_job_path(**expected) @@ -9644,24 +9966,178 @@ def test_parse_evaluation_job_path(): assert expected == actual -def test_dataset_path(): +def test_example_path(): + project = "cuttlefish" + dataset = "mussel" + annotated_dataset = "winkle" + example = "nautilus" + + expected = "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}/examples/{example}".format( + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, + example=example, + ) + actual = DataLabelingServiceClient.example_path( + project, dataset, annotated_dataset, example + ) + assert expected == actual + + +def test_parse_example_path(): + expected = { + "project": "scallop", + "dataset": "abalone", + "annotated_dataset": "squid", + "example": "clam", + } + path = DataLabelingServiceClient.example_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_example_path(path) + assert expected == actual + + +def test_instruction_path(): + project = "whelk" + instruction = "octopus" + + expected = "projects/{project}/instructions/{instruction}".format( + project=project, instruction=instruction, + ) + actual = DataLabelingServiceClient.instruction_path(project, instruction) + assert expected == actual + + +def test_parse_instruction_path(): + expected = { + "project": "oyster", + "instruction": "nudibranch", + } + path = DataLabelingServiceClient.instruction_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_instruction_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "cuttlefish" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = DataLabelingServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = DataLabelingServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "winkle" + + expected = "folders/{folder}".format(folder=folder,) + actual = DataLabelingServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = DataLabelingServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "scallop" + + expected = "organizations/{organization}".format(organization=organization,) + actual = DataLabelingServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = DataLabelingServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): project = "squid" - dataset = "clam" - expected = "projects/{project}/datasets/{dataset}".format( - project=project, dataset=dataset, + expected = "projects/{project}".format(project=project,) + actual = DataLabelingServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = DataLabelingServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = DataLabelingServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "whelk" + location = "octopus" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, ) - actual = DataLabelingServiceClient.dataset_path(project, dataset) + actual = DataLabelingServiceClient.common_location_path(project, location) assert expected == actual -def test_parse_dataset_path(): +def test_parse_common_location_path(): expected = { - "project": "whelk", - "dataset": "octopus", + "project": "oyster", + "location": "nudibranch", } - path = DataLabelingServiceClient.dataset_path(**expected) + path = DataLabelingServiceClient.common_location_path(**expected) # Check that the path construction is reversible. - actual = DataLabelingServiceClient.parse_dataset_path(path) + actual = DataLabelingServiceClient.parse_common_location_path(path) assert expected == actual + + +def test_client_withDEFAULT_CLIENT_INFO(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.DataLabelingServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = DataLabelingServiceClient( + credentials=credentials.AnonymousCredentials(), client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.DataLabelingServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = DataLabelingServiceClient.get_transport_class() + transport = transport_class( + credentials=credentials.AnonymousCredentials(), client_info=client_info, + ) + prep.assert_called_once_with(client_info)