diff --git a/.flake8 b/.flake8 index 29227d4..2e43874 100644 --- a/.flake8 +++ b/.flake8 @@ -16,7 +16,7 @@ # Generated by synthtool. DO NOT EDIT! [flake8] -ignore = E203, E266, E501, W503 +ignore = E203, E231, E266, E501, W503 exclude = # Exclude generated code. **/proto/** diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 44c78f7..757c9dc 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:4e1991042fe54b991db9ca17c8fb386e61b22fe4d1472a568bf0fcac85dcf5d3 + digest: sha256:81ed5ecdfc7cac5b699ba4537376f3563f6f04122c4ec9e735d3b3dc1d43dd32 +# created: 2022-05-05T22:08:23.383410683Z diff --git a/.github/auto-approve.yml b/.github/auto-approve.yml new file mode 100644 index 0000000..311ebbb --- /dev/null +++ b/.github/auto-approve.yml @@ -0,0 +1,3 @@ +# https://github.com/googleapis/repo-automation-bots/tree/main/packages/auto-approve +processes: + - "OwlBotTemplateChanges" diff --git a/.github/auto-label.yaml b/.github/auto-label.yaml new file mode 100644 index 0000000..41bff0b --- /dev/null +++ b/.github/auto-label.yaml @@ -0,0 +1,15 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +requestsize: + enabled: true diff --git a/.github/release-please.yml b/.github/release-please.yml index 466597e..6def37a 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1,2 +1,8 @@ releaseType: python handleGHRelease: true +# NOTE: this section is generated by synthtool.languages.python +# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py +branches: +- branch: v0 + handleGHRelease: true + releaseType: python diff --git a/.kokoro/docker/docs/Dockerfile b/.kokoro/docker/docs/Dockerfile index 4e1b1fb..238b87b 100644 --- a/.kokoro/docker/docs/Dockerfile +++ b/.kokoro/docker/docs/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ubuntu:20.04 +from ubuntu:22.04 ENV DEBIAN_FRONTEND noninteractive @@ -60,8 +60,24 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* \ && rm -f /var/cache/apt/archives/*.deb +###################### Install python 3.8.11 + +# Download python 3.8.11 +RUN wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz + +# Extract files +RUN tar -xvf Python-3.8.11.tgz + +# Install python 3.8.11 +RUN ./Python-3.8.11/configure --enable-optimizations +RUN make altinstall + +###################### Install pip RUN wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ - && python3.8 /tmp/get-pip.py \ + && python3 /tmp/get-pip.py \ && rm /tmp/get-pip.py +# Test pip +RUN python3 -m pip + CMD ["python3.8"] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62eb5a7..46d2371 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 22.3.0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 diff --git a/CHANGELOG.md b/CHANGELOG.md index cd49ded..372bb71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ # Changelog -### [1.1.1](https://github.com/googleapis/python-monitoring-metrics-scopes/compare/v1.1.0...v1.1.1) (2022-03-07) +## [1.1.2](https://github.com/googleapis/python-monitoring-metrics-scopes/compare/v1.1.1...v1.1.2) (2022-06-03) + + +### Bug Fixes + +* **deps:** require protobuf <4.0.0dev ([#67](https://github.com/googleapis/python-monitoring-metrics-scopes/issues/67)) ([6ccab96](https://github.com/googleapis/python-monitoring-metrics-scopes/commit/6ccab968c48e88d9159afc9d87bf13bd53dd5d7e)) + + +### Documentation + +* fix changelog header to consistent size ([#66](https://github.com/googleapis/python-monitoring-metrics-scopes/issues/66)) ([4bbf9d8](https://github.com/googleapis/python-monitoring-metrics-scopes/commit/4bbf9d87432aaf9a981d4a834f187bf12568b218)) + +## [1.1.1](https://github.com/googleapis/python-monitoring-metrics-scopes/compare/v1.1.0...v1.1.1) (2022-03-07) ### Bug Fixes @@ -26,7 +38,7 @@ * bump release level to production/stable ([#7](https://www.github.com/googleapis/python-monitoring-metrics-scopes/issues/7)) ([52fe836](https://www.github.com/googleapis/python-monitoring-metrics-scopes/commit/52fe8369d035a1f906488789948dab480eaca59b)) -### [0.1.1](https://www.github.com/googleapis/python-monitoring-metrics-scopes/compare/v0.1.0...v0.1.1) (2021-11-01) +## [0.1.1](https://www.github.com/googleapis/python-monitoring-metrics-scopes/compare/v0.1.0...v0.1.1) (2021-11-01) ### Bug Fixes diff --git a/docs/conf.py b/docs/conf.py index 142b027..d5c7b08 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,9 +24,9 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os import shlex +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -361,7 +361,10 @@ intersphinx_mapping = { "python": ("https://python.readthedocs.org/en/latest/", None), "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), + "google.api_core": ( + "https://googleapis.dev/python/google-api-core/latest/", + None, + ), "grpc": ("https://grpc.github.io/grpc/python/", None), "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), diff --git a/google/cloud/monitoring_metrics_scope/__init__.py b/google/cloud/monitoring_metrics_scope/__init__.py index e63ae35..ff0bac2 100644 --- a/google/cloud/monitoring_metrics_scope/__init__.py +++ b/google/cloud/monitoring_metrics_scope/__init__.py @@ -14,33 +14,22 @@ # limitations under the License. # -from google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes.client import ( - MetricsScopesClient, -) from google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes.async_client import ( MetricsScopesAsyncClient, ) - -from google.cloud.monitoring_metrics_scope_v1.types.metrics_scope import MetricsScope +from google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes.client import ( + MetricsScopesClient, +) from google.cloud.monitoring_metrics_scope_v1.types.metrics_scope import ( + MetricsScope, MonitoredProject, ) from google.cloud.monitoring_metrics_scope_v1.types.metrics_scopes import ( CreateMonitoredProjectRequest, -) -from google.cloud.monitoring_metrics_scope_v1.types.metrics_scopes import ( DeleteMonitoredProjectRequest, -) -from google.cloud.monitoring_metrics_scope_v1.types.metrics_scopes import ( GetMetricsScopeRequest, -) -from google.cloud.monitoring_metrics_scope_v1.types.metrics_scopes import ( ListMetricsScopesByMonitoredProjectRequest, -) -from google.cloud.monitoring_metrics_scope_v1.types.metrics_scopes import ( ListMetricsScopesByMonitoredProjectResponse, -) -from google.cloud.monitoring_metrics_scope_v1.types.metrics_scopes import ( OperationMetadata, ) diff --git a/google/cloud/monitoring_metrics_scope_v1/__init__.py b/google/cloud/monitoring_metrics_scope_v1/__init__.py index 3f42378..0862a7f 100644 --- a/google/cloud/monitoring_metrics_scope_v1/__init__.py +++ b/google/cloud/monitoring_metrics_scope_v1/__init__.py @@ -14,17 +14,16 @@ # limitations under the License. # -from .services.metrics_scopes import MetricsScopesClient -from .services.metrics_scopes import MetricsScopesAsyncClient - -from .types.metrics_scope import MetricsScope -from .types.metrics_scope import MonitoredProject -from .types.metrics_scopes import CreateMonitoredProjectRequest -from .types.metrics_scopes import DeleteMonitoredProjectRequest -from .types.metrics_scopes import GetMetricsScopeRequest -from .types.metrics_scopes import ListMetricsScopesByMonitoredProjectRequest -from .types.metrics_scopes import ListMetricsScopesByMonitoredProjectResponse -from .types.metrics_scopes import OperationMetadata +from .services.metrics_scopes import MetricsScopesAsyncClient, MetricsScopesClient +from .types.metrics_scope import MetricsScope, MonitoredProject +from .types.metrics_scopes import ( + CreateMonitoredProjectRequest, + DeleteMonitoredProjectRequest, + GetMetricsScopeRequest, + ListMetricsScopesByMonitoredProjectRequest, + ListMetricsScopesByMonitoredProjectResponse, + OperationMetadata, +) __all__ = ( "MetricsScopesAsyncClient", diff --git a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/__init__.py b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/__init__.py index 672f09f..10526f7 100644 --- a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/__init__.py +++ b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/__init__.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .client import MetricsScopesClient from .async_client import MetricsScopesAsyncClient +from .client import MetricsScopesClient __all__ = ( "MetricsScopesClient", diff --git a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py index 8a17ba8..44f5649 100644 --- a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py +++ b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py @@ -16,15 +16,15 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries +from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -33,13 +33,14 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scopes from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import MetricsScopesTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import MetricsScopesGrpcAsyncIOTransport + +from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope, metrics_scopes + from .client import MetricsScopesClient +from .transports.base import DEFAULT_CLIENT_INFO, MetricsScopesTransport +from .transports.grpc_asyncio import MetricsScopesGrpcAsyncIOTransport class MetricsScopesAsyncClient: @@ -229,9 +230,9 @@ async def get_metrics_scope( from google.cloud import monitoring_metrics_scope_v1 - def sample_get_metrics_scope(): + async def sample_get_metrics_scope(): # Create a client - client = monitoring_metrics_scope_v1.MetricsScopesClient() + client = monitoring_metrics_scope_v1.MetricsScopesAsyncClient() # Initialize request argument(s) request = monitoring_metrics_scope_v1.GetMetricsScopeRequest( @@ -239,7 +240,7 @@ def sample_get_metrics_scope(): ) # Make the request - response = client.get_metrics_scope(request=request) + response = await client.get_metrics_scope(request=request) # Handle the response print(response) @@ -303,7 +304,12 @@ def sample_get_metrics_scope(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -323,14 +329,13 @@ async def list_metrics_scopes_by_monitored_project( representing the specified monitored project will always be the first entry in the response. - .. code-block:: python from google.cloud import monitoring_metrics_scope_v1 - def sample_list_metrics_scopes_by_monitored_project(): + async def sample_list_metrics_scopes_by_monitored_project(): # Create a client - client = monitoring_metrics_scope_v1.MetricsScopesClient() + client = monitoring_metrics_scope_v1.MetricsScopesAsyncClient() # Initialize request argument(s) request = monitoring_metrics_scope_v1.ListMetricsScopesByMonitoredProjectRequest( @@ -338,7 +343,7 @@ def sample_list_metrics_scopes_by_monitored_project(): ) # Make the request - response = client.list_metrics_scopes_by_monitored_project(request=request) + response = await client.list_metrics_scopes_by_monitored_project(request=request) # Handle the response print(response) @@ -371,7 +376,12 @@ def sample_list_metrics_scopes_by_monitored_project(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -389,14 +399,13 @@ async def create_monitored_project( r"""Adds a ``MonitoredProject`` with the given project ID to the specified ``Metrics Scope``. - .. code-block:: python from google.cloud import monitoring_metrics_scope_v1 - def sample_create_monitored_project(): + async def sample_create_monitored_project(): # Create a client - client = monitoring_metrics_scope_v1.MetricsScopesClient() + client = monitoring_metrics_scope_v1.MetricsScopesAsyncClient() # Initialize request argument(s) request = monitoring_metrics_scope_v1.CreateMonitoredProjectRequest( @@ -408,7 +417,7 @@ def sample_create_monitored_project(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -486,7 +495,12 @@ def sample_create_monitored_project(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -511,14 +525,13 @@ async def delete_monitored_project( r"""Deletes a ``MonitoredProject`` from the specified ``Metrics Scope``. - .. code-block:: python from google.cloud import monitoring_metrics_scope_v1 - def sample_delete_monitored_project(): + async def sample_delete_monitored_project(): # Create a client - client = monitoring_metrics_scope_v1.MetricsScopesClient() + client = monitoring_metrics_scope_v1.MetricsScopesAsyncClient() # Initialize request argument(s) request = monitoring_metrics_scope_v1.DeleteMonitoredProjectRequest( @@ -530,7 +543,7 @@ def sample_delete_monitored_project(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -609,7 +622,12 @@ def sample_delete_monitored_project(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( diff --git a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py index a72adbc..da20fe5 100644 --- a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py +++ b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py @@ -16,18 +16,18 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore +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.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -36,11 +36,12 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scopes from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import MetricsScopesTransport, DEFAULT_CLIENT_INFO + +from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope, metrics_scopes + +from .transports.base import DEFAULT_CLIENT_INFO, MetricsScopesTransport from .transports.grpc import MetricsScopesGrpcTransport from .transports.grpc_asyncio import MetricsScopesGrpcAsyncIOTransport @@ -57,7 +58,10 @@ class MetricsScopesClientMeta(type): _transport_registry["grpc"] = MetricsScopesGrpcTransport _transport_registry["grpc_asyncio"] = MetricsScopesGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[MetricsScopesTransport]: + def get_transport_class( + cls, + label: str = None, + ) -> Type[MetricsScopesTransport]: """Returns an appropriate transport class. Args: @@ -164,7 +168,9 @@ def transport(self) -> MetricsScopesTransport: return self._transport @staticmethod - def metrics_scope_path(metrics_scope: str,) -> str: + def metrics_scope_path( + metrics_scope: str, + ) -> str: """Returns a fully-qualified metrics_scope string.""" return "locations/global/metricsScope/{metrics_scope}".format( metrics_scope=metrics_scope, @@ -177,10 +183,16 @@ def parse_metrics_scope_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def monitored_project_path(metrics_scope: str, project: str,) -> str: + def monitored_project_path( + metrics_scope: str, + project: str, + ) -> str: """Returns a fully-qualified monitored_project string.""" - return "locations/global/metricsScopes/{metrics_scope}/projects/{project}".format( - metrics_scope=metrics_scope, project=project, + return ( + "locations/global/metricsScopes/{metrics_scope}/projects/{project}".format( + metrics_scope=metrics_scope, + project=project, + ) ) @staticmethod @@ -193,7 +205,9 @@ def parse_monitored_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -206,9 +220,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -217,9 +235,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -228,9 +250,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -239,10 +265,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -505,7 +535,12 @@ def sample_get_metrics_scope(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -525,7 +560,6 @@ def list_metrics_scopes_by_monitored_project( representing the specified monitored project will always be the first entry in the response. - .. code-block:: python from google.cloud import monitoring_metrics_scope_v1 @@ -578,7 +612,12 @@ def sample_list_metrics_scopes_by_monitored_project(): ] # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -596,7 +635,6 @@ def create_monitored_project( r"""Adds a ``MonitoredProject`` with the given project ID to the specified ``Metrics Scope``. - .. code-block:: python from google.cloud import monitoring_metrics_scope_v1 @@ -693,7 +731,12 @@ def sample_create_monitored_project(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -718,7 +761,6 @@ def delete_monitored_project( r"""Deletes a ``MonitoredProject`` from the specified ``Metrics Scope``. - .. code-block:: python from google.cloud import monitoring_metrics_scope_v1 @@ -816,7 +858,12 @@ def sample_delete_monitored_project(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( diff --git a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/__init__.py b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/__init__.py index d67abb4..0760bf5 100644 --- a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/__init__.py +++ b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/__init__.py @@ -20,7 +20,6 @@ from .grpc import MetricsScopesGrpcTransport from .grpc_asyncio import MetricsScopesGrpcAsyncIOTransport - # Compile a registry of transports. _transport_registry = OrderedDict() # type: Dict[str, Type[MetricsScopesTransport]] _transport_registry["grpc"] = MetricsScopesGrpcTransport diff --git a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py index 625ae53..93c7ed1 100644 --- a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py +++ b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py @@ -15,20 +15,18 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources -import google.auth # type: ignore import google.api_core from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries -from google.api_core import operations_v1 +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scopes -from google.longrunning import operations_pb2 # type: ignore +from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope, metrics_scopes try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -88,6 +86,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -129,7 +128,9 @@ def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.get_metrics_scope: gapic_v1.method.wrap_method( - self.get_metrics_scope, default_timeout=None, client_info=client_info, + self.get_metrics_scope, + default_timeout=None, + client_info=client_info, ), self.list_metrics_scopes_by_monitored_project: gapic_v1.method.wrap_method( self.list_metrics_scopes_by_monitored_project, @@ -151,9 +152,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @@ -201,5 +202,9 @@ def delete_monitored_project( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("MetricsScopesTransport",) diff --git a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py index b1cbe4d..3249076 100644 --- a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py +++ b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py @@ -13,22 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import grpc_helpers -from google.api_core import operations_v1 -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, grpc_helpers, operations_v1 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.longrunning import operations_pb2 # type: ignore import grpc # type: ignore -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scopes -from google.longrunning import operations_pb2 # type: ignore -from .base import MetricsScopesTransport, DEFAULT_CLIENT_INFO +from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope, metrics_scopes + +from .base import DEFAULT_CLIENT_INFO, MetricsScopesTransport class MetricsScopesGrpcTransport(MetricsScopesTransport): @@ -229,8 +226,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -369,5 +365,9 @@ def delete_monitored_project( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("MetricsScopesGrpcTransport",) diff --git a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py index bcf91e9..b501f42 100644 --- a/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py @@ -13,22 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import operations_v1 +from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scopes -from google.longrunning import operations_pb2 # type: ignore -from .base import MetricsScopesTransport, DEFAULT_CLIENT_INFO +from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope, metrics_scopes + +from .base import DEFAULT_CLIENT_INFO, MetricsScopesTransport from .grpc import MetricsScopesGrpcTransport diff --git a/google/cloud/monitoring_metrics_scope_v1/types/__init__.py b/google/cloud/monitoring_metrics_scope_v1/types/__init__.py index 82366f1..4447e7e 100644 --- a/google/cloud/monitoring_metrics_scope_v1/types/__init__.py +++ b/google/cloud/monitoring_metrics_scope_v1/types/__init__.py @@ -13,10 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .metrics_scope import ( - MetricsScope, - MonitoredProject, -) +from .metrics_scope import MetricsScope, MonitoredProject from .metrics_scopes import ( CreateMonitoredProjectRequest, DeleteMonitoredProjectRequest, diff --git a/google/cloud/monitoring_metrics_scope_v1/types/metrics_scope.py b/google/cloud/monitoring_metrics_scope_v1/types/metrics_scope.py index 57c1d45..1d7b937 100644 --- a/google/cloud/monitoring_metrics_scope_v1/types/metrics_scope.py +++ b/google/cloud/monitoring_metrics_scope_v1/types/metrics_scope.py @@ -13,14 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - from google.protobuf import timestamp_pb2 # type: ignore - +import proto # type: ignore __protobuf__ = proto.module( package="google.monitoring.metricsscope.v1", - manifest={"MetricsScope", "MonitoredProject",}, + manifest={ + "MetricsScope", + "MonitoredProject", + }, ) @@ -48,11 +49,24 @@ class MetricsScope(proto.Message): ``Metrics Scope``. """ - name = proto.Field(proto.STRING, number=1,) - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) monitored_projects = proto.RepeatedField( - proto.MESSAGE, number=4, message="MonitoredProject", + proto.MESSAGE, + number=4, + message="MonitoredProject", ) @@ -73,8 +87,15 @@ class MonitoredProject(proto.Message): created. """ - name = proto.Field(proto.STRING, number=1,) - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/monitoring_metrics_scope_v1/types/metrics_scopes.py b/google/cloud/monitoring_metrics_scope_v1/types/metrics_scopes.py index 3e35376..e694ce6 100644 --- a/google/cloud/monitoring_metrics_scope_v1/types/metrics_scopes.py +++ b/google/cloud/monitoring_metrics_scope_v1/types/metrics_scopes.py @@ -13,11 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope -from google.protobuf import timestamp_pb2 # type: ignore - __protobuf__ = proto.module( package="google.monitoring.metricsscope.v1", @@ -42,7 +41,10 @@ class GetMetricsScopeRequest(proto.Message): ``locations/global/metricsScopes/{SCOPING_PROJECT_ID_OR_NUMBER}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListMetricsScopesByMonitoredProjectRequest(proto.Message): @@ -55,7 +57,10 @@ class ListMetricsScopesByMonitoredProjectRequest(proto.Message): ``projects/{MONITORED_PROJECT_ID_OR_NUMBER}`` """ - monitored_resource_container = proto.Field(proto.STRING, number=1,) + monitored_resource_container = proto.Field( + proto.STRING, + number=1, + ) class ListMetricsScopesByMonitoredProjectResponse(proto.Message): @@ -68,7 +73,9 @@ class ListMetricsScopesByMonitoredProjectResponse(proto.Message): """ metrics_scopes = proto.RepeatedField( - proto.MESSAGE, number=1, message=metrics_scope.MetricsScope, + proto.MESSAGE, + number=1, + message=metrics_scope.MetricsScope, ) @@ -88,9 +95,14 @@ class CreateMonitoredProjectRequest(proto.Message): ``locations/global/metricsScopes/{SCOPING_PROJECT_ID_OR_NUMBER}/projects/{MONITORED_PROJECT_ID_OR_NUMBER}`` """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) monitored_project = proto.Field( - proto.MESSAGE, number=2, message=metrics_scope.MonitoredProject, + proto.MESSAGE, + number=2, + message=metrics_scope.MonitoredProject, ) @@ -109,7 +121,10 @@ class DeleteMonitoredProjectRequest(proto.Message): ``monitoring.metricsScopes.link`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class OperationMetadata(proto.Message): @@ -134,9 +149,21 @@ class State(proto.Enum): DONE = 3 CANCELLED = 4 - state = proto.Field(proto.ENUM, number=1, enum=State,) - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/noxfile.py b/noxfile.py index 2a2001c..7c1742d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -17,19 +17,45 @@ # Generated by synthtool. DO NOT EDIT! from __future__ import absolute_import + import os import pathlib import shutil +import warnings import nox - -BLACK_VERSION = "black==19.10b0" -BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] +BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" +LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" -SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] + UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +UNIT_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "asyncmock", + "pytest", + "pytest-cov", + "pytest-asyncio", +] +UNIT_TEST_EXTERNAL_DEPENDENCIES = [] +UNIT_TEST_LOCAL_DEPENDENCIES = [] +UNIT_TEST_DEPENDENCIES = [] +UNIT_TEST_EXTRAS = [] +UNIT_TEST_EXTRAS_BY_PYTHON = {} + +SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] +SYSTEM_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "pytest", + "google-cloud-testutils", +] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES = [] +SYSTEM_TEST_DEPENDENCIES = [] +SYSTEM_TEST_EXTRAS = [] +SYSTEM_TEST_EXTRAS_BY_PYTHON = {} CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() @@ -57,7 +83,9 @@ def lint(session): """ session.install("flake8", BLACK_VERSION) session.run( - "black", "--check", *BLACK_PATHS, + "black", + "--check", + *LINT_PATHS, ) session.run("flake8", "google", "tests") @@ -67,7 +95,28 @@ def blacken(session): """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( - "black", *BLACK_PATHS, + "black", + *LINT_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def format(session): + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run( + "isort", + "--fss", + *LINT_PATHS, + ) + session.run( + "black", + *LINT_PATHS, ) @@ -78,23 +127,41 @@ def lint_setup_py(session): session.run("python", "setup.py", "check", "--restructuredtext", "--strict") +def install_unittest_dependencies(session, *constraints): + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, *constraints) + + if UNIT_TEST_EXTERNAL_DEPENDENCIES: + warnings.warn( + "'unit_test_external_dependencies' is deprecated. Instead, please " + "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", + DeprecationWarning, + ) + session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_LOCAL_DEPENDENCIES: + session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_EXTRAS_BY_PYTHON: + extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif UNIT_TEST_EXTRAS: + extras = UNIT_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + def default(session): # Install all test dependencies, then install this package in-place. constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) - session.install( - "mock", - "asyncmock", - "pytest", - "pytest-cov", - "pytest-asyncio", - "-c", - constraints_path, - ) - - session.install("-e", ".", "-c", constraints_path) + install_unittest_dependencies(session, "-c", constraints_path) # Run py.test against the unit tests. session.run( @@ -118,6 +185,35 @@ def unit(session): default(session) +def install_systemtest_dependencies(session, *constraints): + + # Use pre-release gRPC for system tests. + session.install("--pre", "grpcio") + + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_LOCAL_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTRAS_BY_PYTHON: + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif SYSTEM_TEST_EXTRAS: + extras = SYSTEM_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" @@ -140,13 +236,7 @@ def system(session): if not system_test_exists and not system_test_folder_exists: session.skip("System tests were not found") - # Use pre-release gRPC for system tests. - session.install("--pre", "grpcio") - - # Install all test dependencies, then install this package into the - # virtualenv's dist-packages. - session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) - session.install("-e", ".", "-c", constraints_path) + install_systemtest_dependencies(session, "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: diff --git a/samples/generated_samples/snippet_metadata_monitoring metrics scope_v1.json b/samples/generated_samples/snippet_metadata_monitoring metrics scope_v1.json index 1a5777d..c3d0ef2 100644 --- a/samples/generated_samples/snippet_metadata_monitoring metrics scope_v1.json +++ b/samples/generated_samples/snippet_metadata_monitoring metrics scope_v1.json @@ -1,16 +1,65 @@ { + "clientLibrary": { + "apis": [ + { + "id": "google.monitoring.metricsscope.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-monitoring-metrics-scope" + }, "snippets": [ { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient", + "shortName": "MetricsScopesAsyncClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient.create_monitored_project", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.CreateMonitoredProject", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "CreateMonitoredProject" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.CreateMonitoredProjectRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "monitored_project", + "type": "google.cloud.monitoring_metrics_scope_v1.types.MonitoredProject" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_monitored_project" }, + "description": "Sample for CreateMonitoredProject", "file": "monitoring_v1_generated_metrics_scopes_create_monitored_project_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_CreateMonitoredProject_async", "segments": [ { @@ -43,18 +92,58 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_create_monitored_project_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient", + "shortName": "MetricsScopesClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient.create_monitored_project", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.CreateMonitoredProject", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "CreateMonitoredProject" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.CreateMonitoredProjectRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "monitored_project", + "type": "google.cloud.monitoring_metrics_scope_v1.types.MonitoredProject" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_monitored_project" }, + "description": "Sample for CreateMonitoredProject", "file": "monitoring_v1_generated_metrics_scopes_create_monitored_project_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_CreateMonitoredProject_sync", "segments": [ { @@ -87,19 +176,55 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_create_monitored_project_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient", + "shortName": "MetricsScopesAsyncClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient.delete_monitored_project", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.DeleteMonitoredProject", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "DeleteMonitoredProject" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.DeleteMonitoredProjectRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_monitored_project" }, + "description": "Sample for DeleteMonitoredProject", "file": "monitoring_v1_generated_metrics_scopes_delete_monitored_project_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_DeleteMonitoredProject_async", "segments": [ { @@ -132,18 +257,54 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_delete_monitored_project_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient", + "shortName": "MetricsScopesClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient.delete_monitored_project", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.DeleteMonitoredProject", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "DeleteMonitoredProject" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.DeleteMonitoredProjectRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_monitored_project" }, + "description": "Sample for DeleteMonitoredProject", "file": "monitoring_v1_generated_metrics_scopes_delete_monitored_project_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_DeleteMonitoredProject_sync", "segments": [ { @@ -176,19 +337,55 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_delete_monitored_project_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient", + "shortName": "MetricsScopesAsyncClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient.get_metrics_scope", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.GetMetricsScope", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "GetMetricsScope" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.GetMetricsScopeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.monitoring_metrics_scope_v1.types.MetricsScope", + "shortName": "get_metrics_scope" }, + "description": "Sample for GetMetricsScope", "file": "monitoring_v1_generated_metrics_scopes_get_metrics_scope_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_GetMetricsScope_async", "segments": [ { @@ -221,18 +418,54 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_get_metrics_scope_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient", + "shortName": "MetricsScopesClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient.get_metrics_scope", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.GetMetricsScope", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "GetMetricsScope" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.GetMetricsScopeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.monitoring_metrics_scope_v1.types.MetricsScope", + "shortName": "get_metrics_scope" }, + "description": "Sample for GetMetricsScope", "file": "monitoring_v1_generated_metrics_scopes_get_metrics_scope_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_GetMetricsScope_sync", "segments": [ { @@ -265,19 +498,51 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_get_metrics_scope_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient", + "shortName": "MetricsScopesAsyncClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesAsyncClient.list_metrics_scopes_by_monitored_project", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.ListMetricsScopesByMonitoredProject", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "ListMetricsScopesByMonitoredProject" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.ListMetricsScopesByMonitoredProjectRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.monitoring_metrics_scope_v1.types.ListMetricsScopesByMonitoredProjectResponse", + "shortName": "list_metrics_scopes_by_monitored_project" }, + "description": "Sample for ListMetricsScopesByMonitoredProject", "file": "monitoring_v1_generated_metrics_scopes_list_metrics_scopes_by_monitored_project_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_ListMetricsScopesByMonitoredProject_async", "segments": [ { @@ -310,18 +575,50 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_list_metrics_scopes_by_monitored_project_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient", + "shortName": "MetricsScopesClient" + }, + "fullName": "google.cloud.monitoring_metrics_scope_v1.MetricsScopesClient.list_metrics_scopes_by_monitored_project", "method": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes.ListMetricsScopesByMonitoredProject", "service": { + "fullName": "google.monitoring.metricsscope.v1.MetricsScopes", "shortName": "MetricsScopes" }, "shortName": "ListMetricsScopesByMonitoredProject" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.monitoring_metrics_scope_v1.types.ListMetricsScopesByMonitoredProjectRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.monitoring_metrics_scope_v1.types.ListMetricsScopesByMonitoredProjectResponse", + "shortName": "list_metrics_scopes_by_monitored_project" }, + "description": "Sample for ListMetricsScopesByMonitoredProject", "file": "monitoring_v1_generated_metrics_scopes_list_metrics_scopes_by_monitored_project_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "monitoring_v1_generated_MetricsScopes_ListMetricsScopesByMonitoredProject_sync", "segments": [ { @@ -354,7 +651,8 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "monitoring_v1_generated_metrics_scopes_list_metrics_scopes_by_monitored_project_sync.py" } ] } diff --git a/scripts/readme-gen/readme_gen.py b/scripts/readme-gen/readme_gen.py index d309d6e..91b5967 100644 --- a/scripts/readme-gen/readme_gen.py +++ b/scripts/readme-gen/readme_gen.py @@ -28,7 +28,10 @@ jinja_env = jinja2.Environment( trim_blocks=True, loader=jinja2.FileSystemLoader( - os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')))) + os.path.abspath(os.path.join(os.path.dirname(__file__), "templates")) + ), + autoescape=True, +) README_TMPL = jinja_env.get_template('README.tmpl.rst') diff --git a/setup.py b/setup.py index 28e0522..ce1d423 100644 --- a/setup.py +++ b/setup.py @@ -15,9 +15,10 @@ # import io import os + import setuptools # type: ignore -version = "1.1.1" +version = "1.1.2" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -40,7 +41,8 @@ include_package_data=True, install_requires=( "google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0", - "proto-plus >= 1.15.0", + "proto-plus >= 1.15.0, <2.0.0dev", + "protobuf >= 3.19.0, <4.0.0dev", ), python_requires=">=3.6", classifiers=[ diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index b666ca6..ec8ca20 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -7,3 +7,4 @@ # Then this file should have foo==1.14.0 google-api-core==1.31.5 proto-plus==1.15.0 +protobuf==3.19.0 diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt index e69de29..ec8ca20 100644 --- a/testing/constraints-3.7.txt +++ b/testing/constraints-3.7.txt @@ -0,0 +1,10 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List *all* library dependencies and extras in this file. +# Pin the version to the lower bound. +# +# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", +# Then this file should have foo==1.14.0 +google-api-core==1.31.5 +proto-plus==1.15.0 +protobuf==3.19.0 diff --git a/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py b/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py index e13ef16..8b5c4dd 100644 --- a/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py +++ b/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py @@ -14,40 +14,45 @@ # limitations under the License. # import os -import mock -import grpc -from grpc.experimental import aio -import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock +import math +from google.api_core import ( + future, + gapic_v1, + grpc_helpers, + grpc_helpers_async, + operation, + 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 future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.api_core import path_template +import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import timestamp_pb2 # type: ignore +import grpc +from grpc.experimental import aio +from proto.marshal.rules.dates import DurationRule, TimestampRule +import pytest + from google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes import ( MetricsScopesAsyncClient, -) -from google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes import ( MetricsScopesClient, + transports, ) -from google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes import transports -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope -from google.cloud.monitoring_metrics_scope_v1.types import metrics_scopes -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.protobuf import timestamp_pb2 # type: ignore -import google.auth +from google.cloud.monitoring_metrics_scope_v1.types import metrics_scope, metrics_scopes def client_cert_source_callback(): @@ -95,20 +100,24 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [MetricsScopesClient, MetricsScopesAsyncClient,] + "client_class,transport_name", + [ + (MetricsScopesClient, "grpc"), + (MetricsScopesAsyncClient, "grpc_asyncio"), + ], ) -def test_metrics_scopes_client_from_service_account_info(client_class): +def test_metrics_scopes_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == ("monitoring.googleapis.com:443") @pytest.mark.parametrize( @@ -137,23 +146,31 @@ def test_metrics_scopes_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", [MetricsScopesClient, MetricsScopesAsyncClient,] + "client_class,transport_name", + [ + (MetricsScopesClient, "grpc"), + (MetricsScopesAsyncClient, "grpc_asyncio"), + ], ) -def test_metrics_scopes_client_from_service_account_file(client_class): +def test_metrics_scopes_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == ("monitoring.googleapis.com:443") def test_metrics_scopes_client_get_transport_class(): @@ -501,7 +518,9 @@ def test_metrics_scopes_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -646,10 +665,17 @@ def test_metrics_scopes_client_create_channel_credentials_file( ) -@pytest.mark.parametrize("request_type", [metrics_scopes.GetMetricsScopeRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + metrics_scopes.GetMetricsScopeRequest, + dict, + ], +) def test_get_metrics_scope(request_type, transport: str = "grpc"): client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -661,7 +687,9 @@ def test_get_metrics_scope(request_type, transport: str = "grpc"): type(client.transport.get_metrics_scope), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = metrics_scope.MetricsScope(name="name_value",) + call.return_value = metrics_scope.MetricsScope( + name="name_value", + ) response = client.get_metrics_scope(request) # Establish that the underlying gRPC stub method was called. @@ -678,7 +706,8 @@ def test_get_metrics_scope_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -696,7 +725,8 @@ async def test_get_metrics_scope_async( transport: str = "grpc_asyncio", request_type=metrics_scopes.GetMetricsScopeRequest ): client = MetricsScopesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -709,7 +739,9 @@ async def test_get_metrics_scope_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metrics_scope.MetricsScope(name="name_value",) + metrics_scope.MetricsScope( + name="name_value", + ) ) response = await client.get_metrics_scope(request) @@ -729,13 +761,15 @@ async def test_get_metrics_scope_async_from_dict(): def test_get_metrics_scope_field_headers(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metrics_scopes.GetMetricsScopeRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -751,7 +785,10 @@ def test_get_metrics_scope_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -764,7 +801,7 @@ async def test_get_metrics_scope_field_headers_async(): # a field header. Set these to a non-empty value. request = metrics_scopes.GetMetricsScopeRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -782,11 +819,16 @@ async def test_get_metrics_scope_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_metrics_scope_flattened(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -796,7 +838,9 @@ def test_get_metrics_scope_flattened(): call.return_value = metrics_scope.MetricsScope() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_metrics_scope(name="name_value",) + client.get_metrics_scope( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -808,13 +852,16 @@ def test_get_metrics_scope_flattened(): def test_get_metrics_scope_flattened_error(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_metrics_scope( - metrics_scopes.GetMetricsScopeRequest(), name="name_value", + metrics_scopes.GetMetricsScopeRequest(), + name="name_value", ) @@ -836,7 +883,9 @@ async def test_get_metrics_scope_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_metrics_scope(name="name_value",) + response = await client.get_metrics_scope( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -857,18 +906,24 @@ async def test_get_metrics_scope_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_metrics_scope( - metrics_scopes.GetMetricsScopeRequest(), name="name_value", + metrics_scopes.GetMetricsScopeRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [metrics_scopes.ListMetricsScopesByMonitoredProjectRequest, dict,] + "request_type", + [ + metrics_scopes.ListMetricsScopesByMonitoredProjectRequest, + dict, + ], ) def test_list_metrics_scopes_by_monitored_project( request_type, transport: str = "grpc" ): client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -898,7 +953,8 @@ def test_list_metrics_scopes_by_monitored_project_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -917,7 +973,8 @@ async def test_list_metrics_scopes_by_monitored_project_async( request_type=metrics_scopes.ListMetricsScopesByMonitoredProjectRequest, ): client = MetricsScopesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -951,11 +1008,16 @@ async def test_list_metrics_scopes_by_monitored_project_async_from_dict(): @pytest.mark.parametrize( - "request_type", [metrics_scopes.CreateMonitoredProjectRequest, dict,] + "request_type", + [ + metrics_scopes.CreateMonitoredProjectRequest, + dict, + ], ) def test_create_monitored_project(request_type, transport: str = "grpc"): client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -983,7 +1045,8 @@ def test_create_monitored_project_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1002,7 +1065,8 @@ async def test_create_monitored_project_async( request_type=metrics_scopes.CreateMonitoredProjectRequest, ): client = MetricsScopesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1034,13 +1098,15 @@ async def test_create_monitored_project_async_from_dict(): def test_create_monitored_project_field_headers(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metrics_scopes.CreateMonitoredProjectRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1056,7 +1122,10 @@ def test_create_monitored_project_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1069,7 +1138,7 @@ async def test_create_monitored_project_field_headers_async(): # a field header. Set these to a non-empty value. request = metrics_scopes.CreateMonitoredProjectRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1087,11 +1156,16 @@ async def test_create_monitored_project_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_monitored_project_flattened(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1119,7 +1193,9 @@ def test_create_monitored_project_flattened(): def test_create_monitored_project_flattened_error(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1183,11 +1259,16 @@ async def test_create_monitored_project_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [metrics_scopes.DeleteMonitoredProjectRequest, dict,] + "request_type", + [ + metrics_scopes.DeleteMonitoredProjectRequest, + dict, + ], ) def test_delete_monitored_project(request_type, transport: str = "grpc"): client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1215,7 +1296,8 @@ def test_delete_monitored_project_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1234,7 +1316,8 @@ async def test_delete_monitored_project_async( request_type=metrics_scopes.DeleteMonitoredProjectRequest, ): client = MetricsScopesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1266,13 +1349,15 @@ async def test_delete_monitored_project_async_from_dict(): def test_delete_monitored_project_field_headers(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metrics_scopes.DeleteMonitoredProjectRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1288,7 +1373,10 @@ def test_delete_monitored_project_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1301,7 +1389,7 @@ async def test_delete_monitored_project_field_headers_async(): # a field header. Set these to a non-empty value. request = metrics_scopes.DeleteMonitoredProjectRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1319,11 +1407,16 @@ async def test_delete_monitored_project_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_monitored_project_flattened(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1333,7 +1426,9 @@ def test_delete_monitored_project_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_monitored_project(name="name_value",) + client.delete_monitored_project( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1345,13 +1440,16 @@ def test_delete_monitored_project_flattened(): def test_delete_monitored_project_flattened_error(): - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_monitored_project( - metrics_scopes.DeleteMonitoredProjectRequest(), name="name_value", + metrics_scopes.DeleteMonitoredProjectRequest(), + name="name_value", ) @@ -1373,7 +1471,9 @@ async def test_delete_monitored_project_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_monitored_project(name="name_value",) + response = await client.delete_monitored_project( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1394,7 +1494,8 @@ async def test_delete_monitored_project_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_monitored_project( - metrics_scopes.DeleteMonitoredProjectRequest(), name="name_value", + metrics_scopes.DeleteMonitoredProjectRequest(), + name="name_value", ) @@ -1405,7 +1506,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1425,7 +1527,10 @@ def test_credentials_transport_error(): options = client_options.ClientOptions() options.api_key = "api_key" with pytest.raises(ValueError): - client = MetricsScopesClient(client_options=options, transport=transport,) + client = MetricsScopesClient( + client_options=options, + transport=transport, + ) # It is an error to provide an api_key and a credential. options = mock.Mock() @@ -1441,7 +1546,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = MetricsScopesClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1484,10 +1590,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = MetricsScopesClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = MetricsScopesClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.MetricsScopesGrpcTransport,) + client = MetricsScopesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.MetricsScopesGrpcTransport, + ) def test_metrics_scopes_base_transport_error(): @@ -1529,6 +1653,14 @@ def test_metrics_scopes_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_metrics_scopes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -1540,7 +1672,8 @@ def test_metrics_scopes_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricsScopesTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1693,24 +1826,40 @@ def test_metrics_scopes_grpc_transport_client_cert_source_for_mtls(transport_cla ) -def test_metrics_scopes_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_metrics_scopes_host_no_port(transport_name): client = MetricsScopesClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="monitoring.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == ("monitoring.googleapis.com:443") -def test_metrics_scopes_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_metrics_scopes_host_with_port(transport_name): client = MetricsScopesClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="monitoring.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "monitoring.googleapis.com:8000" + assert client.transport._host == ("monitoring.googleapis.com:8000") def test_metrics_scopes_grpc_transport_channel(): @@ -1718,7 +1867,8 @@ def test_metrics_scopes_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.MetricsScopesGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1730,7 +1880,8 @@ def test_metrics_scopes_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.MetricsScopesGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1837,12 +1988,16 @@ def test_metrics_scopes_transport_channel_mtls_with_adc(transport_class): def test_metrics_scopes_grpc_lro_client(): client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1850,12 +2005,16 @@ def test_metrics_scopes_grpc_lro_client(): def test_metrics_scopes_grpc_lro_async_client(): client = MetricsScopesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1884,8 +2043,11 @@ def test_parse_metrics_scope_path(): def test_monitored_project_path(): metrics_scope = "whelk" project = "octopus" - expected = "locations/global/metricsScopes/{metrics_scope}/projects/{project}".format( - metrics_scope=metrics_scope, project=project, + expected = ( + "locations/global/metricsScopes/{metrics_scope}/projects/{project}".format( + metrics_scope=metrics_scope, + project=project, + ) ) actual = MetricsScopesClient.monitored_project_path(metrics_scope, project) assert expected == actual @@ -1925,7 +2087,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = MetricsScopesClient.common_folder_path(folder) assert expected == actual @@ -1943,7 +2107,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = MetricsScopesClient.common_organization_path(organization) assert expected == actual @@ -1961,7 +2127,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = MetricsScopesClient.common_project_path(project) assert expected == actual @@ -1981,7 +2149,8 @@ def test_common_location_path(): project = "whelk" location = "octopus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = MetricsScopesClient.common_location_path(project, location) assert expected == actual @@ -2006,7 +2175,8 @@ def test_client_with_default_client_info(): transports.MetricsScopesTransport, "_prep_wrapped_messages" ) as prep: client = MetricsScopesClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2015,7 +2185,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = MetricsScopesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2023,7 +2194,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = MetricsScopesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close"