diff --git a/.generator/cli.py b/.generator/cli.py index a9491a400e25..70a8ba63d9de 100644 --- a/.generator/cli.py +++ b/.generator/cli.py @@ -23,6 +23,7 @@ import subprocess import sys import tempfile +import time import yaml from datetime import date, datetime from functools import lru_cache @@ -31,6 +32,40 @@ import build.util import parse_googleapis_content +logging.basicConfig(stream=sys.stdout, level=logging.INFO) + +import functools + +PERF_LOGGING_ENABLED = os.environ.get("ENABLE_PERF_LOGS") == "1" + +if PERF_LOGGING_ENABLED: + perf_logger = logging.getLogger("performance_metrics") + perf_logger.setLevel(logging.INFO) + perf_handler = logging.FileHandler("/tmp/performance_metrics.log", mode='w') + perf_formatter = logging.Formatter('%(asctime)s | %(message)s', datefmt='%H:%M:%S') + perf_handler.setFormatter(perf_formatter) + perf_logger.addHandler(perf_handler) + perf_logger.propagate = False + +def track_time(func): + """ + Decorator. Usage: @track_time + If logging is OFF, it returns the original function (Zero Overhead). + If logging is ON, it wraps the function to measure execution time. + """ + if not PERF_LOGGING_ENABLED: + return func + + @functools.wraps(func) + def wrapper(*args, **kwargs): + start_time = time.perf_counter() + try: + return func(*args, **kwargs) + finally: + duration = time.perf_counter() - start_time + perf_logger.info(f"{func.__name__:<30} | {duration:.4f} seconds") + + return wrapper try: import synthtool @@ -323,8 +358,9 @@ def _get_library_id(request_data: Dict) -> str: return library_id +@track_time def _run_post_processor(output: str, library_id: str, is_mono_repo: bool): - """Runs the synthtool post-processor on the output directory. + """Runs the synthtool post-processor (templates) and Ruff formatter (lint/format). Args: output(str): Path to the directory in the container where code @@ -334,25 +370,57 @@ def _run_post_processor(output: str, library_id: str, is_mono_repo: bool): """ os.chdir(output) path_to_library = f"packages/{library_id}" if is_mono_repo else "." - logger.info("Running Python post-processor...") + + # 1. Run Synthtool (Templates & Fixers only) + # Note: This relies on 'nox' being disabled in your environment (via run_fast.sh shim) + # to avoid the slow formatting step inside owlbot. + logger.info("Running Python post-processor (Templates & Fixers)...") if SYNTHTOOL_INSTALLED: - if is_mono_repo: - python_mono_repo.owlbot_main(path_to_library) - else: - # Some repositories have customizations in `librarian.py`. - # If this file exists, run those customizations instead of `owlbot_main` - if Path(f"{output}/librarian.py").exists(): - subprocess.run(["python3.14", f"{output}/librarian.py"]) + try: + if is_mono_repo: + python_mono_repo.owlbot_main(path_to_library) else: - python.owlbot_main() - else: - raise SYNTHTOOL_IMPORT_ERROR # pragma: NO COVER + # Handle custom librarian scripts if present + if Path(f"{output}/librarian.py").exists(): + subprocess.run(["python3.14", f"{output}/librarian.py"]) + else: + python.owlbot_main() + except Exception as e: + logger.warning(f"Synthtool warning (non-fatal): {e}") + + # 2. Run RUFF (Fast Formatter & Import Sorter) + # This replaces both 'isort' and 'black' and runs in < 1 second. + # We hardcode flags here to match Black defaults so you don't need config files. + # logger.info("🚀 Running Ruff (Fast Formatter)...") + ruff_config_path = Path("/usr/local/google/home/omairn/git/googleapis/google-cloud-python/.generator/ruff.toml").resolve() + + if not ruff_config_path.exists(): + logger.warning(f"⚠️ Could not find Ruff config at {ruff_config_path}. Using defaults.") + + try: - # If there is no noxfile, run `isort`` and `black` on the output. - # This is required for proto-only libraries which are not GAPIC. - if not Path(f"{output}/{path_to_library}/noxfile.py").exists(): - subprocess.run(["isort", output]) - subprocess.run(["black", output]) + subprocess.run(["ruff", "--version"], check=False) + logger.info("Running Ruff Check (Imports)...") + base_args = ["ruff", "--config", str(ruff_config_path)] + + # STEP A: Fix Imports (like isort) + subprocess.run( + base_args + ["check", "--fix", "."], + check=True, + ) + + # STEP B: Format Code (like black) + subprocess.run( + base_args + ["format", "."], + check=True, + ) + logger.info("Ruff formatting completed successfully.") + + except FileNotFoundError: + logger.warning("⚠️ Ruff binary not found. Code will be unformatted.") + logger.warning(" Please run: pip install ruff") + except subprocess.CalledProcessError as e: + logger.error(f"❌ Ruff failed with exit code {e.returncode}.") logger.info("Python post-processor ran successfully.") @@ -392,6 +460,7 @@ def _add_header_to_files(directory: str) -> None: f.writelines(lines) +@track_time def _copy_files_needed_for_post_processing( output: str, input: str, library_id: str, is_mono_repo: bool ): @@ -444,6 +513,7 @@ def _copy_files_needed_for_post_processing( ) +@track_time def _clean_up_files_after_post_processing( output: str, library_id: str, is_mono_repo: bool ): @@ -590,6 +660,7 @@ def _get_repo_name_from_repo_metadata(base: str, library_id: str, is_mono_repo: return repo_name +@track_time def _generate_repo_metadata_file( output: str, library_id: str, source: str, apis: List[Dict], is_mono_repo: bool ): @@ -631,6 +702,7 @@ def _generate_repo_metadata_file( _write_json_file(output_repo_metadata, metadata_content) +@track_time def _copy_readme_to_docs(output: str, library_id: str, is_mono_repo: bool): """Copies the README.rst file for a generated library to docs/README.rst. @@ -672,6 +744,7 @@ def _copy_readme_to_docs(output: str, library_id: str, is_mono_repo: bool): f.write(content) +@track_time def handle_generate( librarian: str = LIBRARIAN_DIR, source: str = SOURCE_DIR, @@ -933,6 +1006,7 @@ def _stage_gapic_library(tmp_dir: str, staging_dir: str) -> None: shutil.copytree(tmp_dir, staging_dir, dirs_exist_ok=True) +@track_time def _generate_api( api_path: str, library_id: str, @@ -1748,6 +1822,7 @@ def handle_release_stage( output=args.output, input=args.input, ) + elif args.command == "build": args.func(librarian=args.librarian, repo=args.repo) elif args.command == "release-stage": diff --git a/.generator/requirements.in b/.generator/requirements.in index 87adc6d50599..a50710f429cc 100644 --- a/.generator/requirements.in +++ b/.generator/requirements.in @@ -3,5 +3,4 @@ gapic-generator==1.30.3 # Fix mypy checks https://github.com/googleapis/gapic-ge nox starlark-pyo3>=2025.1 build -black==23.7.0 -isort==5.11.0 +ruff \ No newline at end of file diff --git a/.generator/ruff.toml b/.generator/ruff.toml new file mode 100644 index 000000000000..3983fe43ac2e --- /dev/null +++ b/.generator/ruff.toml @@ -0,0 +1,22 @@ +# .generator/ruff.toml +line-length = 88 +# Enable preview to get the strictest Black compatibility +preview = true + +[lint] +select = ["I"] + +[lint.isort] +# 1. Force 'google' to be first-party (keeps google.* imports together) +# known-first-party = ["google"] + +# 2. Combine imports from the same module (Standard isort behavior) +# Prevents splitting "from x import a, b" into multiple lines. +# combine-as-imports = true + +# 3. Sort imports by module name, ignoring "from" vs "import" (Standard isort behavior) +# This minimizes diffs where isort mixed them but Ruff separated them. +force-sort-within-sections = true + +[format] +quote-style = "double" \ No newline at end of file diff --git a/.librarian/generate-request.json b/.librarian/generate-request.json new file mode 100644 index 000000000000..31b573bd01da --- /dev/null +++ b/.librarian/generate-request.json @@ -0,0 +1,40 @@ +{ + "id": "google-cloud-vision", + "version": "3.12.0", + "apis": [ + { + "path": "google/cloud/vision/v1p3beta1", + "service_config": "vision_v1p3beta1.yaml" + }, + { + "path": "google/cloud/vision/v1", + "service_config": "vision_v1.yaml" + }, + { + "path": "google/cloud/vision/v1p1beta1", + "service_config": "vision_v1p1beta1.yaml" + }, + { + "path": "google/cloud/vision/v1p2beta1", + "service_config": "vision_v1p2beta1.yaml" + }, + { + "path": "google/cloud/vision/v1p4beta1", + "service_config": "vision_v1p4beta1.yaml" + } + ], + "source_roots": [ + "packages/google-cloud-vision" + ], + "preserve_regex": [ + "packages/google-cloud-vision/CHANGELOG.md", + "docs/CHANGELOG.md", + "samples/README.txt", + "samples/snippets/README.rst", + "tests/system" + ], + "remove_regex": [ + "packages/google-cloud-vision/" + ], + "tag_format": "{id}-v{version}" +} \ No newline at end of file diff --git a/packages/google-cloud-vision/google/cloud/vision/__init__.py b/packages/google-cloud-vision/google/cloud/vision/__init__.py index 271a36da1815..27def75b91c6 100644 --- a/packages/google-cloud-vision/google/cloud/vision/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision/__init__.py @@ -18,10 +18,10 @@ __version__ = package_version.__version__ +from google.cloud.vision_v1 import ImageAnnotatorClient from google.cloud.vision_v1.services.image_annotator.async_client import ( ImageAnnotatorAsyncClient, ) -from google.cloud.vision_v1 import ImageAnnotatorClient from google.cloud.vision_v1.services.product_search.async_client import ( ProductSearchAsyncClient, ) diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1/__init__.py index 99375917c1b9..3084970c5286 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/__init__.py @@ -16,7 +16,6 @@ import sys import google.api_core as api_core - from google.cloud.vision_v1 import gapic_version as package_version __version__ = package_version.__version__ @@ -28,11 +27,8 @@ # this code path once we drop support for Python 3.7 import importlib_metadata as metadata -from google.cloud.vision_helpers import VisionHelpers -from google.cloud.vision_helpers.decorators import add_single_feature_methods -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.image_annotator import ImageAnnotatorClient as IacImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient, ImageAnnotatorClient from .services.product_search import ProductSearchAsyncClient, ProductSearchClient from .types.geometry import BoundingPoly, NormalizedVertex, Position, Vertex from .types.image_annotator import ( @@ -208,13 +204,6 @@ def _get_version(dependency_name): + "https://devguide.python.org/versions/" ) - -@add_single_feature_methods -class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): - __doc__ = IacImageAnnotatorClient.__doc__ - Feature = Feature - - __all__ = ( "ImageAnnotatorAsyncClient", "ProductSearchAsyncClient", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/async_client.py index 6efcecc5173a..e1ccc9c08f1d 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/async_client.py @@ -34,21 +34,21 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.longrunning import operations_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore from .client import ImageAnnotatorClient from .transports.base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport @@ -122,7 +122,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, info, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_info.__func__( + ImageAnnotatorAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -138,7 +140,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_file.__func__( + ImageAnnotatorAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/client.py index 76fbff8ab683..41cba6fd7478 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/client.py @@ -42,11 +42,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -61,11 +60,12 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.longrunning import operations_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore from .transports.base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport from .transports.grpc import ImageAnnotatorGrpcTransport @@ -81,9 +81,7 @@ class ImageAnnotatorClientMeta(type): objects. """ - _transport_registry = ( - OrderedDict() - ) # type: Dict[str, Type[ImageAnnotatorTransport]] + _transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] _transport_registry["grpc"] = ImageAnnotatorGrpcTransport _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport _transport_registry["rest"] = ImageAnnotatorRestTransport @@ -651,11 +649,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ImageAnnotatorClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ImageAnnotatorClient._read_environment_variables() + ) self._client_cert_source = ImageAnnotatorClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -690,8 +686,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ImageAnnotatorTransport, transport) self._api_endpoint = self._transport.host diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/base.py index 6444874ad13b..c899fee5886f 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/base.py @@ -22,13 +22,12 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1 import gapic_version as package_version +from google.cloud.vision_v1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1 import gapic_version as package_version -from google.cloud.vision_v1.types import image_annotator - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ ) @@ -86,8 +85,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -102,11 +99,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py index a4f87b772d49..f0ba9e980442 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py @@ -23,14 +23,13 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport try: @@ -441,12 +440,12 @@ def async_batch_annotate_images( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_images" not in self._stubs: - self._stubs[ - "async_batch_annotate_images" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages", - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_images"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages", + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_images"] @@ -477,12 +476,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py index 1c8c7a631000..37c1428091fe 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message @@ -32,8 +33,6 @@ from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport from .grpc import ImageAnnotatorGrpcTransport @@ -450,12 +449,12 @@ def async_batch_annotate_images( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_images" not in self._stubs: - self._stubs[ - "async_batch_annotate_images" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages", - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_images"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages", + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_images"] @@ -487,12 +486,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest.py index 7c06785750c8..a1ae05ec3d49 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest.py @@ -19,18 +19,17 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore import google.protobuf from google.protobuf import json_format from requests import __version__ as requests_version -from google.cloud.vision_v1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseImageAnnotatorRestTransport @@ -493,6 +492,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -538,9 +538,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() request, metadata = self._interceptor.pre_async_batch_annotate_files( request, metadata @@ -652,6 +650,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -696,9 +695,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateImages._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateImages._get_http_options() request, metadata = self._interceptor.pre_async_batch_annotate_images( request, metadata @@ -809,6 +806,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -849,9 +847,7 @@ def __call__( A list of file annotation responses. """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseBatchAnnotateFiles._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseBatchAnnotateFiles._get_http_options() request, metadata = self._interceptor.pre_batch_annotate_files( request, metadata @@ -965,6 +961,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1007,9 +1004,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() request, metadata = self._interceptor.pre_batch_annotate_images( request, metadata @@ -1114,7 +1109,9 @@ def async_batch_annotate_files( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AsyncBatchAnnotateFiles(self._session, self._host, self._interceptor) # type: ignore + return self._AsyncBatchAnnotateFiles( + self._session, self._host, self._interceptor + ) # type: ignore @property def async_batch_annotate_images( @@ -1124,7 +1121,9 @@ def async_batch_annotate_images( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AsyncBatchAnnotateImages(self._session, self._host, self._interceptor) # type: ignore + return self._AsyncBatchAnnotateImages( + self._session, self._host, self._interceptor + ) # type: ignore @property def batch_annotate_files( @@ -1168,6 +1167,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest_base.py index 8bbd11f6eb0e..41b6dd3542ea 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/rest_base.py @@ -18,11 +18,10 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template +from google.cloud.vision_v1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf import json_format -from google.cloud.vision_v1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/async_client.py index bf2a1db0a73a..bc64b6c301bb 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/async_client.py @@ -34,26 +34,28 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1.services.product_search import pagers from google.cloud.vision_v1.types import geometry, product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import ( + empty_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore from .client import ProductSearchClient from .transports.base import DEFAULT_CLIENT_INFO, ProductSearchTransport @@ -73,20 +75,21 @@ class ProductSearchAsyncClient: """Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1.Product] has a collection of - [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, - named ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` """ _client: ProductSearchClient @@ -144,7 +147,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ProductSearchAsyncClient: The constructed client. """ - return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, info, *args, **kwargs) # type: ignore + return ProductSearchClient.from_service_account_info.__func__( + ProductSearchAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -160,7 +165,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ProductSearchAsyncClient: The constructed client. """ - return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore + return ProductSearchClient.from_service_account_file.__func__( + ProductSearchAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file @@ -335,8 +342,8 @@ async def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. .. code-block:: python @@ -476,8 +483,8 @@ async def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. .. code-block:: python @@ -609,7 +616,7 @@ async def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -732,10 +739,10 @@ async def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. .. code-block:: python @@ -832,9 +839,9 @@ async def sample_update_product_set(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product_set.name", request.product_set.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), ) # Validate the universe domain. @@ -974,12 +981,12 @@ async def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. .. code-block:: python @@ -1114,8 +1121,8 @@ async def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python @@ -1245,7 +1252,7 @@ async def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. .. code-block:: python @@ -1366,14 +1373,14 @@ async def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. .. code-block:: python @@ -1467,9 +1474,9 @@ async def sample_update_product(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product.name", request.product.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), ) # Validate the universe domain. @@ -1620,14 +1627,14 @@ async def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. .. code-block:: python @@ -1882,9 +1889,9 @@ async def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. .. code-block:: python @@ -2017,7 +2024,7 @@ async def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. .. code-block:: python @@ -2140,8 +2147,8 @@ async def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. .. code-block:: python @@ -2386,8 +2393,8 @@ async def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/client.py index 9419a8f2769c..a9abb43c5bf1 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/client.py @@ -42,11 +42,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -61,16 +60,19 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1.services.product_search import pagers from google.cloud.vision_v1.types import geometry, product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import ( + empty_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore from .transports.base import DEFAULT_CLIENT_INFO, ProductSearchTransport from .transports.grpc import ProductSearchGrpcTransport @@ -117,20 +119,21 @@ class ProductSearchClient(metaclass=ProductSearchClientMeta): """Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1.Product] has a collection of - [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, - named ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` """ @staticmethod @@ -691,11 +694,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ProductSearchClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ProductSearchClient._read_environment_variables() + ) self._client_cert_source = ProductSearchClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -730,8 +731,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ProductSearchTransport, transport) self._api_endpoint = self._transport.host @@ -816,8 +816,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. .. code-block:: python @@ -954,8 +954,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. .. code-block:: python @@ -1084,7 +1084,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -1204,10 +1204,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. .. code-block:: python @@ -1301,9 +1301,9 @@ def sample_update_product_set(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product_set.name", request.product_set.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), ) # Validate the universe domain. @@ -1440,12 +1440,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. .. code-block:: python @@ -1577,8 +1577,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python @@ -1705,7 +1705,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. .. code-block:: python @@ -1823,14 +1823,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. .. code-block:: python @@ -1921,9 +1921,9 @@ def sample_update_product(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product.name", request.product.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), ) # Validate the universe domain. @@ -2071,14 +2071,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. .. code-block:: python @@ -2327,9 +2327,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. .. code-block:: python @@ -2459,7 +2459,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. .. code-block:: python @@ -2579,8 +2579,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. .. code-block:: python @@ -2823,8 +2823,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/pagers.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/pagers.py index 685cb392cf54..77727b5abef2 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/pagers.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -145,7 +145,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -227,7 +227,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -303,7 +303,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -383,7 +383,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -461,7 +461,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -543,7 +543,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -623,7 +623,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/base.py index 68aa99040a97..8743066cff04 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/base.py @@ -22,14 +22,13 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1 import gapic_version as package_version +from google.cloud.vision_v1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore import google.protobuf from google.protobuf import empty_pb2 # type: ignore -from google.cloud.vision_v1 import gapic_version as package_version -from google.cloud.vision_v1.types import product_search_service - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ ) @@ -87,8 +86,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -103,11 +100,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py index e75e8b70e142..ef3db3247967 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py @@ -23,6 +23,7 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson @@ -30,8 +31,6 @@ import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport try: @@ -115,20 +114,21 @@ class ProductSearchGrpcTransport(ProductSearchTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1.Product] has a collection of - [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, - named ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -369,8 +369,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. Returns: Callable[[~.CreateProductSetRequest], @@ -403,8 +403,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. Returns: Callable[[~.ListProductSetsRequest], @@ -436,7 +436,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.GetProductSetRequest], @@ -470,10 +470,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. Returns: Callable[[~.UpdateProductSetRequest], @@ -535,12 +535,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. Returns: Callable[[~.CreateProductRequest], @@ -573,8 +573,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsRequest], @@ -606,7 +606,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. Returns: Callable[[~.GetProductRequest], @@ -642,14 +642,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. Returns: Callable[[~.UpdateProductRequest], @@ -723,14 +723,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. Returns: Callable[[~.CreateReferenceImageRequest], @@ -798,9 +798,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. Returns: Callable[[~.ListReferenceImagesRequest], @@ -833,7 +833,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. Returns: Callable[[~.GetReferenceImageRequest], @@ -868,8 +868,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. Returns: Callable[[~.AddProductToProductSetRequest], @@ -882,12 +882,12 @@ def add_product_to_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_product_to_product_set" not in self._stubs: - self._stubs[ - "add_product_to_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ProductSearch/AddProductToProductSet", - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["add_product_to_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ProductSearch/AddProductToProductSet", + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["add_product_to_product_set"] @@ -913,12 +913,12 @@ def remove_product_from_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_product_from_product_set" not in self._stubs: - self._stubs[ - "remove_product_from_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet", - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["remove_product_from_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet", + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["remove_product_from_product_set"] @@ -937,8 +937,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsInProductSetRequest], @@ -951,12 +951,12 @@ def list_products_in_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_products_in_product_set" not in self._stubs: - self._stubs[ - "list_products_in_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet", - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + self._stubs["list_products_in_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet", + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) ) return self._stubs["list_products_in_product_set"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py index 2d25de74b853..201a6cdaf954 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson @@ -33,8 +34,6 @@ from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport from .grpc import ProductSearchGrpcTransport @@ -121,20 +120,21 @@ class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1.Product] has a collection of - [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, - named ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -377,8 +377,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. Returns: Callable[[~.CreateProductSetRequest], @@ -411,8 +411,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. Returns: Callable[[~.ListProductSetsRequest], @@ -445,7 +445,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.GetProductSetRequest], @@ -479,10 +479,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. Returns: Callable[[~.UpdateProductSetRequest], @@ -547,12 +547,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. Returns: Callable[[~.CreateProductRequest], @@ -585,8 +585,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsRequest], @@ -619,7 +619,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. Returns: Callable[[~.GetProductRequest], @@ -656,14 +656,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. Returns: Callable[[~.UpdateProductRequest], @@ -739,14 +739,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. Returns: Callable[[~.CreateReferenceImageRequest], @@ -814,9 +814,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. Returns: Callable[[~.ListReferenceImagesRequest], @@ -849,7 +849,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. Returns: Callable[[~.GetReferenceImageRequest], @@ -885,8 +885,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. Returns: Callable[[~.AddProductToProductSetRequest], @@ -899,12 +899,12 @@ def add_product_to_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_product_to_product_set" not in self._stubs: - self._stubs[ - "add_product_to_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ProductSearch/AddProductToProductSet", - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["add_product_to_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ProductSearch/AddProductToProductSet", + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["add_product_to_product_set"] @@ -931,12 +931,12 @@ def remove_product_from_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_product_from_product_set" not in self._stubs: - self._stubs[ - "remove_product_from_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet", - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["remove_product_from_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet", + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["remove_product_from_product_set"] @@ -955,8 +955,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsInProductSetRequest], @@ -969,12 +969,12 @@ def list_products_in_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_products_in_product_set" not in self._stubs: - self._stubs[ - "list_products_in_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet", - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + self._stubs["list_products_in_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet", + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) ) return self._stubs["list_products_in_product_set"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest.py index 65c13eb81d75..33a87601566d 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest.py @@ -19,19 +19,20 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore import google.protobuf -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from requests import __version__ as requests_version -from google.cloud.vision_v1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseProductSearchRestTransport @@ -1034,20 +1035,21 @@ class ProductSearchRestTransport(_BaseProductSearchRestTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1.Product] has a collection of - [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, - named ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -1188,6 +1190,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1225,9 +1228,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseAddProductToProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseAddProductToProductSet._get_http_options() request, metadata = self._interceptor.pre_add_product_to_product_set( request, metadata @@ -1304,6 +1305,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1454,6 +1456,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1498,9 +1501,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseCreateProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseCreateProductSet._get_http_options() request, metadata = self._interceptor.pre_create_product_set( request, metadata @@ -1613,6 +1614,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1654,9 +1656,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseCreateReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseCreateReferenceImage._get_http_options() request, metadata = self._interceptor.pre_create_reference_image( request, metadata @@ -1769,6 +1769,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1875,6 +1876,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1909,9 +1911,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseDeleteProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseDeleteProductSet._get_http_options() request, metadata = self._interceptor.pre_delete_product_set( request, metadata @@ -1983,6 +1983,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2017,9 +2018,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseDeleteReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseDeleteReferenceImage._get_http_options() request, metadata = self._interceptor.pre_delete_reference_image( request, metadata @@ -2091,6 +2090,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2239,6 +2239,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2390,6 +2391,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2430,9 +2432,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseGetReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseGetReferenceImage._get_http_options() request, metadata = self._interceptor.pre_get_reference_image( request, metadata @@ -2540,6 +2540,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2582,9 +2583,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseImportProductSets._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseImportProductSets._get_http_options() request, metadata = self._interceptor.pre_import_product_sets( request, metadata @@ -2693,6 +2692,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2839,6 +2839,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2988,6 +2989,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3030,9 +3032,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseListProductsInProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseListProductsInProductSet._get_http_options() request, metadata = self._interceptor.pre_list_products_in_product_set( request, metadata @@ -3144,6 +3144,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3182,9 +3183,7 @@ def __call__( Response message for the ``ListReferenceImages`` method. """ - http_options = ( - _BaseProductSearchRestTransport._BaseListReferenceImages._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseListReferenceImages._get_http_options() request, metadata = self._interceptor.pre_list_reference_images( request, metadata @@ -3294,6 +3293,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3446,6 +3446,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3483,9 +3484,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseRemoveProductFromProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseRemoveProductFromProductSet._get_http_options() request, metadata = self._interceptor.pre_remove_product_from_product_set( request, metadata @@ -3564,6 +3563,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3714,6 +3714,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3758,9 +3759,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseUpdateProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseUpdateProductSet._get_http_options() request, metadata = self._interceptor.pre_update_product_set( request, metadata @@ -3865,7 +3864,9 @@ def add_product_to_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AddProductToProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._AddProductToProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def create_product( @@ -3997,7 +3998,9 @@ def list_products_in_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._ListProductsInProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._ListProductsInProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def list_reference_images( @@ -4028,7 +4031,9 @@ def remove_product_from_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._RemoveProductFromProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._RemoveProductFromProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def update_product( @@ -4071,6 +4076,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest_base.py index e704231eadf4..4cb9977b5a74 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/rest_base.py @@ -18,11 +18,12 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format - from google.cloud.vision_v1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/types/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1/types/__init__.py index 6d3af4c629f5..bd9c22403b9f 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/types/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/types/__init__.py @@ -13,7 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .geometry import BoundingPoly, NormalizedVertex, Position, Vertex +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Position, + Vertex, +) from .image_annotator import ( AnnotateFileRequest, AnnotateFileResponse, @@ -56,7 +61,10 @@ TextDetectionParams, WebDetectionParams, ) -from .product_search import ProductSearchParams, ProductSearchResults +from .product_search import ( + ProductSearchParams, + ProductSearchResults, +) from .product_search_service import ( AddProductToProductSetRequest, BatchOperationMetadata, @@ -90,8 +98,17 @@ UpdateProductRequest, UpdateProductSetRequest, ) -from .text_annotation import Block, Page, Paragraph, Symbol, TextAnnotation, Word -from .web_detection import WebDetection +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) __all__ = ( "BoundingPoly", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/types/image_annotator.py b/packages/google-cloud-vision/google/cloud/vision_v1/types/image_annotator.py index 524c4df5c0c9..51878b7d7785 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/types/image_annotator.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/types/image_annotator.py @@ -17,15 +17,16 @@ from typing import MutableMapping, MutableSequence +from google.cloud.vision_v1.types import geometry, product_search, text_annotation +from google.cloud.vision_v1.types import web_detection as gcv_web_detection from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import latlng_pb2 # type: ignore +from google.type import ( + color_pb2, # type: ignore + latlng_pb2, # type: ignore +) import proto # type: ignore -from google.cloud.vision_v1.types import geometry, product_search, text_annotation -from google.cloud.vision_v1.types import web_detection as gcv_web_detection - __protobuf__ = proto.module( package="google.cloud.vision.v1", manifest={ @@ -91,6 +92,7 @@ class Likelihood(proto.Enum): VERY_LIKELY (5): It is very likely. """ + UNKNOWN = 0 VERY_UNLIKELY = 1 UNLIKELY = 2 @@ -157,6 +159,7 @@ class Type(proto.Enum): OBJECT_LOCALIZATION (19): Run localizer for object detection. """ + TYPE_UNSPECIFIED = 0 FACE_DETECTION = 1 LANDMARK_DETECTION = 2 @@ -410,6 +413,7 @@ class Type(proto.Enum): RIGHT_CHEEK_CENTER (36): Right cheek center. """ + UNKNOWN_LANDMARK = 0 LEFT_EYE = 1 RIGHT_EYE = 2 @@ -937,11 +941,11 @@ class TextDetectionParams(proto.Message): A list of advanced OCR options to further fine-tune OCR behavior. Current valid values are: - - ``legacy_layout``: a heuristics layout detection - algorithm, which serves as an alternative to the current - ML-based layout detection algorithm. Customers can choose - the best suitable layout algorithm based on their - situation. + - ``legacy_layout``: a heuristics layout detection + algorithm, which serves as an alternative to the current + ML-based layout detection algorithm. Customers can choose + the best suitable layout algorithm based on their + situation. """ enable_text_detection_confidence_score: bool = proto.Field( @@ -1141,12 +1145,12 @@ class AnnotateImageResponse(proto.Message): number=4, message="EntityAnnotation", ) - localized_object_annotations: MutableSequence[ - "LocalizedObjectAnnotation" - ] = proto.RepeatedField( - proto.MESSAGE, - number=22, - message="LocalizedObjectAnnotation", + localized_object_annotations: MutableSequence["LocalizedObjectAnnotation"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=22, + message="LocalizedObjectAnnotation", + ) ) text_annotations: MutableSequence["EntityAnnotation"] = proto.RepeatedField( proto.MESSAGE, @@ -1712,16 +1716,16 @@ class GcsDestination(proto.Message): Examples: - - File Prefix: gs://bucket-name/here/filenameprefix The - output files will be created in gs://bucket-name/here/ and - the names of the output files will begin with - "filenameprefix". + - File Prefix: gs://bucket-name/here/filenameprefix The + output files will be created in gs://bucket-name/here/ + and the names of the output files will begin with + "filenameprefix". - - Directory Prefix: gs://bucket-name/some/location/ The - output files will be created in - gs://bucket-name/some/location/ and the names of the - output files could be anything because there was no - filename prefix specified. + - Directory Prefix: gs://bucket-name/some/location/ The + output files will be created in + gs://bucket-name/some/location/ and the names of the + output files could be anything because there was no + filename prefix specified. If multiple outputs, each response is still AnnotateFileResponse, each of which contains some subset of @@ -1764,6 +1768,7 @@ class State(proto.Enum): CANCELLED (4): The batch processing was cancelled. """ + STATE_UNSPECIFIED = 0 CREATED = 1 RUNNING = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search.py b/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search.py index 7b745e9b0bbb..a39a9e866dad 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search.py @@ -17,11 +17,10 @@ from typing import MutableMapping, MutableSequence +from google.cloud.vision_v1.types import geometry, product_search_service from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore -from google.cloud.vision_v1.types import geometry, product_search_service - __protobuf__ = proto.module( package="google.cloud.vision.v1", manifest={ @@ -199,12 +198,12 @@ class GroupedResult(proto.Message): number=2, message="ProductSearchResults.Result", ) - object_annotations: MutableSequence[ - "ProductSearchResults.ObjectAnnotation" - ] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message="ProductSearchResults.ObjectAnnotation", + object_annotations: MutableSequence["ProductSearchResults.ObjectAnnotation"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=3, + message="ProductSearchResults.ObjectAnnotation", + ) ) index_time: timestamp_pb2.Timestamp = proto.Field( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py b/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py index 857fe4832ef3..0db0301c1e4b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py @@ -17,13 +17,14 @@ from typing import MutableMapping, MutableSequence -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +from google.cloud.vision_v1.types import geometry +from google.protobuf import ( + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import status_pb2 # type: ignore import proto # type: ignore -from google.cloud.vision_v1.types import geometry - __protobuf__ = proto.module( package="google.cloud.vision.v1", manifest={ @@ -1019,6 +1020,7 @@ class State(proto.Enum): processed before the cancel command are output as specified in the request. """ + STATE_UNSPECIFIED = 0 PROCESSING = 1 SUCCESSFUL = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/types/text_annotation.py b/packages/google-cloud-vision/google/cloud/vision_v1/types/text_annotation.py index 8461cf71f80f..dddd0807d9ca 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/types/text_annotation.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/types/text_annotation.py @@ -17,9 +17,8 @@ from typing import MutableMapping, MutableSequence -import proto # type: ignore - from google.cloud.vision_v1.types import geometry +import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.vision.v1", @@ -101,6 +100,7 @@ class BreakType(proto.Enum): LINE_BREAK (5): Line break that ends a paragraph. """ + UNKNOWN = 0 SPACE = 1 SURE_SPACE = 2 @@ -129,12 +129,12 @@ class TextProperty(proto.Message): Detected start or end of a text segment. """ - detected_languages: MutableSequence[ - "TextAnnotation.DetectedLanguage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message="TextAnnotation.DetectedLanguage", + detected_languages: MutableSequence["TextAnnotation.DetectedLanguage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=1, + message="TextAnnotation.DetectedLanguage", + ) ) detected_break: "TextAnnotation.DetectedBreak" = proto.Field( proto.MESSAGE, @@ -210,24 +210,24 @@ class Block(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: + - when the text is horizontal it might look like: - :: + :: - 0----1 - | | - 3----2 + 0----1 + | | + 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: + - when it's rotated 180 degrees around the top-left corner + it becomes: - :: + :: - 2----3 - | | - 1----0 + 2----3 + | | + 1----0 - and the vertex order will still be (0, 1, 2, 3). + and the vertex order will still be (0, 1, 2, 3). paragraphs (MutableSequence[google.cloud.vision_v1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). @@ -255,6 +255,7 @@ class BlockType(proto.Enum): BARCODE (5): Barcode block. """ + UNKNOWN = 0 TEXT = 1 TABLE = 2 @@ -303,11 +304,11 @@ class Paragraph(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). words (MutableSequence[google.cloud.vision_v1.types.Word]): List of all words in this paragraph. confidence (float): @@ -349,11 +350,11 @@ class Word(proto.Message): represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). symbols (MutableSequence[google.cloud.vision_v1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural @@ -397,11 +398,11 @@ class Symbol(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). text (str): The actual UTF-8 representation of the symbol. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/types/web_detection.py b/packages/google-cloud-vision/google/cloud/vision_v1/types/web_detection.py index 11ce1af125ac..ac19ca90ff8d 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/types/web_detection.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/types/web_detection.py @@ -137,19 +137,19 @@ class WebPage(proto.Message): proto.STRING, number=3, ) - full_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message="WebDetection.WebImage", + full_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=4, + message="WebDetection.WebImage", + ) ) - partial_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=5, - message="WebDetection.WebImage", + partial_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=5, + message="WebDetection.WebImage", + ) ) class WebLabel(proto.Message): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/__init__.py index 097c67e1b303..e5a365361f11 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/__init__.py @@ -16,7 +16,6 @@ import sys import google.api_core as api_core - from google.cloud.vision_v1p1beta1 import gapic_version as package_version __version__ = package_version.__version__ @@ -28,11 +27,8 @@ # this code path once we drop support for Python 3.7 import importlib_metadata as metadata -from google.cloud.vision_helpers import VisionHelpers -from google.cloud.vision_helpers.decorators import add_single_feature_methods -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.image_annotator import ImageAnnotatorClient as IacImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient, ImageAnnotatorClient from .types.geometry import BoundingPoly, Position, Vertex from .types.image_annotator import ( AnnotateImageRequest, @@ -156,13 +152,6 @@ def _get_version(dependency_name): + "https://devguide.python.org/versions/" ) - -@add_single_feature_methods -class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): - __doc__ = IacImageAnnotatorClient.__doc__ - Feature = Feature - - __all__ = ( "ImageAnnotatorAsyncClient", "AnnotateImageRequest", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py index 859362be169a..2474d088ba49 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py @@ -34,11 +34,10 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p1beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p1beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -114,7 +113,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, info, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_info.__func__( + ImageAnnotatorAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -130,7 +131,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_file.__func__( + ImageAnnotatorAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/client.py index bba40b715ef0..57ff52d008e4 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/client.py @@ -42,11 +42,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p1beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p1beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -77,9 +76,7 @@ class ImageAnnotatorClientMeta(type): objects. """ - _transport_registry = ( - OrderedDict() - ) # type: Dict[str, Type[ImageAnnotatorTransport]] + _transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] _transport_registry["grpc"] = ImageAnnotatorGrpcTransport _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport _transport_registry["rest"] = ImageAnnotatorRestTransport @@ -601,11 +598,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ImageAnnotatorClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ImageAnnotatorClient._read_environment_variables() + ) self._client_cert_source = ImageAnnotatorClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -640,8 +635,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ImageAnnotatorTransport, transport) self._api_endpoint = self._transport.host diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py index aaa523f9a02a..76bc32f896c7 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py @@ -22,11 +22,10 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore -import google.protobuf - from google.cloud.vision_v1p1beta1 import gapic_version as package_version from google.cloud.vision_v1p1beta1.types import image_annotator +from google.oauth2 import service_account # type: ignore +import google.protobuf DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ @@ -85,8 +84,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -101,11 +98,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py index 7566cfe34a44..338caf4ee85e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py @@ -23,13 +23,12 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p1beta1.types import image_annotator from google.protobuf.json_format import MessageToJson import google.protobuf.message import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1p1beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport try: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py index 4d9a6f918369..956faa1dcf75 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py @@ -25,14 +25,13 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p1beta1.types import image_annotator from google.protobuf.json_format import MessageToJson import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1p1beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport from .grpc import ImageAnnotatorGrpcTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest.py index e48eb01b6c98..cc95afaff446 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest.py @@ -24,12 +24,11 @@ from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1p1beta1.types import image_annotator import google.protobuf from google.protobuf import json_format from requests import __version__ as requests_version -from google.cloud.vision_v1p1beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseImageAnnotatorRestTransport @@ -246,6 +245,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -288,9 +288,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() request, metadata = self._interceptor.pre_batch_annotate_images( request, metadata diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest_base.py index 74b435f0b046..7afe90a2d4e3 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/rest_base.py @@ -18,9 +18,8 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template -from google.protobuf import json_format - from google.cloud.vision_v1p1beta1.types import image_annotator +from google.protobuf import json_format from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/__init__.py index 16f754224295..59f5c671e0d1 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/__init__.py @@ -13,7 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .geometry import BoundingPoly, Position, Vertex +from .geometry import ( + BoundingPoly, + Position, + Vertex, +) from .image_annotator import ( AnnotateImageRequest, AnnotateImageResponse, @@ -39,8 +43,17 @@ TextDetectionParams, WebDetectionParams, ) -from .text_annotation import Block, Page, Paragraph, Symbol, TextAnnotation, Word -from .web_detection import WebDetection +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) __all__ = ( "BoundingPoly", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/image_annotator.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/image_annotator.py index 5d1e6d68c11e..d649ef8abd38 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/image_annotator.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/image_annotator.py @@ -17,14 +17,15 @@ from typing import MutableMapping, MutableSequence +from google.cloud.vision_v1p1beta1.types import geometry, text_annotation +from google.cloud.vision_v1p1beta1.types import web_detection as gcv_web_detection from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import latlng_pb2 # type: ignore +from google.type import ( + color_pb2, # type: ignore + latlng_pb2, # type: ignore +) import proto # type: ignore -from google.cloud.vision_v1p1beta1.types import web_detection as gcv_web_detection -from google.cloud.vision_v1p1beta1.types import geometry, text_annotation - __protobuf__ = proto.module( package="google.cloud.vision.v1p1beta1", manifest={ @@ -78,6 +79,7 @@ class Likelihood(proto.Enum): It is very likely that the image belongs to the specified vertical. """ + UNKNOWN = 0 VERY_UNLIKELY = 1 UNLIKELY = 2 @@ -136,6 +138,7 @@ class Type(proto.Enum): WEB_DETECTION (10): Run web detection. """ + TYPE_UNSPECIFIED = 0 FACE_DETECTION = 1 LANDMARK_DETECTION = 2 @@ -370,6 +373,7 @@ class Type(proto.Enum): CHIN_RIGHT_GONION (34): Chin right gonion. """ + UNKNOWN_LANDMARK = 0 LEFT_EYE = 1 RIGHT_EYE = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/text_annotation.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/text_annotation.py index 6a1893ff64f2..722c919433de 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/text_annotation.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/text_annotation.py @@ -17,9 +17,8 @@ from typing import MutableMapping, MutableSequence -import proto # type: ignore - from google.cloud.vision_v1p1beta1.types import geometry +import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.vision.v1p1beta1", @@ -101,6 +100,7 @@ class BreakType(proto.Enum): LINE_BREAK (5): Line break that ends a paragraph. """ + UNKNOWN = 0 SPACE = 1 SURE_SPACE = 2 @@ -129,12 +129,12 @@ class TextProperty(proto.Message): Detected start or end of a text segment. """ - detected_languages: MutableSequence[ - "TextAnnotation.DetectedLanguage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message="TextAnnotation.DetectedLanguage", + detected_languages: MutableSequence["TextAnnotation.DetectedLanguage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=1, + message="TextAnnotation.DetectedLanguage", + ) ) detected_break: "TextAnnotation.DetectedBreak" = proto.Field( proto.MESSAGE, @@ -208,11 +208,11 @@ class Block(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). paragraphs (MutableSequence[google.cloud.vision_v1p1beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). @@ -240,6 +240,7 @@ class BlockType(proto.Enum): BARCODE (5): Barcode block. """ + UNKNOWN = 0 TEXT = 1 TABLE = 2 @@ -288,11 +289,11 @@ class Paragraph(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). words (MutableSequence[google.cloud.vision_v1p1beta1.types.Word]): List of words in this paragraph. confidence (float): @@ -334,11 +335,11 @@ class Word(proto.Message): represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). symbols (MutableSequence[google.cloud.vision_v1p1beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural @@ -382,11 +383,11 @@ class Symbol(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). text (str): The actual UTF-8 representation of the symbol. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/web_detection.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/web_detection.py index bdfaf20fc558..2924fbd3cf5d 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/web_detection.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/types/web_detection.py @@ -135,19 +135,19 @@ class WebPage(proto.Message): proto.STRING, number=3, ) - full_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message="WebDetection.WebImage", + full_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=4, + message="WebDetection.WebImage", + ) ) - partial_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=5, - message="WebDetection.WebImage", + partial_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=5, + message="WebDetection.WebImage", + ) ) class WebLabel(proto.Message): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/__init__.py index 38b15b5dabec..06d169afc46a 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/__init__.py @@ -16,7 +16,6 @@ import sys import google.api_core as api_core - from google.cloud.vision_v1p2beta1 import gapic_version as package_version __version__ = package_version.__version__ @@ -28,11 +27,8 @@ # this code path once we drop support for Python 3.7 import importlib_metadata as metadata -from google.cloud.vision_helpers import VisionHelpers -from google.cloud.vision_helpers.decorators import add_single_feature_methods -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.image_annotator import ImageAnnotatorClient as IacImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient, ImageAnnotatorClient from .types.geometry import BoundingPoly, NormalizedVertex, Position, Vertex from .types.image_annotator import ( AnnotateFileResponse, @@ -167,13 +163,6 @@ def _get_version(dependency_name): + "https://devguide.python.org/versions/" ) - -@add_single_feature_methods -class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): - __doc__ = IacImageAnnotatorClient.__doc__ - Feature = Feature - - __all__ = ( "ImageAnnotatorAsyncClient", "AnnotateFileResponse", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py index fb5632ad071d..0528a39427ab 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py @@ -35,19 +35,19 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p2beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p2beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p2beta1.types import image_annotator from .client import ImageAnnotatorClient @@ -118,7 +118,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, info, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_info.__func__( + ImageAnnotatorAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -134,7 +136,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_file.__func__( + ImageAnnotatorAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/client.py index aa9125703821..1021ff959735 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/client.py @@ -43,11 +43,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p2beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p2beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -62,9 +61,10 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p2beta1.types import image_annotator from .transports.base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport @@ -81,9 +81,7 @@ class ImageAnnotatorClientMeta(type): objects. """ - _transport_registry = ( - OrderedDict() - ) # type: Dict[str, Type[ImageAnnotatorTransport]] + _transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] _transport_registry["grpc"] = ImageAnnotatorGrpcTransport _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport _transport_registry["rest"] = ImageAnnotatorRestTransport @@ -605,11 +603,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ImageAnnotatorClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ImageAnnotatorClient._read_environment_variables() + ) self._client_cert_source = ImageAnnotatorClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -644,8 +640,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ImageAnnotatorTransport, transport) self._api_endpoint = self._transport.host diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py index 0e16cba7627b..6b9732e8deb5 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py @@ -22,13 +22,12 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p2beta1 import gapic_version as package_version +from google.cloud.vision_v1p2beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p2beta1 import gapic_version as package_version -from google.cloud.vision_v1p2beta1.types import image_annotator - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ ) @@ -86,8 +85,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -102,11 +99,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py index 7fe5866362e2..c14911e3a9d2 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py @@ -23,14 +23,13 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p2beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1p2beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport try: @@ -399,12 +398,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py index 41879c4326a0..ccd791fc5b4f 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p2beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message @@ -32,8 +33,6 @@ from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1p2beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport from .grpc import ImageAnnotatorGrpcTransport @@ -408,12 +407,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest.py index 69fd6a6d7998..74c75fb0bb2e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest.py @@ -19,18 +19,17 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1p2beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore import google.protobuf from google.protobuf import json_format from requests import __version__ as requests_version -from google.cloud.vision_v1p2beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseImageAnnotatorRestTransport @@ -332,6 +331,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -377,9 +377,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() request, metadata = self._interceptor.pre_async_batch_annotate_files( request, metadata @@ -491,6 +489,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -533,9 +532,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() request, metadata = self._interceptor.pre_batch_annotate_images( request, metadata @@ -640,7 +637,9 @@ def async_batch_annotate_files( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AsyncBatchAnnotateFiles(self._session, self._host, self._interceptor) # type: ignore + return self._AsyncBatchAnnotateFiles( + self._session, self._host, self._interceptor + ) # type: ignore @property def batch_annotate_images( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest_base.py index e26576904564..7db7c233ba6e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/rest_base.py @@ -18,11 +18,10 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template +from google.cloud.vision_v1p2beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf import json_format -from google.cloud.vision_v1p2beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/__init__.py index 70859b5384a4..3905e34e3f6b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/__init__.py @@ -13,7 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .geometry import BoundingPoly, NormalizedVertex, Position, Vertex +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Position, + Vertex, +) from .image_annotator import ( AnnotateFileResponse, AnnotateImageRequest, @@ -50,8 +55,17 @@ TextDetectionParams, WebDetectionParams, ) -from .text_annotation import Block, Page, Paragraph, Symbol, TextAnnotation, Word -from .web_detection import WebDetection +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) __all__ = ( "BoundingPoly", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/image_annotator.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/image_annotator.py index 89143e766721..936810b1b923 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/image_annotator.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/image_annotator.py @@ -17,15 +17,16 @@ from typing import MutableMapping, MutableSequence +from google.cloud.vision_v1p2beta1.types import geometry, text_annotation +from google.cloud.vision_v1p2beta1.types import web_detection as gcv_web_detection from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import latlng_pb2 # type: ignore +from google.type import ( + color_pb2, # type: ignore + latlng_pb2, # type: ignore +) import proto # type: ignore -from google.cloud.vision_v1p2beta1.types import web_detection as gcv_web_detection -from google.cloud.vision_v1p2beta1.types import geometry, text_annotation - __protobuf__ = proto.module( package="google.cloud.vision.v1p2beta1", manifest={ @@ -90,6 +91,7 @@ class Likelihood(proto.Enum): It is very likely that the image belongs to the specified vertical. """ + UNKNOWN = 0 VERY_UNLIKELY = 1 UNLIKELY = 2 @@ -152,6 +154,7 @@ class Type(proto.Enum): WEB_DETECTION (10): Run web detection. """ + TYPE_UNSPECIFIED = 0 FACE_DETECTION = 1 LANDMARK_DETECTION = 2 @@ -396,6 +399,7 @@ class Type(proto.Enum): CHIN_RIGHT_GONION (34): Chin right gonion. """ + UNKNOWN_LANDMARK = 0 LEFT_EYE = 1 RIGHT_EYE = 2 @@ -1336,9 +1340,9 @@ class GcsDestination(proto.Message): Examples: - - File: gs://bucket-name/filename.json - - Prefix: gs://bucket-name/prefix/here/ - - File: gs://bucket-name/prefix/here + - File: gs://bucket-name/filename.json + - Prefix: gs://bucket-name/prefix/here/ + - File: gs://bucket-name/prefix/here If multiple outputs, each response is still AnnotateFileResponse, each of which contains some subset of @@ -1381,6 +1385,7 @@ class State(proto.Enum): CANCELLED (4): The batch processing was cancelled. """ + STATE_UNSPECIFIED = 0 CREATED = 1 RUNNING = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/text_annotation.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/text_annotation.py index 1fed739872b4..53181f8b3e0a 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/text_annotation.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/text_annotation.py @@ -17,9 +17,8 @@ from typing import MutableMapping, MutableSequence -import proto # type: ignore - from google.cloud.vision_v1p2beta1.types import geometry +import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.vision.v1p2beta1", @@ -101,6 +100,7 @@ class BreakType(proto.Enum): LINE_BREAK (5): Line break that ends a paragraph. """ + UNKNOWN = 0 SPACE = 1 SURE_SPACE = 2 @@ -129,12 +129,12 @@ class TextProperty(proto.Message): Detected start or end of a text segment. """ - detected_languages: MutableSequence[ - "TextAnnotation.DetectedLanguage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message="TextAnnotation.DetectedLanguage", + detected_languages: MutableSequence["TextAnnotation.DetectedLanguage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=1, + message="TextAnnotation.DetectedLanguage", + ) ) detected_break: "TextAnnotation.DetectedBreak" = proto.Field( proto.MESSAGE, @@ -210,24 +210,24 @@ class Block(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: + - when the text is horizontal it might look like: - :: + :: - 0----1 - | | - 3----2 + 0----1 + | | + 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: + - when it's rotated 180 degrees around the top-left corner + it becomes: - :: + :: - 2----3 - | | - 1----0 + 2----3 + | | + 1----0 - and the vertice order will still be (0, 1, 2, 3). + and the vertice order will still be (0, 1, 2, 3). paragraphs (MutableSequence[google.cloud.vision_v1p2beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). @@ -255,6 +255,7 @@ class BlockType(proto.Enum): BARCODE (5): Barcode block. """ + UNKNOWN = 0 TEXT = 1 TABLE = 2 @@ -303,11 +304,11 @@ class Paragraph(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). words (MutableSequence[google.cloud.vision_v1p2beta1.types.Word]): List of words in this paragraph. confidence (float): @@ -349,11 +350,11 @@ class Word(proto.Message): represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). symbols (MutableSequence[google.cloud.vision_v1p2beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural @@ -397,11 +398,11 @@ class Symbol(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). text (str): The actual UTF-8 representation of the symbol. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/web_detection.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/web_detection.py index 648d4e415953..5b82e384e648 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/web_detection.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/types/web_detection.py @@ -135,19 +135,19 @@ class WebPage(proto.Message): proto.STRING, number=3, ) - full_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message="WebDetection.WebImage", + full_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=4, + message="WebDetection.WebImage", + ) ) - partial_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=5, - message="WebDetection.WebImage", + partial_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=5, + message="WebDetection.WebImage", + ) ) class WebLabel(proto.Message): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/__init__.py index a2e768f2a3da..c9c687b9dccd 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/__init__.py @@ -16,7 +16,6 @@ import sys import google.api_core as api_core - from google.cloud.vision_v1p3beta1 import gapic_version as package_version __version__ = package_version.__version__ @@ -28,11 +27,8 @@ # this code path once we drop support for Python 3.7 import importlib_metadata as metadata -from google.cloud.vision_helpers import VisionHelpers -from google.cloud.vision_helpers.decorators import add_single_feature_methods -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.image_annotator import ImageAnnotatorClient as IacImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient, ImageAnnotatorClient from .services.product_search import ProductSearchAsyncClient, ProductSearchClient from .types.geometry import BoundingPoly, NormalizedVertex, Position, Vertex from .types.image_annotator import ( @@ -201,13 +197,6 @@ def _get_version(dependency_name): + "https://devguide.python.org/versions/" ) - -@add_single_feature_methods -class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): - __doc__ = IacImageAnnotatorClient.__doc__ - Feature = Feature - - __all__ = ( "ImageAnnotatorAsyncClient", "ProductSearchAsyncClient", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py index 2d7135564480..255facc5fd8b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py @@ -34,19 +34,19 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p3beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p3beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p3beta1.types import image_annotator from .client import ImageAnnotatorClient @@ -121,7 +121,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, info, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_info.__func__( + ImageAnnotatorAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -137,7 +139,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_file.__func__( + ImageAnnotatorAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/client.py index d459e909b674..31cbc1f0e797 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/client.py @@ -42,11 +42,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p3beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p3beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -61,9 +60,10 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p3beta1.types import image_annotator from .transports.base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport @@ -80,9 +80,7 @@ class ImageAnnotatorClientMeta(type): objects. """ - _transport_registry = ( - OrderedDict() - ) # type: Dict[str, Type[ImageAnnotatorTransport]] + _transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] _transport_registry["grpc"] = ImageAnnotatorGrpcTransport _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport _transport_registry["rest"] = ImageAnnotatorRestTransport @@ -650,11 +648,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ImageAnnotatorClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ImageAnnotatorClient._read_environment_variables() + ) self._client_cert_source = ImageAnnotatorClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -689,8 +685,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ImageAnnotatorTransport, transport) self._api_endpoint = self._transport.host diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py index 1f027daad808..ebff7014f168 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py @@ -22,13 +22,12 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p3beta1 import gapic_version as package_version +from google.cloud.vision_v1p3beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p3beta1 import gapic_version as package_version -from google.cloud.vision_v1p3beta1.types import image_annotator - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ ) @@ -86,8 +85,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -102,11 +99,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py index 19d16fc5d3a5..741e8d60035b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py @@ -23,14 +23,13 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p3beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1p3beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport try: @@ -399,12 +398,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py index 73745c486211..3cb7dcffbc4a 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p3beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message @@ -32,8 +33,6 @@ from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1p3beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport from .grpc import ImageAnnotatorGrpcTransport @@ -408,12 +407,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest.py index 3a71729d0405..eedfe15adcf2 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest.py @@ -19,18 +19,17 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1p3beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore import google.protobuf from google.protobuf import json_format from requests import __version__ as requests_version -from google.cloud.vision_v1p3beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseImageAnnotatorRestTransport @@ -332,6 +331,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -377,9 +377,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() request, metadata = self._interceptor.pre_async_batch_annotate_files( request, metadata @@ -491,6 +489,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -533,9 +532,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() request, metadata = self._interceptor.pre_batch_annotate_images( request, metadata @@ -640,7 +637,9 @@ def async_batch_annotate_files( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AsyncBatchAnnotateFiles(self._session, self._host, self._interceptor) # type: ignore + return self._AsyncBatchAnnotateFiles( + self._session, self._host, self._interceptor + ) # type: ignore @property def batch_annotate_images( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest_base.py index 16497c3859bd..e186e4b91f96 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/rest_base.py @@ -18,11 +18,10 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template +from google.cloud.vision_v1p3beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf import json_format -from google.cloud.vision_v1p3beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/async_client.py index 5902002a7d3d..42d5029dd52c 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/async_client.py @@ -34,24 +34,26 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p3beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p3beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p3beta1.services.product_search import pagers from google.cloud.vision_v1p3beta1.types import geometry, product_search_service +from google.protobuf import ( + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore from .client import ProductSearchClient from .transports.base import DEFAULT_CLIENT_INFO, ProductSearchTransport @@ -71,22 +73,23 @@ class ProductSearchAsyncClient: """Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` """ _client: ProductSearchClient @@ -144,7 +147,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ProductSearchAsyncClient: The constructed client. """ - return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, info, *args, **kwargs) # type: ignore + return ProductSearchClient.from_service_account_info.__func__( + ProductSearchAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -160,7 +165,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ProductSearchAsyncClient: The constructed client. """ - return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore + return ProductSearchClient.from_service_account_file.__func__( + ProductSearchAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file @@ -335,8 +342,8 @@ async def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. .. code-block:: python @@ -476,8 +483,8 @@ async def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. .. code-block:: python @@ -609,7 +616,7 @@ async def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -732,10 +739,10 @@ async def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. .. code-block:: python @@ -832,9 +839,9 @@ async def sample_update_product_set(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product_set.name", request.product_set.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), ) # Validate the universe domain. @@ -870,7 +877,7 @@ async def delete_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -978,12 +985,12 @@ async def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. .. code-block:: python @@ -1118,8 +1125,8 @@ async def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python @@ -1249,7 +1256,7 @@ async def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. .. code-block:: python @@ -1370,14 +1377,14 @@ async def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. .. code-block:: python @@ -1471,9 +1478,9 @@ async def sample_update_product(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product.name", request.product.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), ) # Validate the universe domain. @@ -1509,7 +1516,7 @@ async def delete_product( Possible errors: - - Returns NOT_FOUND if the product does not exist. + - Returns NOT_FOUND if the product does not exist. .. code-block:: python @@ -1627,14 +1634,14 @@ async def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. .. code-block:: python @@ -1786,7 +1793,7 @@ async def delete_reference_image( Possible errors: - - Returns NOT_FOUND if the reference image does not exist. + - Returns NOT_FOUND if the reference image does not exist. .. code-block:: python @@ -1894,9 +1901,9 @@ async def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. .. code-block:: python @@ -2029,7 +2036,7 @@ async def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. .. code-block:: python @@ -2153,8 +2160,8 @@ async def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. .. code-block:: python @@ -2278,8 +2285,8 @@ async def remove_product_from_product_set( Possible errors: - - Returns NOT_FOUND If the Product is not found under the - ProductSet. + - Returns NOT_FOUND If the Product is not found under the + ProductSet. .. code-block:: python @@ -2404,8 +2411,8 @@ async def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/client.py index 49204ee8fdac..71b1f3d4ebd0 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/client.py @@ -42,11 +42,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p3beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p3beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -61,14 +60,17 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p3beta1.services.product_search import pagers from google.cloud.vision_v1p3beta1.types import geometry, product_search_service +from google.protobuf import ( + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore from .transports.base import DEFAULT_CLIENT_INFO, ProductSearchTransport from .transports.grpc import ProductSearchGrpcTransport @@ -115,22 +117,23 @@ class ProductSearchClient(metaclass=ProductSearchClientMeta): """Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` """ @staticmethod @@ -691,11 +694,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ProductSearchClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ProductSearchClient._read_environment_variables() + ) self._client_cert_source = ProductSearchClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -730,8 +731,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ProductSearchTransport, transport) self._api_endpoint = self._transport.host @@ -816,8 +816,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. .. code-block:: python @@ -954,8 +954,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. .. code-block:: python @@ -1084,7 +1084,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -1204,10 +1204,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. .. code-block:: python @@ -1301,9 +1301,9 @@ def sample_update_product_set(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product_set.name", request.product_set.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), ) # Validate the universe domain. @@ -1339,7 +1339,7 @@ def delete_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -1444,12 +1444,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. .. code-block:: python @@ -1581,8 +1581,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python @@ -1709,7 +1709,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. .. code-block:: python @@ -1827,14 +1827,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. .. code-block:: python @@ -1925,9 +1925,9 @@ def sample_update_product(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product.name", request.product.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), ) # Validate the universe domain. @@ -1963,7 +1963,7 @@ def delete_product( Possible errors: - - Returns NOT_FOUND if the product does not exist. + - Returns NOT_FOUND if the product does not exist. .. code-block:: python @@ -2078,14 +2078,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. .. code-block:: python @@ -2234,7 +2234,7 @@ def delete_reference_image( Possible errors: - - Returns NOT_FOUND if the reference image does not exist. + - Returns NOT_FOUND if the reference image does not exist. .. code-block:: python @@ -2339,9 +2339,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. .. code-block:: python @@ -2471,7 +2471,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. .. code-block:: python @@ -2592,8 +2592,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. .. code-block:: python @@ -2716,8 +2716,8 @@ def remove_product_from_product_set( Possible errors: - - Returns NOT_FOUND If the Product is not found under the - ProductSet. + - Returns NOT_FOUND If the Product is not found under the + ProductSet. .. code-block:: python @@ -2841,8 +2841,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/pagers.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/pagers.py index 4dee59745eaf..9913867a51ff 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/pagers.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -145,7 +145,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -227,7 +227,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -303,7 +303,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -383,7 +383,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -461,7 +461,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -543,7 +543,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -623,7 +623,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py index dbc3b9149b32..44a5727133f6 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py @@ -22,14 +22,13 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p3beta1 import gapic_version as package_version +from google.cloud.vision_v1p3beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore import google.protobuf from google.protobuf import empty_pb2 # type: ignore -from google.cloud.vision_v1p3beta1 import gapic_version as package_version -from google.cloud.vision_v1p3beta1.types import product_search_service - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ ) @@ -87,8 +86,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -103,11 +100,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py index 4ddca650fe7e..ff3bbf8d8591 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py @@ -23,6 +23,7 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p3beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson @@ -30,8 +31,6 @@ import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1p3beta1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport try: @@ -115,22 +114,23 @@ class ProductSearchGrpcTransport(ProductSearchTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -371,8 +371,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. Returns: Callable[[~.CreateProductSetRequest], @@ -405,8 +405,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. Returns: Callable[[~.ListProductSetsRequest], @@ -438,7 +438,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.GetProductSetRequest], @@ -472,10 +472,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. Returns: Callable[[~.UpdateProductSetRequest], @@ -509,7 +509,7 @@ def delete_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.DeleteProductSetRequest], @@ -541,12 +541,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. Returns: Callable[[~.CreateProductRequest], @@ -579,8 +579,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsRequest], @@ -612,7 +612,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. Returns: Callable[[~.GetProductRequest], @@ -648,14 +648,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. Returns: Callable[[~.UpdateProductRequest], @@ -689,7 +689,7 @@ def delete_product( Possible errors: - - Returns NOT_FOUND if the product does not exist. + - Returns NOT_FOUND if the product does not exist. Returns: Callable[[~.DeleteProductRequest], @@ -732,14 +732,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. Returns: Callable[[~.CreateReferenceImageRequest], @@ -778,7 +778,7 @@ def delete_reference_image( Possible errors: - - Returns NOT_FOUND if the reference image does not exist. + - Returns NOT_FOUND if the reference image does not exist. Returns: Callable[[~.DeleteReferenceImageRequest], @@ -811,9 +811,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. Returns: Callable[[~.ListReferenceImagesRequest], @@ -846,7 +846,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. Returns: Callable[[~.GetReferenceImageRequest], @@ -881,8 +881,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. Returns: Callable[[~.AddProductToProductSetRequest], @@ -895,12 +895,12 @@ def add_product_to_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_product_to_product_set" not in self._stubs: - self._stubs[ - "add_product_to_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet", - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["add_product_to_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet", + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["add_product_to_product_set"] @@ -917,8 +917,8 @@ def remove_product_from_product_set( Possible errors: - - Returns NOT_FOUND If the Product is not found under the - ProductSet. + - Returns NOT_FOUND If the Product is not found under the + ProductSet. Returns: Callable[[~.RemoveProductFromProductSetRequest], @@ -931,12 +931,12 @@ def remove_product_from_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_product_from_product_set" not in self._stubs: - self._stubs[ - "remove_product_from_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet", - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["remove_product_from_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet", + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["remove_product_from_product_set"] @@ -955,8 +955,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsInProductSetRequest], @@ -969,12 +969,12 @@ def list_products_in_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_products_in_product_set" not in self._stubs: - self._stubs[ - "list_products_in_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet", - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + self._stubs["list_products_in_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet", + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) ) return self._stubs["list_products_in_product_set"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py index cc26271ea70d..e10aa44e93e3 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p3beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson @@ -33,8 +34,6 @@ from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1p3beta1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport from .grpc import ProductSearchGrpcTransport @@ -121,22 +120,23 @@ class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -379,8 +379,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. Returns: Callable[[~.CreateProductSetRequest], @@ -413,8 +413,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. Returns: Callable[[~.ListProductSetsRequest], @@ -447,7 +447,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.GetProductSetRequest], @@ -481,10 +481,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. Returns: Callable[[~.UpdateProductSetRequest], @@ -520,7 +520,7 @@ def delete_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.DeleteProductSetRequest], @@ -553,12 +553,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. Returns: Callable[[~.CreateProductRequest], @@ -591,8 +591,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsRequest], @@ -625,7 +625,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. Returns: Callable[[~.GetProductRequest], @@ -662,14 +662,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. Returns: Callable[[~.UpdateProductRequest], @@ -705,7 +705,7 @@ def delete_product( Possible errors: - - Returns NOT_FOUND if the product does not exist. + - Returns NOT_FOUND if the product does not exist. Returns: Callable[[~.DeleteProductRequest], @@ -748,14 +748,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. Returns: Callable[[~.CreateReferenceImageRequest], @@ -794,7 +794,7 @@ def delete_reference_image( Possible errors: - - Returns NOT_FOUND if the reference image does not exist. + - Returns NOT_FOUND if the reference image does not exist. Returns: Callable[[~.DeleteReferenceImageRequest], @@ -827,9 +827,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. Returns: Callable[[~.ListReferenceImagesRequest], @@ -862,7 +862,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. Returns: Callable[[~.GetReferenceImageRequest], @@ -898,8 +898,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. Returns: Callable[[~.AddProductToProductSetRequest], @@ -912,12 +912,12 @@ def add_product_to_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_product_to_product_set" not in self._stubs: - self._stubs[ - "add_product_to_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet", - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["add_product_to_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet", + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["add_product_to_product_set"] @@ -935,8 +935,8 @@ def remove_product_from_product_set( Possible errors: - - Returns NOT_FOUND If the Product is not found under the - ProductSet. + - Returns NOT_FOUND If the Product is not found under the + ProductSet. Returns: Callable[[~.RemoveProductFromProductSetRequest], @@ -949,12 +949,12 @@ def remove_product_from_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_product_from_product_set" not in self._stubs: - self._stubs[ - "remove_product_from_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet", - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["remove_product_from_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet", + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["remove_product_from_product_set"] @@ -973,8 +973,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsInProductSetRequest], @@ -987,12 +987,12 @@ def list_products_in_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_products_in_product_set" not in self._stubs: - self._stubs[ - "list_products_in_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet", - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + self._stubs["list_products_in_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet", + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) ) return self._stubs["list_products_in_product_set"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest.py index 157314187d5e..4da64b85fb72 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest.py @@ -19,19 +19,20 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1p3beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore import google.protobuf -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from requests import __version__ as requests_version -from google.cloud.vision_v1p3beta1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseProductSearchRestTransport @@ -952,22 +953,23 @@ class ProductSearchRestTransport(_BaseProductSearchRestTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -1089,6 +1091,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1126,9 +1129,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseAddProductToProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseAddProductToProductSet._get_http_options() request, metadata = self._interceptor.pre_add_product_to_product_set( request, metadata @@ -1205,6 +1206,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1355,6 +1357,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1399,9 +1402,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseCreateProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseCreateProductSet._get_http_options() request, metadata = self._interceptor.pre_create_product_set( request, metadata @@ -1514,6 +1515,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1555,9 +1557,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseCreateReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseCreateReferenceImage._get_http_options() request, metadata = self._interceptor.pre_create_reference_image( request, metadata @@ -1670,6 +1670,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1776,6 +1777,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1810,9 +1812,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseDeleteProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseDeleteProductSet._get_http_options() request, metadata = self._interceptor.pre_delete_product_set( request, metadata @@ -1884,6 +1884,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1918,9 +1919,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseDeleteReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseDeleteReferenceImage._get_http_options() request, metadata = self._interceptor.pre_delete_reference_image( request, metadata @@ -1992,6 +1991,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2140,6 +2140,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2291,6 +2292,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2331,9 +2333,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseGetReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseGetReferenceImage._get_http_options() request, metadata = self._interceptor.pre_get_reference_image( request, metadata @@ -2441,6 +2441,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2483,9 +2484,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseImportProductSets._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseImportProductSets._get_http_options() request, metadata = self._interceptor.pre_import_product_sets( request, metadata @@ -2594,6 +2593,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2740,6 +2740,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2889,6 +2890,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2931,9 +2933,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseListProductsInProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseListProductsInProductSet._get_http_options() request, metadata = self._interceptor.pre_list_products_in_product_set( request, metadata @@ -3045,6 +3045,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3083,9 +3084,7 @@ def __call__( Response message for the ``ListReferenceImages`` method. """ - http_options = ( - _BaseProductSearchRestTransport._BaseListReferenceImages._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseListReferenceImages._get_http_options() request, metadata = self._interceptor.pre_list_reference_images( request, metadata @@ -3196,6 +3195,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3233,9 +3233,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseRemoveProductFromProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseRemoveProductFromProductSet._get_http_options() request, metadata = self._interceptor.pre_remove_product_from_product_set( request, metadata @@ -3314,6 +3312,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3464,6 +3463,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3508,9 +3508,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseUpdateProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseUpdateProductSet._get_http_options() request, metadata = self._interceptor.pre_update_product_set( request, metadata @@ -3615,7 +3613,9 @@ def add_product_to_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AddProductToProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._AddProductToProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def create_product( @@ -3747,7 +3747,9 @@ def list_products_in_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._ListProductsInProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._ListProductsInProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def list_reference_images( @@ -3768,7 +3770,9 @@ def remove_product_from_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._RemoveProductFromProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._RemoveProductFromProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def update_product( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest_base.py index b29be1fe56d3..213f135f11e7 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/rest_base.py @@ -18,11 +18,12 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format - from google.cloud.vision_v1p3beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/__init__.py index e5688e0c64f2..0c838e6d7f41 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/__init__.py @@ -13,7 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .geometry import BoundingPoly, NormalizedVertex, Position, Vertex +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Position, + Vertex, +) from .image_annotator import ( AnnotateFileResponse, AnnotateImageRequest, @@ -51,7 +56,10 @@ TextDetectionParams, WebDetectionParams, ) -from .product_search import ProductSearchParams, ProductSearchResults +from .product_search import ( + ProductSearchParams, + ProductSearchResults, +) from .product_search_service import ( AddProductToProductSetRequest, BatchOperationMetadata, @@ -83,8 +91,17 @@ UpdateProductRequest, UpdateProductSetRequest, ) -from .text_annotation import Block, Page, Paragraph, Symbol, TextAnnotation, Word -from .web_detection import WebDetection +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) __all__ = ( "BoundingPoly", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/image_annotator.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/image_annotator.py index d9726c6461f3..a6a62c409175 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/image_annotator.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/image_annotator.py @@ -17,18 +17,19 @@ from typing import MutableMapping, MutableSequence -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import latlng_pb2 # type: ignore -import proto # type: ignore - from google.cloud.vision_v1p3beta1.types import ( geometry, product_search, text_annotation, ) from google.cloud.vision_v1p3beta1.types import web_detection as gcv_web_detection +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from google.type import ( + color_pb2, # type: ignore + latlng_pb2, # type: ignore +) +import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.vision.v1p3beta1", @@ -95,6 +96,7 @@ class Likelihood(proto.Enum): It is very likely that the image belongs to the specified vertical. """ + UNKNOWN = 0 VERY_UNLIKELY = 1 UNLIKELY = 2 @@ -161,6 +163,7 @@ class Type(proto.Enum): OBJECT_LOCALIZATION (19): Run localizer for object detection. """ + TYPE_UNSPECIFIED = 0 FACE_DETECTION = 1 LANDMARK_DETECTION = 2 @@ -407,6 +410,7 @@ class Type(proto.Enum): CHIN_RIGHT_GONION (34): Chin right gonion. """ + UNKNOWN_LANDMARK = 0 LEFT_EYE = 1 RIGHT_EYE = 2 @@ -1128,12 +1132,12 @@ class AnnotateImageResponse(proto.Message): number=4, message="EntityAnnotation", ) - localized_object_annotations: MutableSequence[ - "LocalizedObjectAnnotation" - ] = proto.RepeatedField( - proto.MESSAGE, - number=22, - message="LocalizedObjectAnnotation", + localized_object_annotations: MutableSequence["LocalizedObjectAnnotation"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=22, + message="LocalizedObjectAnnotation", + ) ) text_annotations: MutableSequence["EntityAnnotation"] = proto.RepeatedField( proto.MESSAGE, @@ -1416,9 +1420,9 @@ class GcsDestination(proto.Message): Examples: - - File: gs://bucket-name/filename.json - - Prefix: gs://bucket-name/prefix/here/ - - File: gs://bucket-name/prefix/here + - File: gs://bucket-name/filename.json + - Prefix: gs://bucket-name/prefix/here/ + - File: gs://bucket-name/prefix/here If multiple outputs, each response is still AnnotateFileResponse, each of which contains some subset of @@ -1461,6 +1465,7 @@ class State(proto.Enum): CANCELLED (4): The batch processing was cancelled. """ + STATE_UNSPECIFIED = 0 CREATED = 1 RUNNING = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search.py index 4cd22fcf75e0..940086c9ab9d 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search.py @@ -17,11 +17,10 @@ from typing import MutableMapping, MutableSequence +from google.cloud.vision_v1p3beta1.types import geometry, product_search_service from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore -from google.cloud.vision_v1p3beta1.types import geometry, product_search_service - __protobuf__ = proto.module( package="google.cloud.vision.v1p3beta1", manifest={ @@ -199,12 +198,12 @@ class GroupedResult(proto.Message): number=2, message="ProductSearchResults.Result", ) - object_annotations: MutableSequence[ - "ProductSearchResults.ObjectAnnotation" - ] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message="ProductSearchResults.ObjectAnnotation", + object_annotations: MutableSequence["ProductSearchResults.ObjectAnnotation"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=3, + message="ProductSearchResults.ObjectAnnotation", + ) ) index_time: timestamp_pb2.Timestamp = proto.Field( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py index b082ad202abf..f9a7b5ec2c2e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py @@ -17,13 +17,14 @@ from typing import MutableMapping, MutableSequence -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +from google.cloud.vision_v1p3beta1.types import geometry +from google.protobuf import ( + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import status_pb2 # type: ignore import proto # type: ignore -from google.cloud.vision_v1p3beta1.types import geometry - __protobuf__ = proto.module( package="google.cloud.vision.v1p3beta1", manifest={ @@ -1000,6 +1001,7 @@ class State(proto.Enum): processed before the cancel command are output as specified in the request. """ + STATE_UNSPECIFIED = 0 PROCESSING = 1 SUCCESSFUL = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/text_annotation.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/text_annotation.py index 660990572b2e..4d30a350308b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/text_annotation.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/text_annotation.py @@ -17,9 +17,8 @@ from typing import MutableMapping, MutableSequence -import proto # type: ignore - from google.cloud.vision_v1p3beta1.types import geometry +import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.vision.v1p3beta1", @@ -101,6 +100,7 @@ class BreakType(proto.Enum): LINE_BREAK (5): Line break that ends a paragraph. """ + UNKNOWN = 0 SPACE = 1 SURE_SPACE = 2 @@ -129,12 +129,12 @@ class TextProperty(proto.Message): Detected start or end of a text segment. """ - detected_languages: MutableSequence[ - "TextAnnotation.DetectedLanguage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message="TextAnnotation.DetectedLanguage", + detected_languages: MutableSequence["TextAnnotation.DetectedLanguage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=1, + message="TextAnnotation.DetectedLanguage", + ) ) detected_break: "TextAnnotation.DetectedBreak" = proto.Field( proto.MESSAGE, @@ -210,24 +210,24 @@ class Block(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: + - when the text is horizontal it might look like: - :: + :: - 0----1 - | | - 3----2 + 0----1 + | | + 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: + - when it's rotated 180 degrees around the top-left corner + it becomes: - :: + :: - 2----3 - | | - 1----0 + 2----3 + | | + 1----0 - and the vertice order will still be (0, 1, 2, 3). + and the vertice order will still be (0, 1, 2, 3). paragraphs (MutableSequence[google.cloud.vision_v1p3beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). @@ -255,6 +255,7 @@ class BlockType(proto.Enum): BARCODE (5): Barcode block. """ + UNKNOWN = 0 TEXT = 1 TABLE = 2 @@ -303,11 +304,11 @@ class Paragraph(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). words (MutableSequence[google.cloud.vision_v1p3beta1.types.Word]): List of words in this paragraph. confidence (float): @@ -349,11 +350,11 @@ class Word(proto.Message): represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). symbols (MutableSequence[google.cloud.vision_v1p3beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural @@ -397,11 +398,11 @@ class Symbol(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). text (str): The actual UTF-8 representation of the symbol. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/web_detection.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/web_detection.py index 887e53444d05..7144923b02aa 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/web_detection.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/web_detection.py @@ -135,19 +135,19 @@ class WebPage(proto.Message): proto.STRING, number=3, ) - full_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message="WebDetection.WebImage", + full_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=4, + message="WebDetection.WebImage", + ) ) - partial_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=5, - message="WebDetection.WebImage", + partial_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=5, + message="WebDetection.WebImage", + ) ) class WebLabel(proto.Message): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/__init__.py index f921e4ab9124..8b3a427c0577 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/__init__.py @@ -16,7 +16,6 @@ import sys import google.api_core as api_core - from google.cloud.vision_v1p4beta1 import gapic_version as package_version __version__ = package_version.__version__ @@ -28,11 +27,8 @@ # this code path once we drop support for Python 3.7 import importlib_metadata as metadata -from google.cloud.vision_helpers import VisionHelpers -from google.cloud.vision_helpers.decorators import add_single_feature_methods -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.image_annotator import ImageAnnotatorClient as IacImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient, ImageAnnotatorClient from .services.product_search import ProductSearchAsyncClient, ProductSearchClient from .types.face import Celebrity, FaceRecognitionParams, FaceRecognitionResult from .types.geometry import BoundingPoly, NormalizedVertex, Position, Vertex @@ -209,13 +205,6 @@ def _get_version(dependency_name): + "https://devguide.python.org/versions/" ) - -@add_single_feature_methods -class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): - __doc__ = IacImageAnnotatorClient.__doc__ - Feature = Feature - - __all__ = ( "ImageAnnotatorAsyncClient", "ProductSearchAsyncClient", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py index 82d9164b0b9a..c621954c3af7 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py @@ -34,19 +34,19 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p4beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p4beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p4beta1.types import image_annotator from .client import ImageAnnotatorClient @@ -121,7 +121,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, info, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_info.__func__( + ImageAnnotatorAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -137,7 +139,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ImageAnnotatorAsyncClient: The constructed client. """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + return ImageAnnotatorClient.from_service_account_file.__func__( + ImageAnnotatorAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/client.py index bd2be3894228..0fbe93b97a20 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/client.py @@ -42,11 +42,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p4beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p4beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -61,9 +60,10 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p4beta1.types import image_annotator from .transports.base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport @@ -80,9 +80,7 @@ class ImageAnnotatorClientMeta(type): objects. """ - _transport_registry = ( - OrderedDict() - ) # type: Dict[str, Type[ImageAnnotatorTransport]] + _transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] _transport_registry["grpc"] = ImageAnnotatorGrpcTransport _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport _transport_registry["rest"] = ImageAnnotatorRestTransport @@ -650,11 +648,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ImageAnnotatorClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ImageAnnotatorClient._read_environment_variables() + ) self._client_cert_source = ImageAnnotatorClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -689,8 +685,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ImageAnnotatorTransport, transport) self._api_endpoint = self._transport.host diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py index 3534da170b88..7dc31f163a50 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py @@ -22,13 +22,12 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p4beta1 import gapic_version as package_version +from google.cloud.vision_v1p4beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p4beta1 import gapic_version as package_version -from google.cloud.vision_v1p4beta1.types import image_annotator - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ ) @@ -86,8 +85,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -102,11 +99,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py index 3a4e2ca1115e..2bdc92e3464e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py @@ -23,14 +23,13 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p4beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1p4beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport try: @@ -441,12 +440,12 @@ def async_batch_annotate_images( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_images" not in self._stubs: - self._stubs[ - "async_batch_annotate_images" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages", - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_images"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages", + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_images"] @@ -477,12 +476,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py index f78715e6006e..a1c672565bf8 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p4beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message @@ -32,8 +33,6 @@ from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1p4beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport from .grpc import ImageAnnotatorGrpcTransport @@ -450,12 +449,12 @@ def async_batch_annotate_images( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_images" not in self._stubs: - self._stubs[ - "async_batch_annotate_images" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages", - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_images"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages", + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_images"] @@ -487,12 +486,12 @@ def async_batch_annotate_files( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "async_batch_annotate_files" not in self._stubs: - self._stubs[ - "async_batch_annotate_files" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles", - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["async_batch_annotate_files"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles", + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["async_batch_annotate_files"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest.py index 7bf18d1c4973..8274aa60cb75 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest.py @@ -19,18 +19,17 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1p4beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore import google.protobuf from google.protobuf import json_format from requests import __version__ as requests_version -from google.cloud.vision_v1p4beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseImageAnnotatorRestTransport @@ -449,6 +448,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -494,9 +494,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateFiles._get_http_options() request, metadata = self._interceptor.pre_async_batch_annotate_files( request, metadata @@ -608,6 +606,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -652,9 +651,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateImages._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseAsyncBatchAnnotateImages._get_http_options() request, metadata = self._interceptor.pre_async_batch_annotate_images( request, metadata @@ -765,6 +762,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -805,9 +803,7 @@ def __call__( A list of file annotation responses. """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseBatchAnnotateFiles._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseBatchAnnotateFiles._get_http_options() request, metadata = self._interceptor.pre_batch_annotate_files( request, metadata @@ -921,6 +917,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -963,9 +960,7 @@ def __call__( """ - http_options = ( - _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() - ) + http_options = _BaseImageAnnotatorRestTransport._BaseBatchAnnotateImages._get_http_options() request, metadata = self._interceptor.pre_batch_annotate_images( request, metadata @@ -1070,7 +1065,9 @@ def async_batch_annotate_files( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AsyncBatchAnnotateFiles(self._session, self._host, self._interceptor) # type: ignore + return self._AsyncBatchAnnotateFiles( + self._session, self._host, self._interceptor + ) # type: ignore @property def async_batch_annotate_images( @@ -1080,7 +1077,9 @@ def async_batch_annotate_images( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AsyncBatchAnnotateImages(self._session, self._host, self._interceptor) # type: ignore + return self._AsyncBatchAnnotateImages( + self._session, self._host, self._interceptor + ) # type: ignore @property def batch_annotate_files( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest_base.py index 804a391713b9..d450843b5b5e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/rest_base.py @@ -18,11 +18,10 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template +from google.cloud.vision_v1p4beta1.types import image_annotator from google.longrunning import operations_pb2 # type: ignore from google.protobuf import json_format -from google.cloud.vision_v1p4beta1.types import image_annotator - from .base import DEFAULT_CLIENT_INFO, ImageAnnotatorTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/async_client.py index 25cfb5dfc83e..aaeb8a588a67 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/async_client.py @@ -34,25 +34,27 @@ from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p4beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p4beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p4beta1.services.product_search import pagers from google.cloud.vision_v1p4beta1.types import geometry, product_search_service +from google.protobuf import ( + empty_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore from .client import ProductSearchClient from .transports.base import DEFAULT_CLIENT_INFO, ProductSearchTransport @@ -72,22 +74,23 @@ class ProductSearchAsyncClient: """Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` """ _client: ProductSearchClient @@ -145,7 +148,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: ProductSearchAsyncClient: The constructed client. """ - return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, info, *args, **kwargs) # type: ignore + return ProductSearchClient.from_service_account_info.__func__( + ProductSearchAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -161,7 +166,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ProductSearchAsyncClient: The constructed client. """ - return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore + return ProductSearchClient.from_service_account_file.__func__( + ProductSearchAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file @@ -336,8 +343,8 @@ async def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. .. code-block:: python @@ -477,8 +484,8 @@ async def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. .. code-block:: python @@ -610,7 +617,7 @@ async def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -733,10 +740,10 @@ async def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. .. code-block:: python @@ -833,9 +840,9 @@ async def sample_update_product_set(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product_set.name", request.product_set.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), ) # Validate the universe domain. @@ -975,12 +982,12 @@ async def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. .. code-block:: python @@ -1115,8 +1122,8 @@ async def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python @@ -1246,7 +1253,7 @@ async def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. .. code-block:: python @@ -1367,14 +1374,14 @@ async def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. .. code-block:: python @@ -1468,9 +1475,9 @@ async def sample_update_product(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product.name", request.product.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), ) # Validate the universe domain. @@ -1621,14 +1628,14 @@ async def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. .. code-block:: python @@ -1884,9 +1891,9 @@ async def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. .. code-block:: python @@ -2019,7 +2026,7 @@ async def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. .. code-block:: python @@ -2143,8 +2150,8 @@ async def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. .. code-block:: python @@ -2389,8 +2396,8 @@ async def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/client.py index c34d87387b68..60d066a17fc1 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/client.py @@ -42,11 +42,10 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p4beta1 import gapic_version as package_version from google.oauth2 import service_account # type: ignore import google.protobuf -from google.cloud.vision_v1p4beta1 import gapic_version as package_version - try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -61,15 +60,18 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.cloud.vision_v1p4beta1.services.product_search import pagers from google.cloud.vision_v1p4beta1.types import geometry, product_search_service +from google.protobuf import ( + empty_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore from .transports.base import DEFAULT_CLIENT_INFO, ProductSearchTransport from .transports.grpc import ProductSearchGrpcTransport @@ -116,22 +118,23 @@ class ProductSearchClient(metaclass=ProductSearchClientMeta): """Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` """ @staticmethod @@ -692,11 +695,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = ProductSearchClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + ProductSearchClient._read_environment_variables() + ) self._client_cert_source = ProductSearchClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -731,8 +732,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(ProductSearchTransport, transport) self._api_endpoint = self._transport.host @@ -817,8 +817,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. .. code-block:: python @@ -955,8 +955,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. .. code-block:: python @@ -1085,7 +1085,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. .. code-block:: python @@ -1205,10 +1205,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. .. code-block:: python @@ -1302,9 +1302,9 @@ def sample_update_product_set(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product_set.name", request.product_set.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), ) # Validate the universe domain. @@ -1441,12 +1441,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. .. code-block:: python @@ -1578,8 +1578,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python @@ -1706,7 +1706,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. .. code-block:: python @@ -1824,14 +1824,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. .. code-block:: python @@ -1922,9 +1922,9 @@ def sample_update_product(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("product.name", request.product.name),) - ), + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), ) # Validate the universe domain. @@ -2072,14 +2072,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. .. code-block:: python @@ -2329,9 +2329,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. .. code-block:: python @@ -2461,7 +2461,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. .. code-block:: python @@ -2582,8 +2582,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. .. code-block:: python @@ -2826,8 +2826,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. .. code-block:: python diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/pagers.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/pagers.py index 8000978f3121..d6d1065fd30d 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/pagers.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -145,7 +145,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -227,7 +227,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -303,7 +303,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -383,7 +383,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -461,7 +461,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -543,7 +543,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -623,7 +623,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py index 64ce1bc97cbd..b697cd62f256 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py @@ -22,14 +22,13 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.vision_v1p4beta1 import gapic_version as package_version +from google.cloud.vision_v1p4beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore import google.protobuf from google.protobuf import empty_pb2 # type: ignore -from google.cloud.vision_v1p4beta1 import gapic_version as package_version -from google.cloud.vision_v1p4beta1.types import product_search_service - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ ) @@ -87,8 +86,6 @@ def __init__( be used for service account credentials. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -103,11 +100,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py index 452d930a604c..e7dfba14abf4 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py @@ -23,6 +23,7 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p4beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson @@ -30,8 +31,6 @@ import grpc # type: ignore import proto # type: ignore -from google.cloud.vision_v1p4beta1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport try: @@ -115,22 +114,23 @@ class ProductSearchGrpcTransport(ProductSearchTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -371,8 +371,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. Returns: Callable[[~.CreateProductSetRequest], @@ -405,8 +405,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. Returns: Callable[[~.ListProductSetsRequest], @@ -438,7 +438,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.GetProductSetRequest], @@ -472,10 +472,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. Returns: Callable[[~.UpdateProductSetRequest], @@ -537,12 +537,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. Returns: Callable[[~.CreateProductRequest], @@ -575,8 +575,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsRequest], @@ -608,7 +608,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. Returns: Callable[[~.GetProductRequest], @@ -644,14 +644,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. Returns: Callable[[~.UpdateProductRequest], @@ -725,14 +725,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. Returns: Callable[[~.CreateReferenceImageRequest], @@ -800,9 +800,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. Returns: Callable[[~.ListReferenceImagesRequest], @@ -835,7 +835,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. Returns: Callable[[~.GetReferenceImageRequest], @@ -870,8 +870,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. Returns: Callable[[~.AddProductToProductSetRequest], @@ -884,12 +884,12 @@ def add_product_to_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_product_to_product_set" not in self._stubs: - self._stubs[ - "add_product_to_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet", - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["add_product_to_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet", + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["add_product_to_product_set"] @@ -915,12 +915,12 @@ def remove_product_from_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_product_from_product_set" not in self._stubs: - self._stubs[ - "remove_product_from_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet", - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["remove_product_from_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet", + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["remove_product_from_product_set"] @@ -939,8 +939,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsInProductSetRequest], @@ -953,12 +953,12 @@ def list_products_in_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_products_in_product_set" not in self._stubs: - self._stubs[ - "list_products_in_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet", - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + self._stubs["list_products_in_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet", + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) ) return self._stubs["list_products_in_product_set"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py index 16ae1eac3171..b7382ad9644c 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.vision_v1p4beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson @@ -33,8 +34,6 @@ from grpc.experimental import aio # type: ignore import proto # type: ignore -from google.cloud.vision_v1p4beta1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport from .grpc import ProductSearchGrpcTransport @@ -121,22 +120,23 @@ class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -379,8 +379,8 @@ def create_product_set( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. Returns: Callable[[~.CreateProductSetRequest], @@ -413,8 +413,8 @@ def list_product_sets( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. Returns: Callable[[~.ListProductSetsRequest], @@ -447,7 +447,7 @@ def get_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. + - Returns NOT_FOUND if the ProductSet does not exist. Returns: Callable[[~.GetProductSetRequest], @@ -481,10 +481,10 @@ def update_product_set( Possible errors: - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. Returns: Callable[[~.UpdateProductSetRequest], @@ -549,12 +549,12 @@ def create_product( Possible errors: - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. Returns: Callable[[~.CreateProductRequest], @@ -587,8 +587,8 @@ def list_products( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsRequest], @@ -621,7 +621,7 @@ def get_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. + - Returns NOT_FOUND if the Product does not exist. Returns: Callable[[~.GetProductRequest], @@ -658,14 +658,14 @@ def update_product( Possible errors: - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. Returns: Callable[[~.UpdateProductRequest], @@ -741,14 +741,14 @@ def create_reference_image( Possible errors: - - Returns INVALID_ARGUMENT if the image_uri is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, and - nothing compatible with the parent product's product_category - is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. Returns: Callable[[~.CreateReferenceImageRequest], @@ -816,9 +816,9 @@ def list_reference_images( Possible errors: - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than 100, - or less than 1. + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. Returns: Callable[[~.ListReferenceImagesRequest], @@ -851,7 +851,7 @@ def get_reference_image( Possible errors: - - Returns NOT_FOUND if the specified image does not exist. + - Returns NOT_FOUND if the specified image does not exist. Returns: Callable[[~.GetReferenceImageRequest], @@ -887,8 +887,8 @@ def add_product_to_product_set( Possible errors: - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. Returns: Callable[[~.AddProductToProductSetRequest], @@ -901,12 +901,12 @@ def add_product_to_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_product_to_product_set" not in self._stubs: - self._stubs[ - "add_product_to_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet", - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["add_product_to_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet", + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["add_product_to_product_set"] @@ -933,12 +933,12 @@ def remove_product_from_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_product_from_product_set" not in self._stubs: - self._stubs[ - "remove_product_from_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet", - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, + self._stubs["remove_product_from_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet", + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) ) return self._stubs["remove_product_from_product_set"] @@ -957,8 +957,8 @@ def list_products_in_product_set( Possible errors: - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. Returns: Callable[[~.ListProductsInProductSetRequest], @@ -971,12 +971,12 @@ def list_products_in_product_set( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_products_in_product_set" not in self._stubs: - self._stubs[ - "list_products_in_product_set" - ] = self._logged_channel.unary_unary( - "/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet", - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + self._stubs["list_products_in_product_set"] = ( + self._logged_channel.unary_unary( + "/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet", + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) ) return self._stubs["list_products_in_product_set"] diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest.py index af54bbc62247..3da338ce5069 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest.py @@ -19,19 +19,20 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.cloud.vision_v1p4beta1.types import product_search_service from google.longrunning import operations_pb2 # type: ignore import google.protobuf -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from requests import __version__ as requests_version -from google.cloud.vision_v1p4beta1.types import product_search_service - from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO from .rest_base import _BaseProductSearchRestTransport @@ -1009,22 +1010,23 @@ class ProductSearchRestTransport(_BaseProductSearchRestTransport): Manages Products and ProductSets of reference images for use in product search. It uses the following resource model: - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit identification. + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. In parallel, - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -1146,6 +1148,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1183,9 +1186,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseAddProductToProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseAddProductToProductSet._get_http_options() request, metadata = self._interceptor.pre_add_product_to_product_set( request, metadata @@ -1262,6 +1263,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1412,6 +1414,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1456,9 +1459,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseCreateProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseCreateProductSet._get_http_options() request, metadata = self._interceptor.pre_create_product_set( request, metadata @@ -1571,6 +1572,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1612,9 +1614,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseCreateReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseCreateReferenceImage._get_http_options() request, metadata = self._interceptor.pre_create_reference_image( request, metadata @@ -1727,6 +1727,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1833,6 +1834,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1867,9 +1869,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseDeleteProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseDeleteProductSet._get_http_options() request, metadata = self._interceptor.pre_delete_product_set( request, metadata @@ -1941,6 +1941,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -1975,9 +1976,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseDeleteReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseDeleteReferenceImage._get_http_options() request, metadata = self._interceptor.pre_delete_reference_image( request, metadata @@ -2049,6 +2048,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2197,6 +2197,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2348,6 +2349,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2388,9 +2390,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseGetReferenceImage._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseGetReferenceImage._get_http_options() request, metadata = self._interceptor.pre_get_reference_image( request, metadata @@ -2498,6 +2498,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2540,9 +2541,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseImportProductSets._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseImportProductSets._get_http_options() request, metadata = self._interceptor.pre_import_product_sets( request, metadata @@ -2651,6 +2650,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2797,6 +2797,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2946,6 +2947,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -2988,9 +2990,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseListProductsInProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseListProductsInProductSet._get_http_options() request, metadata = self._interceptor.pre_list_products_in_product_set( request, metadata @@ -3102,6 +3102,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3140,9 +3141,7 @@ def __call__( Response message for the ``ListReferenceImages`` method. """ - http_options = ( - _BaseProductSearchRestTransport._BaseListReferenceImages._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseListReferenceImages._get_http_options() request, metadata = self._interceptor.pre_list_reference_images( request, metadata @@ -3252,6 +3251,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3404,6 +3404,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3441,9 +3442,7 @@ def __call__( be of type `bytes`. """ - http_options = ( - _BaseProductSearchRestTransport._BaseRemoveProductFromProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseRemoveProductFromProductSet._get_http_options() request, metadata = self._interceptor.pre_remove_product_from_product_set( request, metadata @@ -3522,6 +3521,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3672,6 +3672,7 @@ def _get_response( transcoded_request, body=None, ): + uri = transcoded_request["uri"] method = transcoded_request["method"] headers = dict(metadata) @@ -3716,9 +3717,7 @@ def __call__( """ - http_options = ( - _BaseProductSearchRestTransport._BaseUpdateProductSet._get_http_options() - ) + http_options = _BaseProductSearchRestTransport._BaseUpdateProductSet._get_http_options() request, metadata = self._interceptor.pre_update_product_set( request, metadata @@ -3823,7 +3822,9 @@ def add_product_to_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AddProductToProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._AddProductToProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def create_product( @@ -3955,7 +3956,9 @@ def list_products_in_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._ListProductsInProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._ListProductsInProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def list_reference_images( @@ -3986,7 +3989,9 @@ def remove_product_from_product_set( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._RemoveProductFromProductSet(self._session, self._host, self._interceptor) # type: ignore + return self._RemoveProductFromProductSet( + self._session, self._host, self._interceptor + ) # type: ignore @property def update_product( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest_base.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest_base.py index 81775562e533..4c22d16d951e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest_base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/rest_base.py @@ -18,11 +18,12 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1, path_template -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format - from google.cloud.vision_v1p4beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from .base import DEFAULT_CLIENT_INFO, ProductSearchTransport diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/__init__.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/__init__.py index fd13455ce39b..bda072655d51 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/__init__.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/__init__.py @@ -13,8 +13,17 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .face import Celebrity, FaceRecognitionParams, FaceRecognitionResult -from .geometry import BoundingPoly, NormalizedVertex, Position, Vertex +from .face import ( + Celebrity, + FaceRecognitionParams, + FaceRecognitionResult, +) +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Position, + Vertex, +) from .image_annotator import ( AnnotateFileRequest, AnnotateFileResponse, @@ -57,7 +66,10 @@ TextDetectionParams, WebDetectionParams, ) -from .product_search import ProductSearchParams, ProductSearchResults +from .product_search import ( + ProductSearchParams, + ProductSearchResults, +) from .product_search_service import ( AddProductToProductSetRequest, BatchOperationMetadata, @@ -91,8 +103,17 @@ UpdateProductRequest, UpdateProductSetRequest, ) -from .text_annotation import Block, Page, Paragraph, Symbol, TextAnnotation, Word -from .web_detection import WebDetection +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) __all__ = ( "Celebrity", diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/image_annotator.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/image_annotator.py index a0a0cf215916..99da67beca01 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/image_annotator.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/image_annotator.py @@ -17,12 +17,6 @@ from typing import MutableMapping, MutableSequence -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import latlng_pb2 # type: ignore -import proto # type: ignore - from google.cloud.vision_v1p4beta1.types import ( face, geometry, @@ -30,6 +24,13 @@ text_annotation, ) from google.cloud.vision_v1p4beta1.types import web_detection as gcv_web_detection +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from google.type import ( + color_pb2, # type: ignore + latlng_pb2, # type: ignore +) +import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.vision.v1p4beta1", @@ -96,6 +97,7 @@ class Likelihood(proto.Enum): VERY_LIKELY (5): It is very likely. """ + UNKNOWN = 0 VERY_UNLIKELY = 1 UNLIKELY = 2 @@ -162,6 +164,7 @@ class Type(proto.Enum): OBJECT_LOCALIZATION (19): Run localizer for object detection. """ + TYPE_UNSPECIFIED = 0 FACE_DETECTION = 1 LANDMARK_DETECTION = 2 @@ -416,6 +419,7 @@ class Type(proto.Enum): CHIN_RIGHT_GONION (34): Chin right gonion. """ + UNKNOWN_LANDMARK = 0 LEFT_EYE = 1 RIGHT_EYE = 2 @@ -533,12 +537,12 @@ class Type(proto.Enum): number=15, enum="Likelihood", ) - recognition_result: MutableSequence[ - face.FaceRecognitionResult - ] = proto.RepeatedField( - proto.MESSAGE, - number=16, - message=face.FaceRecognitionResult, + recognition_result: MutableSequence[face.FaceRecognitionResult] = ( + proto.RepeatedField( + proto.MESSAGE, + number=16, + message=face.FaceRecognitionResult, + ) ) @@ -1152,12 +1156,12 @@ class AnnotateImageResponse(proto.Message): number=4, message="EntityAnnotation", ) - localized_object_annotations: MutableSequence[ - "LocalizedObjectAnnotation" - ] = proto.RepeatedField( - proto.MESSAGE, - number=22, - message="LocalizedObjectAnnotation", + localized_object_annotations: MutableSequence["LocalizedObjectAnnotation"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=22, + message="LocalizedObjectAnnotation", + ) ) text_annotations: MutableSequence["EntityAnnotation"] = proto.RepeatedField( proto.MESSAGE, @@ -1599,16 +1603,16 @@ class GcsDestination(proto.Message): Examples: - - File Prefix: gs://bucket-name/here/filenameprefix The - output files will be created in gs://bucket-name/here/ and - the names of the output files will begin with - "filenameprefix". + - File Prefix: gs://bucket-name/here/filenameprefix The + output files will be created in gs://bucket-name/here/ + and the names of the output files will begin with + "filenameprefix". - - Directory Prefix: gs://bucket-name/some/location/ The - output files will be created in - gs://bucket-name/some/location/ and the names of the - output files could be anything because there was no - filename prefix specified. + - Directory Prefix: gs://bucket-name/some/location/ The + output files will be created in + gs://bucket-name/some/location/ and the names of the + output files could be anything because there was no + filename prefix specified. If multiple outputs, each response is still AnnotateFileResponse, each of which contains some subset of @@ -1651,6 +1655,7 @@ class State(proto.Enum): CANCELLED (4): The batch processing was cancelled. """ + STATE_UNSPECIFIED = 0 CREATED = 1 RUNNING = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search.py index 1d5fb1d412b1..0767a7ed9db2 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search.py @@ -17,11 +17,10 @@ from typing import MutableMapping, MutableSequence +from google.cloud.vision_v1p4beta1.types import geometry, product_search_service from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore -from google.cloud.vision_v1p4beta1.types import geometry, product_search_service - __protobuf__ = proto.module( package="google.cloud.vision.v1p4beta1", manifest={ @@ -199,12 +198,12 @@ class GroupedResult(proto.Message): number=2, message="ProductSearchResults.Result", ) - object_annotations: MutableSequence[ - "ProductSearchResults.ObjectAnnotation" - ] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message="ProductSearchResults.ObjectAnnotation", + object_annotations: MutableSequence["ProductSearchResults.ObjectAnnotation"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=3, + message="ProductSearchResults.ObjectAnnotation", + ) ) index_time: timestamp_pb2.Timestamp = proto.Field( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py index e2d1875066cc..e308f576527f 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py @@ -17,13 +17,14 @@ from typing import MutableMapping, MutableSequence -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +from google.cloud.vision_v1p4beta1.types import geometry +from google.protobuf import ( + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import status_pb2 # type: ignore import proto # type: ignore -from google.cloud.vision_v1p4beta1.types import geometry - __protobuf__ = proto.module( package="google.cloud.vision.v1p4beta1", manifest={ @@ -1021,6 +1022,7 @@ class State(proto.Enum): processed before the cancel command are output as specified in the request. """ + STATE_UNSPECIFIED = 0 PROCESSING = 1 SUCCESSFUL = 2 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/text_annotation.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/text_annotation.py index 8ff74951cbad..a49d2e7319f2 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/text_annotation.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/text_annotation.py @@ -17,9 +17,8 @@ from typing import MutableMapping, MutableSequence -import proto # type: ignore - from google.cloud.vision_v1p4beta1.types import geometry +import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.vision.v1p4beta1", @@ -101,6 +100,7 @@ class BreakType(proto.Enum): LINE_BREAK (5): Line break that ends a paragraph. """ + UNKNOWN = 0 SPACE = 1 SURE_SPACE = 2 @@ -129,12 +129,12 @@ class TextProperty(proto.Message): Detected start or end of a text segment. """ - detected_languages: MutableSequence[ - "TextAnnotation.DetectedLanguage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message="TextAnnotation.DetectedLanguage", + detected_languages: MutableSequence["TextAnnotation.DetectedLanguage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=1, + message="TextAnnotation.DetectedLanguage", + ) ) detected_break: "TextAnnotation.DetectedBreak" = proto.Field( proto.MESSAGE, @@ -210,24 +210,24 @@ class Block(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: + - when the text is horizontal it might look like: - :: + :: - 0----1 - | | - 3----2 + 0----1 + | | + 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: + - when it's rotated 180 degrees around the top-left corner + it becomes: - :: + :: - 2----3 - | | - 1----0 + 2----3 + | | + 1----0 - and the vertex order will still be (0, 1, 2, 3). + and the vertex order will still be (0, 1, 2, 3). paragraphs (MutableSequence[google.cloud.vision_v1p4beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). @@ -255,6 +255,7 @@ class BlockType(proto.Enum): BARCODE (5): Barcode block. """ + UNKNOWN = 0 TEXT = 1 TABLE = 2 @@ -303,11 +304,11 @@ class Paragraph(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). words (MutableSequence[google.cloud.vision_v1p4beta1.types.Word]): List of all words in this paragraph. confidence (float): @@ -349,11 +350,11 @@ class Word(proto.Message): represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). symbols (MutableSequence[google.cloud.vision_v1p4beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural @@ -397,11 +398,11 @@ class Symbol(proto.Message): is represented as around the top-left corner as defined when the text is read in the 'natural' orientation. For example: - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). text (str): The actual UTF-8 representation of the symbol. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/web_detection.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/web_detection.py index 3bfadec02406..e56d463dad92 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/web_detection.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/web_detection.py @@ -137,19 +137,19 @@ class WebPage(proto.Message): proto.STRING, number=3, ) - full_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message="WebDetection.WebImage", + full_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=4, + message="WebDetection.WebImage", + ) ) - partial_matching_images: MutableSequence[ - "WebDetection.WebImage" - ] = proto.RepeatedField( - proto.MESSAGE, - number=5, - message="WebDetection.WebImage", + partial_matching_images: MutableSequence["WebDetection.WebImage"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=5, + message="WebDetection.WebImage", + ) ) class WebLabel(proto.Message): diff --git a/packages/google-cloud-vision/mypy.ini b/packages/google-cloud-vision/mypy.ini index 574c5aed394b..a3cb5c292172 100644 --- a/packages/google-cloud-vision/mypy.ini +++ b/packages/google-cloud-vision/mypy.ini @@ -1,3 +1,3 @@ [mypy] -python_version = 3.7 +python_version = 3.14 namespace_packages = True diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py index 9c169e69edaf..e8924ad9c02b 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py @@ -44,31 +44,30 @@ HAS_GOOGLE_AUTH_AIO = False from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.type import latlng_pb2 # type: ignore - from google.cloud.vision_v1.services.image_annotator import ( ImageAnnotatorAsyncClient, ImageAnnotatorClient, transports, ) from google.cloud.vision_v1.types import geometry, image_annotator, product_search +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.type import latlng_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -955,10 +954,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1003,10 +1001,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1042,10 +1039,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1288,13 +1284,13 @@ def test_image_annotator_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1408,9 +1404,9 @@ def test_batch_annotate_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -1703,9 +1699,9 @@ def test_batch_annotate_files_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_files - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_files] = ( + mock_rpc + ) request = {} client.batch_annotate_files(request) @@ -2592,9 +2588,9 @@ def test_batch_annotate_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -2776,9 +2772,9 @@ def test_batch_annotate_files_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_files - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_files] = ( + mock_rpc + ) request = {} client.batch_annotate_files(request) @@ -3062,12 +3058,10 @@ def test_async_batch_annotate_images_rest_unset_required_fields(): unset_fields = transport.async_batch_annotate_images._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "requests", - "outputConfig", - ) - ) + & set(( + "requests", + "outputConfig", + )) ) @@ -3665,8 +3659,9 @@ def test_batch_annotate_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3726,18 +3721,20 @@ def test_batch_annotate_images_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_batch_annotate_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_batch_annotate_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3795,8 +3792,9 @@ def test_batch_annotate_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3856,18 +3854,20 @@ def test_batch_annotate_files_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_files" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_batch_annotate_files_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_files" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_batch_annotate_files_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3925,8 +3925,9 @@ def test_async_batch_annotate_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3983,20 +3984,21 @@ def test_async_batch_annotate_images_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_images" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_async_batch_annotate_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_images" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_async_batch_annotate_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4049,8 +4051,9 @@ def test_async_batch_annotate_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4107,20 +4110,21 @@ def test_async_batch_annotate_files_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_async_batch_annotate_files_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_async_batch_annotate_files_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4175,8 +4179,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4398,11 +4403,14 @@ def test_image_annotator_base_transport(): def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport( @@ -4422,9 +4430,12 @@ def test_image_annotator_base_transport_with_credentials_file(): def test_image_annotator_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport() @@ -4502,11 +4513,12 @@ def test_image_annotator_transport_auth_gdch_credentials(transport_class): def test_image_annotator_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.py index c7be6a7ce441..54e3f35b36fc 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.py @@ -44,29 +44,21 @@ HAS_GOOGLE_AUTH_AIO = False from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - from google.cloud.vision_v1.services.product_search import ( ProductSearchAsyncClient, ProductSearchClient, @@ -74,6 +66,15 @@ transports, ) from google.cloud.vision_v1.types import geometry, product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.protobuf import ( + any_pb2, # type: ignore + empty_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -956,10 +957,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1004,10 +1004,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1043,10 +1042,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1289,13 +1287,13 @@ def test_product_search_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1415,9 +1413,9 @@ def test_create_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_product_set] = ( + mock_rpc + ) request = {} client.create_product_set(request) @@ -1779,9 +1777,9 @@ def test_list_product_sets_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_product_sets] = ( + mock_rpc + ) request = {} client.list_product_sets(request) @@ -2649,9 +2647,9 @@ def test_update_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_product_set] = ( + mock_rpc + ) request = {} client.update_product_set(request) @@ -3000,9 +2998,9 @@ def test_delete_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_product_set] = ( + mock_rpc + ) request = {} client.delete_product_set(request) @@ -5206,9 +5204,9 @@ def test_create_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_reference_image] = ( + mock_rpc + ) request = {} client.create_reference_image(request) @@ -5568,9 +5566,9 @@ def test_delete_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_reference_image] = ( + mock_rpc + ) request = {} client.delete_reference_image(request) @@ -5906,9 +5904,9 @@ def test_list_reference_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_reference_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_reference_images] = ( + mock_rpc + ) request = {} client.list_reference_images(request) @@ -6458,9 +6456,9 @@ def test_get_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_reference_image] = ( + mock_rpc + ) request = {} client.get_reference_image(request) @@ -8034,9 +8032,9 @@ def test_import_product_sets_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.import_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.import_product_sets] = ( + mock_rpc + ) request = {} client.import_product_sets(request) @@ -8677,9 +8675,9 @@ def test_create_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_product_set] = ( + mock_rpc + ) request = {} client.create_product_set(request) @@ -8780,12 +8778,10 @@ def test_create_product_set_rest_unset_required_fields(): unset_fields = transport.create_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( set(("productSetId",)) - & set( - ( - "parent", - "productSet", - ) - ) + & set(( + "parent", + "productSet", + )) ) @@ -8872,9 +8868,9 @@ def test_list_product_sets_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_product_sets] = ( + mock_rpc + ) request = {} client.list_product_sets(request) @@ -8917,12 +8913,10 @@ def test_list_product_sets_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_product_sets._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -8980,12 +8974,10 @@ def test_list_product_sets_rest_unset_required_fields(): unset_fields = transport.list_product_sets._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -9314,9 +9306,9 @@ def test_update_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_product_set] = ( + mock_rpc + ) request = {} client.update_product_set(request) @@ -9500,9 +9492,9 @@ def test_delete_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_product_set] = ( + mock_rpc + ) request = {} client.delete_product_set(request) @@ -9778,12 +9770,10 @@ def test_create_product_rest_unset_required_fields(): unset_fields = transport.create_product._get_unset_required_fields({}) assert set(unset_fields) == ( set(("productId",)) - & set( - ( - "parent", - "product", - ) - ) + & set(( + "parent", + "product", + )) ) @@ -9912,12 +9902,10 @@ def test_list_products_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_products._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -9973,12 +9961,10 @@ def test_list_products_rest_unset_required_fields(): unset_fields = transport.list_products._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -10656,9 +10642,9 @@ def test_create_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_reference_image] = ( + mock_rpc + ) request = {} client.create_reference_image(request) @@ -10759,12 +10745,10 @@ def test_create_reference_image_rest_unset_required_fields(): unset_fields = transport.create_reference_image._get_unset_required_fields({}) assert set(unset_fields) == ( set(("referenceImageId",)) - & set( - ( - "parent", - "referenceImage", - ) - ) + & set(( + "parent", + "referenceImage", + )) ) @@ -10856,9 +10840,9 @@ def test_delete_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_reference_image] = ( + mock_rpc + ) request = {} client.delete_reference_image(request) @@ -11036,9 +11020,9 @@ def test_list_reference_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_reference_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_reference_images] = ( + mock_rpc + ) request = {} client.list_reference_images(request) @@ -11081,12 +11065,10 @@ def test_list_reference_images_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_reference_images._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -11144,12 +11126,10 @@ def test_list_reference_images_rest_unset_required_fields(): unset_fields = transport.list_reference_images._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -11307,9 +11287,9 @@ def test_get_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_reference_image] = ( + mock_rpc + ) request = {} client.get_reference_image(request) @@ -11594,12 +11574,10 @@ def test_add_product_to_product_set_rest_unset_required_fields(): unset_fields = transport.add_product_to_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "name", - "product", - ) - ) + & set(( + "name", + "product", + )) ) @@ -11786,17 +11764,15 @@ def test_remove_product_from_product_set_rest_unset_required_fields(): credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.remove_product_from_product_set._get_unset_required_fields( - {} + unset_fields = ( + transport.remove_product_from_product_set._get_unset_required_fields({}) ) assert set(unset_fields) == ( set(()) - & set( - ( - "name", - "product", - ) - ) + & set(( + "name", + "product", + )) ) @@ -11929,12 +11905,10 @@ def test_list_products_in_product_set_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_products_in_product_set._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -11992,12 +11966,10 @@ def test_list_products_in_product_set_rest_unset_required_fields(): unset_fields = transport.list_products_in_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("name",)) ) @@ -12153,9 +12125,9 @@ def test_import_product_sets_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.import_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.import_product_sets] = ( + mock_rpc + ) request = {} client.import_product_sets(request) @@ -12255,12 +12227,10 @@ def test_import_product_sets_rest_unset_required_fields(): unset_fields = transport.import_product_sets._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "parent", - "inputConfig", - ) - ) + & set(( + "parent", + "inputConfig", + )) ) @@ -13597,8 +13567,9 @@ def test_create_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13689,13 +13660,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -13747,17 +13716,20 @@ def test_create_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_create_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13812,8 +13784,9 @@ def test_list_product_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13876,17 +13849,20 @@ def test_list_product_sets_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_product_sets" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_product_sets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_product_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_product_sets" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_product_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_product_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13944,8 +13920,9 @@ def test_get_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14010,17 +13987,20 @@ def test_get_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_get_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14079,8 +14059,9 @@ def test_update_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14175,13 +14156,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -14233,17 +14212,20 @@ def test_update_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_update_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_update_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_update_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14298,8 +14280,9 @@ def test_delete_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14356,13 +14339,13 @@ def test_delete_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_product_set" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteProductSetRequest.pb( product_search_service.DeleteProductSetRequest() @@ -14407,8 +14390,9 @@ def test_create_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14489,13 +14473,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -14551,17 +14533,19 @@ def test_create_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14616,8 +14600,9 @@ def test_list_products_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14680,17 +14665,19 @@ def test_list_products_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_products" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_products" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14748,8 +14735,9 @@ def test_get_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14818,17 +14806,19 @@ def test_get_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14885,8 +14875,9 @@ def test_update_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14969,13 +14960,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -15031,17 +15020,19 @@ def test_update_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_update_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_update_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15096,8 +15087,9 @@ def test_delete_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15154,13 +15146,13 @@ def test_delete_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_product" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteProductRequest.pb( product_search_service.DeleteProductRequest() @@ -15205,8 +15197,9 @@ def test_create_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15292,13 +15285,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -15350,18 +15341,20 @@ def test_create_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_reference_image" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_create_reference_image_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_reference_image" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_create_reference_image_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_reference_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15421,8 +15414,9 @@ def test_delete_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15481,13 +15475,13 @@ def test_delete_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_reference_image" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteReferenceImageRequest.pb( product_search_service.DeleteReferenceImageRequest() @@ -15532,8 +15526,9 @@ def test_list_reference_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15600,18 +15595,20 @@ def test_list_reference_images_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_reference_images" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_list_reference_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_reference_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_reference_images" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_reference_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_reference_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15671,8 +15668,9 @@ def test_get_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15739,18 +15737,20 @@ def test_get_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_reference_image" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_get_reference_image_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_reference_image" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_get_reference_image_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_reference_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15808,8 +15808,9 @@ def test_add_product_to_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15866,13 +15867,13 @@ def test_add_product_to_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_add_product_to_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_add_product_to_product_set" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.AddProductToProductSetRequest.pb( product_search_service.AddProductToProductSetRequest() @@ -15917,8 +15918,9 @@ def test_remove_product_from_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15975,13 +15977,14 @@ def test_remove_product_from_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_remove_product_from_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "pre_remove_product_from_product_set", + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.RemoveProductFromProductSetRequest.pb( product_search_service.RemoveProductFromProductSetRequest() @@ -16026,8 +16029,9 @@ def test_list_products_in_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16092,18 +16096,20 @@ def test_list_products_in_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products_in_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_list_products_in_product_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_products_in_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products_in_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_products_in_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_products_in_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16161,8 +16167,9 @@ def test_import_product_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16219,20 +16226,21 @@ def test_import_product_sets_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProductSearchRestInterceptor, "post_import_product_sets" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_import_product_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_import_product_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_import_product_sets" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_import_product_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_import_product_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16285,8 +16293,9 @@ def test_purge_products_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16343,19 +16352,20 @@ def test_purge_products_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProductSearchRestInterceptor, "post_purge_products" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_purge_products_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_purge_products" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_purge_products" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_purge_products_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_purge_products" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16410,8 +16420,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16964,11 +16975,14 @@ def test_product_search_base_transport(): def test_product_search_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductSearchTransport( @@ -16988,9 +17002,12 @@ def test_product_search_base_transport_with_credentials_file(): def test_product_search_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductSearchTransport() @@ -17068,11 +17085,12 @@ def test_product_search_transport_auth_gdch_credentials(transport_class): def test_product_search_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py index c9ce8ca8bddf..6ea4fa37bb1a 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py @@ -43,22 +43,26 @@ except ImportError: # pragma: NO COVER HAS_GOOGLE_AUTH_AIO = False -from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import ( + client_options, + gapic_v1, + grpc_helpers, + grpc_helpers_async, + path_template, +) from google.api_core import exceptions as core_exceptions from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.oauth2 import service_account -from google.type import latlng_pb2 # type: ignore - from google.cloud.vision_v1p1beta1.services.image_annotator import ( ImageAnnotatorAsyncClient, ImageAnnotatorClient, transports, ) from google.cloud.vision_v1p1beta1.types import image_annotator +from google.oauth2 import service_account +from google.type import latlng_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -945,10 +949,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -993,10 +996,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1032,10 +1034,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1278,13 +1279,13 @@ def test_image_annotator_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1394,9 +1395,9 @@ def test_batch_annotate_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -1625,9 +1626,9 @@ def test_batch_annotate_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -1974,8 +1975,9 @@ def test_batch_annotate_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2035,18 +2037,20 @@ def test_batch_annotate_images_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_batch_annotate_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_batch_annotate_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2173,11 +2177,14 @@ def test_image_annotator_base_transport(): def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport( @@ -2197,9 +2204,12 @@ def test_image_annotator_base_transport_with_credentials_file(): def test_image_annotator_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport() @@ -2277,11 +2287,12 @@ def test_image_annotator_transport_auth_gdch_credentials(transport_class): def test_image_annotator_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py index 3f12d6920955..fa034915efd9 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py @@ -45,31 +45,30 @@ HAS_GOOGLE_AUTH_AIO = False from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.type import latlng_pb2 # type: ignore - from google.cloud.vision_v1p2beta1.services.image_annotator import ( ImageAnnotatorAsyncClient, ImageAnnotatorClient, transports, ) from google.cloud.vision_v1p2beta1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.type import latlng_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -956,10 +955,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1004,10 +1002,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1043,10 +1040,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1289,13 +1285,13 @@ def test_image_annotator_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1405,9 +1401,9 @@ def test_batch_annotate_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -1950,9 +1946,9 @@ def test_batch_annotate_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -2537,8 +2533,9 @@ def test_batch_annotate_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2598,18 +2595,20 @@ def test_batch_annotate_images_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_batch_annotate_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_batch_annotate_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2667,8 +2666,9 @@ def test_async_batch_annotate_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2725,20 +2725,21 @@ def test_async_batch_annotate_files_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_async_batch_annotate_files_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_async_batch_annotate_files_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2907,11 +2908,14 @@ def test_image_annotator_base_transport(): def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport( @@ -2931,9 +2935,12 @@ def test_image_annotator_base_transport_with_credentials_file(): def test_image_annotator_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport() @@ -3011,11 +3018,12 @@ def test_image_annotator_transport_auth_gdch_credentials(transport_class): def test_image_annotator_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py index dbb2d9cb8abb..d32da9ee1d1a 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py @@ -44,25 +44,21 @@ HAS_GOOGLE_AUTH_AIO = False from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.type import latlng_pb2 # type: ignore - from google.cloud.vision_v1p3beta1.services.image_annotator import ( ImageAnnotatorAsyncClient, ImageAnnotatorClient, @@ -73,6 +69,9 @@ image_annotator, product_search, ) +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.type import latlng_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -959,10 +958,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1007,10 +1005,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1046,10 +1043,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1292,13 +1288,13 @@ def test_image_annotator_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1408,9 +1404,9 @@ def test_batch_annotate_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -1953,9 +1949,9 @@ def test_batch_annotate_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -2540,8 +2536,9 @@ def test_batch_annotate_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2601,18 +2598,20 @@ def test_batch_annotate_images_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_batch_annotate_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_batch_annotate_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2670,8 +2669,9 @@ def test_async_batch_annotate_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2728,20 +2728,21 @@ def test_async_batch_annotate_files_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_async_batch_annotate_files_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_async_batch_annotate_files_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2910,11 +2911,14 @@ def test_image_annotator_base_transport(): def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport( @@ -2934,9 +2938,12 @@ def test_image_annotator_base_transport_with_credentials_file(): def test_image_annotator_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport() @@ -3014,11 +3021,12 @@ def test_image_annotator_transport_auth_gdch_credentials(transport_class): def test_image_annotator_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py index a5f93c48545b..bc315c675b62 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py @@ -44,28 +44,21 @@ HAS_GOOGLE_AUTH_AIO = False from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - from google.cloud.vision_v1p3beta1.services.product_search import ( ProductSearchAsyncClient, ProductSearchClient, @@ -73,6 +66,14 @@ transports, ) from google.cloud.vision_v1p3beta1.types import geometry, product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.protobuf import ( + any_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -955,10 +956,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1003,10 +1003,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1042,10 +1041,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1288,13 +1286,13 @@ def test_product_search_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1414,9 +1412,9 @@ def test_create_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_product_set] = ( + mock_rpc + ) request = {} client.create_product_set(request) @@ -1778,9 +1776,9 @@ def test_list_product_sets_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_product_sets] = ( + mock_rpc + ) request = {} client.list_product_sets(request) @@ -2648,9 +2646,9 @@ def test_update_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_product_set] = ( + mock_rpc + ) request = {} client.update_product_set(request) @@ -2999,9 +2997,9 @@ def test_delete_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_product_set] = ( + mock_rpc + ) request = {} client.delete_product_set(request) @@ -5205,9 +5203,9 @@ def test_create_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_reference_image] = ( + mock_rpc + ) request = {} client.create_reference_image(request) @@ -5567,9 +5565,9 @@ def test_delete_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_reference_image] = ( + mock_rpc + ) request = {} client.delete_reference_image(request) @@ -5905,9 +5903,9 @@ def test_list_reference_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_reference_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_reference_images] = ( + mock_rpc + ) request = {} client.list_reference_images(request) @@ -6457,9 +6455,9 @@ def test_get_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_reference_image] = ( + mock_rpc + ) request = {} client.get_reference_image(request) @@ -8033,9 +8031,9 @@ def test_import_product_sets_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.import_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.import_product_sets] = ( + mock_rpc + ) request = {} client.import_product_sets(request) @@ -8348,9 +8346,9 @@ def test_create_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_product_set] = ( + mock_rpc + ) request = {} client.create_product_set(request) @@ -8451,12 +8449,10 @@ def test_create_product_set_rest_unset_required_fields(): unset_fields = transport.create_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( set(("productSetId",)) - & set( - ( - "parent", - "productSet", - ) - ) + & set(( + "parent", + "productSet", + )) ) @@ -8543,9 +8539,9 @@ def test_list_product_sets_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_product_sets] = ( + mock_rpc + ) request = {} client.list_product_sets(request) @@ -8588,12 +8584,10 @@ def test_list_product_sets_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_product_sets._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -8651,12 +8645,10 @@ def test_list_product_sets_rest_unset_required_fields(): unset_fields = transport.list_product_sets._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -8985,9 +8977,9 @@ def test_update_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_product_set] = ( + mock_rpc + ) request = {} client.update_product_set(request) @@ -9171,9 +9163,9 @@ def test_delete_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_product_set] = ( + mock_rpc + ) request = {} client.delete_product_set(request) @@ -9449,12 +9441,10 @@ def test_create_product_rest_unset_required_fields(): unset_fields = transport.create_product._get_unset_required_fields({}) assert set(unset_fields) == ( set(("productId",)) - & set( - ( - "parent", - "product", - ) - ) + & set(( + "parent", + "product", + )) ) @@ -9584,12 +9574,10 @@ def test_list_products_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_products._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -9645,12 +9633,10 @@ def test_list_products_rest_unset_required_fields(): unset_fields = transport.list_products._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -10331,9 +10317,9 @@ def test_create_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_reference_image] = ( + mock_rpc + ) request = {} client.create_reference_image(request) @@ -10434,12 +10420,10 @@ def test_create_reference_image_rest_unset_required_fields(): unset_fields = transport.create_reference_image._get_unset_required_fields({}) assert set(unset_fields) == ( set(("referenceImageId",)) - & set( - ( - "parent", - "referenceImage", - ) - ) + & set(( + "parent", + "referenceImage", + )) ) @@ -10531,9 +10515,9 @@ def test_delete_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_reference_image] = ( + mock_rpc + ) request = {} client.delete_reference_image(request) @@ -10711,9 +10695,9 @@ def test_list_reference_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_reference_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_reference_images] = ( + mock_rpc + ) request = {} client.list_reference_images(request) @@ -10756,12 +10740,10 @@ def test_list_reference_images_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_reference_images._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -10819,12 +10801,10 @@ def test_list_reference_images_rest_unset_required_fields(): unset_fields = transport.list_reference_images._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -10982,9 +10962,9 @@ def test_get_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_reference_image] = ( + mock_rpc + ) request = {} client.get_reference_image(request) @@ -11269,12 +11249,10 @@ def test_add_product_to_product_set_rest_unset_required_fields(): unset_fields = transport.add_product_to_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "name", - "product", - ) - ) + & set(( + "name", + "product", + )) ) @@ -11461,17 +11439,15 @@ def test_remove_product_from_product_set_rest_unset_required_fields(): credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.remove_product_from_product_set._get_unset_required_fields( - {} + unset_fields = ( + transport.remove_product_from_product_set._get_unset_required_fields({}) ) assert set(unset_fields) == ( set(()) - & set( - ( - "name", - "product", - ) - ) + & set(( + "name", + "product", + )) ) @@ -11604,12 +11580,10 @@ def test_list_products_in_product_set_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_products_in_product_set._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -11667,12 +11641,10 @@ def test_list_products_in_product_set_rest_unset_required_fields(): unset_fields = transport.list_products_in_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("name",)) ) @@ -11828,9 +11800,9 @@ def test_import_product_sets_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.import_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.import_product_sets] = ( + mock_rpc + ) request = {} client.import_product_sets(request) @@ -11930,12 +11902,10 @@ def test_import_product_sets_rest_unset_required_fields(): unset_fields = transport.import_product_sets._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "parent", - "inputConfig", - ) - ) + & set(( + "parent", + "inputConfig", + )) ) @@ -13048,8 +13018,9 @@ def test_create_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13140,13 +13111,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -13198,17 +13167,20 @@ def test_create_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_create_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13263,8 +13235,9 @@ def test_list_product_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13327,17 +13300,20 @@ def test_list_product_sets_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_product_sets" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_product_sets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_product_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_product_sets" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_product_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_product_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13395,8 +13371,9 @@ def test_get_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13461,17 +13438,20 @@ def test_get_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_get_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13530,8 +13510,9 @@ def test_update_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13626,13 +13607,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -13684,17 +13663,20 @@ def test_update_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_update_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_update_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_update_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13749,8 +13731,9 @@ def test_delete_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13807,13 +13790,13 @@ def test_delete_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_product_set" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteProductSetRequest.pb( product_search_service.DeleteProductSetRequest() @@ -13858,8 +13841,9 @@ def test_create_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13940,13 +13924,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -14002,17 +13984,19 @@ def test_create_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14067,8 +14051,9 @@ def test_list_products_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14131,17 +14116,19 @@ def test_list_products_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_products" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_products" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14199,8 +14186,9 @@ def test_get_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14269,17 +14257,19 @@ def test_get_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14336,8 +14326,9 @@ def test_update_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14420,13 +14411,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -14482,17 +14471,19 @@ def test_update_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_update_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_update_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14547,8 +14538,9 @@ def test_delete_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14605,13 +14597,13 @@ def test_delete_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_product" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteProductRequest.pb( product_search_service.DeleteProductRequest() @@ -14656,8 +14648,9 @@ def test_create_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14743,13 +14736,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -14801,18 +14792,20 @@ def test_create_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_reference_image" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_create_reference_image_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_reference_image" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_create_reference_image_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_reference_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14872,8 +14865,9 @@ def test_delete_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14932,13 +14926,13 @@ def test_delete_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_reference_image" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteReferenceImageRequest.pb( product_search_service.DeleteReferenceImageRequest() @@ -14983,8 +14977,9 @@ def test_list_reference_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15051,18 +15046,20 @@ def test_list_reference_images_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_reference_images" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_list_reference_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_reference_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_reference_images" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_reference_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_reference_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15122,8 +15119,9 @@ def test_get_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15190,18 +15188,20 @@ def test_get_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_reference_image" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_get_reference_image_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_reference_image" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_get_reference_image_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_reference_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15259,8 +15259,9 @@ def test_add_product_to_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15317,13 +15318,13 @@ def test_add_product_to_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_add_product_to_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_add_product_to_product_set" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.AddProductToProductSetRequest.pb( product_search_service.AddProductToProductSetRequest() @@ -15368,8 +15369,9 @@ def test_remove_product_from_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15426,13 +15428,14 @@ def test_remove_product_from_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_remove_product_from_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "pre_remove_product_from_product_set", + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.RemoveProductFromProductSetRequest.pb( product_search_service.RemoveProductFromProductSetRequest() @@ -15477,8 +15480,9 @@ def test_list_products_in_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15543,18 +15547,20 @@ def test_list_products_in_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products_in_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_list_products_in_product_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_products_in_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products_in_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_products_in_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_products_in_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15612,8 +15618,9 @@ def test_import_product_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15670,20 +15677,21 @@ def test_import_product_sets_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProductSearchRestInterceptor, "post_import_product_sets" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_import_product_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_import_product_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_import_product_sets" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_import_product_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_import_product_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16208,11 +16216,14 @@ def test_product_search_base_transport(): def test_product_search_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductSearchTransport( @@ -16232,9 +16243,12 @@ def test_product_search_base_transport_with_credentials_file(): def test_product_search_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductSearchTransport() @@ -16312,11 +16326,12 @@ def test_product_search_transport_auth_gdch_credentials(transport_class): def test_product_search_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py index 3cbaccb9bab4..2a2decdb61e2 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py @@ -44,25 +44,21 @@ HAS_GOOGLE_AUTH_AIO = False from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.type import latlng_pb2 # type: ignore - from google.cloud.vision_v1p4beta1.services.image_annotator import ( ImageAnnotatorAsyncClient, ImageAnnotatorClient, @@ -74,6 +70,9 @@ image_annotator, product_search, ) +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.type import latlng_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -960,10 +959,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1008,10 +1006,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1047,10 +1044,9 @@ def test_image_annotator_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1293,13 +1289,13 @@ def test_image_annotator_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1409,9 +1405,9 @@ def test_batch_annotate_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -1700,9 +1696,9 @@ def test_batch_annotate_files_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_files - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_files] = ( + mock_rpc + ) request = {} client.batch_annotate_files(request) @@ -2581,9 +2577,9 @@ def test_batch_annotate_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_images] = ( + mock_rpc + ) request = {} client.batch_annotate_images(request) @@ -2765,9 +2761,9 @@ def test_batch_annotate_files_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.batch_annotate_files - ] = mock_rpc + client._transport._wrapped_methods[client._transport.batch_annotate_files] = ( + mock_rpc + ) request = {} client.batch_annotate_files(request) @@ -3051,12 +3047,10 @@ def test_async_batch_annotate_images_rest_unset_required_fields(): unset_fields = transport.async_batch_annotate_images._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "requests", - "outputConfig", - ) - ) + & set(( + "requests", + "outputConfig", + )) ) @@ -3654,8 +3648,9 @@ def test_batch_annotate_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3715,18 +3710,20 @@ def test_batch_annotate_images_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_batch_annotate_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_images" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_batch_annotate_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3784,8 +3781,9 @@ def test_batch_annotate_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3845,18 +3843,20 @@ def test_batch_annotate_files_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_files" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_batch_annotate_files_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_batch_annotate_files" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_batch_annotate_files_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_batch_annotate_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3914,8 +3914,9 @@ def test_async_batch_annotate_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3972,20 +3973,21 @@ def test_async_batch_annotate_images_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_images" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_async_batch_annotate_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_images" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_async_batch_annotate_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4038,8 +4040,9 @@ def test_async_batch_annotate_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4096,20 +4099,21 @@ def test_async_batch_annotate_files_rest_interceptors(null_interceptor): ) client = ImageAnnotatorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" - ) as post, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, - "post_async_batch_annotate_files_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "post_async_batch_annotate_files" + ) as post, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, + "post_async_batch_annotate_files_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ImageAnnotatorRestInterceptor, "pre_async_batch_annotate_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4324,11 +4328,14 @@ def test_image_annotator_base_transport(): def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport( @@ -4348,9 +4355,12 @@ def test_image_annotator_base_transport_with_credentials_file(): def test_image_annotator_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageAnnotatorTransport() @@ -4428,11 +4438,12 @@ def test_image_annotator_transport_auth_gdch_credentials(transport_class): def test_image_annotator_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py index 16924d11f086..5ea40569d236 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py @@ -44,29 +44,21 @@ HAS_GOOGLE_AUTH_AIO = False from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - from google.cloud.vision_v1p4beta1.services.product_search import ( ProductSearchAsyncClient, ProductSearchClient, @@ -74,6 +66,15 @@ transports, ) from google.cloud.vision_v1p4beta1.types import geometry, product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.protobuf import ( + any_pb2, # type: ignore + empty_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) +from google.rpc import status_pb2 # type: ignore CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -956,10 +957,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1004,10 +1004,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1043,10 +1042,9 @@ def test_product_search_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1289,13 +1287,13 @@ def test_product_search_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1415,9 +1413,9 @@ def test_create_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_product_set] = ( + mock_rpc + ) request = {} client.create_product_set(request) @@ -1779,9 +1777,9 @@ def test_list_product_sets_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_product_sets] = ( + mock_rpc + ) request = {} client.list_product_sets(request) @@ -2649,9 +2647,9 @@ def test_update_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_product_set] = ( + mock_rpc + ) request = {} client.update_product_set(request) @@ -3000,9 +2998,9 @@ def test_delete_product_set_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_product_set] = ( + mock_rpc + ) request = {} client.delete_product_set(request) @@ -5206,9 +5204,9 @@ def test_create_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_reference_image] = ( + mock_rpc + ) request = {} client.create_reference_image(request) @@ -5568,9 +5566,9 @@ def test_delete_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_reference_image] = ( + mock_rpc + ) request = {} client.delete_reference_image(request) @@ -5906,9 +5904,9 @@ def test_list_reference_images_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_reference_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_reference_images] = ( + mock_rpc + ) request = {} client.list_reference_images(request) @@ -6458,9 +6456,9 @@ def test_get_reference_image_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_reference_image] = ( + mock_rpc + ) request = {} client.get_reference_image(request) @@ -8034,9 +8032,9 @@ def test_import_product_sets_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.import_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.import_product_sets] = ( + mock_rpc + ) request = {} client.import_product_sets(request) @@ -8677,9 +8675,9 @@ def test_create_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_product_set] = ( + mock_rpc + ) request = {} client.create_product_set(request) @@ -8780,12 +8778,10 @@ def test_create_product_set_rest_unset_required_fields(): unset_fields = transport.create_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( set(("productSetId",)) - & set( - ( - "parent", - "productSet", - ) - ) + & set(( + "parent", + "productSet", + )) ) @@ -8872,9 +8868,9 @@ def test_list_product_sets_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_product_sets] = ( + mock_rpc + ) request = {} client.list_product_sets(request) @@ -8917,12 +8913,10 @@ def test_list_product_sets_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_product_sets._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -8980,12 +8974,10 @@ def test_list_product_sets_rest_unset_required_fields(): unset_fields = transport.list_product_sets._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -9314,9 +9306,9 @@ def test_update_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_product_set] = ( + mock_rpc + ) request = {} client.update_product_set(request) @@ -9500,9 +9492,9 @@ def test_delete_product_set_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_product_set - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_product_set] = ( + mock_rpc + ) request = {} client.delete_product_set(request) @@ -9778,12 +9770,10 @@ def test_create_product_rest_unset_required_fields(): unset_fields = transport.create_product._get_unset_required_fields({}) assert set(unset_fields) == ( set(("productId",)) - & set( - ( - "parent", - "product", - ) - ) + & set(( + "parent", + "product", + )) ) @@ -9913,12 +9903,10 @@ def test_list_products_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_products._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -9974,12 +9962,10 @@ def test_list_products_rest_unset_required_fields(): unset_fields = transport.list_products._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -10660,9 +10646,9 @@ def test_create_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_reference_image] = ( + mock_rpc + ) request = {} client.create_reference_image(request) @@ -10763,12 +10749,10 @@ def test_create_reference_image_rest_unset_required_fields(): unset_fields = transport.create_reference_image._get_unset_required_fields({}) assert set(unset_fields) == ( set(("referenceImageId",)) - & set( - ( - "parent", - "referenceImage", - ) - ) + & set(( + "parent", + "referenceImage", + )) ) @@ -10860,9 +10844,9 @@ def test_delete_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_reference_image] = ( + mock_rpc + ) request = {} client.delete_reference_image(request) @@ -11040,9 +11024,9 @@ def test_list_reference_images_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_reference_images - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_reference_images] = ( + mock_rpc + ) request = {} client.list_reference_images(request) @@ -11085,12 +11069,10 @@ def test_list_reference_images_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_reference_images._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -11148,12 +11130,10 @@ def test_list_reference_images_rest_unset_required_fields(): unset_fields = transport.list_reference_images._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("parent",)) ) @@ -11311,9 +11291,9 @@ def test_get_reference_image_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_reference_image - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_reference_image] = ( + mock_rpc + ) request = {} client.get_reference_image(request) @@ -11598,12 +11578,10 @@ def test_add_product_to_product_set_rest_unset_required_fields(): unset_fields = transport.add_product_to_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "name", - "product", - ) - ) + & set(( + "name", + "product", + )) ) @@ -11790,17 +11768,15 @@ def test_remove_product_from_product_set_rest_unset_required_fields(): credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.remove_product_from_product_set._get_unset_required_fields( - {} + unset_fields = ( + transport.remove_product_from_product_set._get_unset_required_fields({}) ) assert set(unset_fields) == ( set(()) - & set( - ( - "name", - "product", - ) - ) + & set(( + "name", + "product", + )) ) @@ -11933,12 +11909,10 @@ def test_list_products_in_product_set_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).list_products_in_product_set._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(( + "page_size", + "page_token", + )) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -11996,12 +11970,10 @@ def test_list_products_in_product_set_rest_unset_required_fields(): unset_fields = transport.list_products_in_product_set._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) + set(( + "pageSize", + "pageToken", + )) & set(("name",)) ) @@ -12157,9 +12129,9 @@ def test_import_product_sets_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.import_product_sets - ] = mock_rpc + client._transport._wrapped_methods[client._transport.import_product_sets] = ( + mock_rpc + ) request = {} client.import_product_sets(request) @@ -12259,12 +12231,10 @@ def test_import_product_sets_rest_unset_required_fields(): unset_fields = transport.import_product_sets._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) - & set( - ( - "parent", - "inputConfig", - ) - ) + & set(( + "parent", + "inputConfig", + )) ) @@ -13601,8 +13571,9 @@ def test_create_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13693,13 +13664,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -13751,17 +13720,20 @@ def test_create_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_create_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13816,8 +13788,9 @@ def test_list_product_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13880,17 +13853,20 @@ def test_list_product_sets_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_product_sets" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_product_sets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_product_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_product_sets" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_product_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_product_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13948,8 +13924,9 @@ def test_get_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14014,17 +13991,20 @@ def test_get_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_get_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14083,8 +14063,9 @@ def test_update_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14179,13 +14160,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -14237,17 +14216,20 @@ def test_update_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_update_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_update_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_update_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14302,8 +14284,9 @@ def test_delete_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14360,13 +14343,13 @@ def test_delete_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_product_set" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteProductSetRequest.pb( product_search_service.DeleteProductSetRequest() @@ -14411,8 +14394,9 @@ def test_create_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14493,13 +14477,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -14555,17 +14537,19 @@ def test_create_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14620,8 +14604,9 @@ def test_list_products_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14684,17 +14669,19 @@ def test_list_products_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_products" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_products" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14752,8 +14739,9 @@ def test_get_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14822,17 +14810,19 @@ def test_get_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14889,8 +14879,9 @@ def test_update_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14973,13 +14964,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -15035,17 +15024,19 @@ def test_update_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_update_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_update_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_update_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_update_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15100,8 +15091,9 @@ def test_delete_product_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15158,13 +15150,13 @@ def test_delete_product_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_product" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteProductRequest.pb( product_search_service.DeleteProductRequest() @@ -15209,8 +15201,9 @@ def test_create_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15296,13 +15289,11 @@ def get_message_fields(field): if result and hasattr(result, "keys"): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) + subfields_not_in_runtime.append({ + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + }) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime @@ -15354,18 +15345,20 @@ def test_create_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_create_reference_image" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_create_reference_image_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_create_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_create_reference_image" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_create_reference_image_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_create_reference_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15425,8 +15418,9 @@ def test_delete_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15485,13 +15479,13 @@ def test_delete_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_delete_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_delete_reference_image" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.DeleteReferenceImageRequest.pb( product_search_service.DeleteReferenceImageRequest() @@ -15536,8 +15530,9 @@ def test_list_reference_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15604,18 +15599,20 @@ def test_list_reference_images_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_reference_images" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_list_reference_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_reference_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_reference_images" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_reference_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_reference_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15675,8 +15672,9 @@ def test_get_reference_image_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15743,18 +15741,20 @@ def test_get_reference_image_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_get_reference_image" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_get_reference_image_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_get_reference_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_get_reference_image" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_get_reference_image_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_get_reference_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15812,8 +15812,9 @@ def test_add_product_to_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15870,13 +15871,13 @@ def test_add_product_to_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_add_product_to_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_add_product_to_product_set" + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.AddProductToProductSetRequest.pb( product_search_service.AddProductToProductSetRequest() @@ -15921,8 +15922,9 @@ def test_remove_product_from_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15979,13 +15981,14 @@ def test_remove_product_from_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_remove_product_from_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "pre_remove_product_from_product_set", + ) as pre, + ): pre.assert_not_called() pb_message = product_search_service.RemoveProductFromProductSetRequest.pb( product_search_service.RemoveProductFromProductSetRequest() @@ -16030,8 +16033,9 @@ def test_list_products_in_product_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16096,18 +16100,20 @@ def test_list_products_in_product_set_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_list_products_in_product_set" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_list_products_in_product_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_list_products_in_product_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_list_products_in_product_set" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_list_products_in_product_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_list_products_in_product_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16165,8 +16171,9 @@ def test_import_product_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16223,20 +16230,21 @@ def test_import_product_sets_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProductSearchRestInterceptor, "post_import_product_sets" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, - "post_import_product_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_import_product_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_import_product_sets" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, + "post_import_product_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_import_product_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16289,8 +16297,9 @@ def test_purge_products_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16347,19 +16356,20 @@ def test_purge_products_rest_interceptors(null_interceptor): ) client = ProductSearchClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProductSearchRestInterceptor, "post_purge_products" - ) as post, mock.patch.object( - transports.ProductSearchRestInterceptor, "post_purge_products_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProductSearchRestInterceptor, "pre_purge_products" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_purge_products" + ) as post, + mock.patch.object( + transports.ProductSearchRestInterceptor, "post_purge_products_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProductSearchRestInterceptor, "pre_purge_products" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16905,11 +16915,14 @@ def test_product_search_base_transport(): def test_product_search_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductSearchTransport( @@ -16929,9 +16942,12 @@ def test_product_search_base_transport_with_credentials_file(): def test_product_search_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductSearchTransport() @@ -17009,11 +17025,12 @@ def test_product_search_transport_auth_gdch_credentials(transport_class): def test_product_search_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"])