diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml
index 2567653..7d98291 100644
--- a/.github/.OwlBot.lock.yaml
+++ b/.github/.OwlBot.lock.yaml
@@ -1,3 +1,3 @@
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
- digest: sha256:87eee22d276554e4e52863ec9b1cb6a7245815dfae20439712bf644348215a5a
+ digest: sha256:58f73ba196b5414782605236dd0712a73541b44ff2ff4d3a36ec41092dd6fa5b
diff --git a/.kokoro/samples/lint/common.cfg b/.kokoro/samples/lint/common.cfg
index 06f6916..26839ed 100644
--- a/.kokoro/samples/lint/common.cfg
+++ b/.kokoro/samples/lint/common.cfg
@@ -31,4 +31,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
# Use the trampoline script to run in docker.
-build_file: "python-binary-authorization/.kokoro/trampoline.sh"
\ No newline at end of file
+build_file: "python-binary-authorization/.kokoro/trampoline_v2.sh"
\ No newline at end of file
diff --git a/.kokoro/samples/python3.10/common.cfg b/.kokoro/samples/python3.10/common.cfg
new file mode 100644
index 0000000..1eb6733
--- /dev/null
+++ b/.kokoro/samples/python3.10/common.cfg
@@ -0,0 +1,40 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Build logs will be here
+action {
+ define_artifacts {
+ regex: "**/*sponge_log.xml"
+ }
+}
+
+# Specify which tests to run
+env_vars: {
+ key: "RUN_TESTS_SESSION"
+ value: "py-3.10"
+}
+
+# Declare build specific Cloud project.
+env_vars: {
+ key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
+ value: "python-docs-samples-tests-310"
+}
+
+env_vars: {
+ key: "TRAMPOLINE_BUILD_FILE"
+ value: "github/python-binary-authorization/.kokoro/test-samples.sh"
+}
+
+# Configure the docker image for kokoro-trampoline.
+env_vars: {
+ key: "TRAMPOLINE_IMAGE"
+ value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
+}
+
+# Download secrets for samples
+gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
+
+# Download trampoline resources.
+gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
+
+# Use the trampoline script to run in docker.
+build_file: "python-binary-authorization/.kokoro/trampoline_v2.sh"
\ No newline at end of file
diff --git a/.kokoro/samples/python3.10/continuous.cfg b/.kokoro/samples/python3.10/continuous.cfg
new file mode 100644
index 0000000..a1c8d97
--- /dev/null
+++ b/.kokoro/samples/python3.10/continuous.cfg
@@ -0,0 +1,6 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "True"
+}
\ No newline at end of file
diff --git a/.kokoro/samples/python3.10/periodic-head.cfg b/.kokoro/samples/python3.10/periodic-head.cfg
new file mode 100644
index 0000000..0b0f4ba
--- /dev/null
+++ b/.kokoro/samples/python3.10/periodic-head.cfg
@@ -0,0 +1,11 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "True"
+}
+
+env_vars: {
+ key: "TRAMPOLINE_BUILD_FILE"
+ value: "github/python-binary-authorization/.kokoro/test-samples-against-head.sh"
+}
diff --git a/.kokoro/samples/python3.10/periodic.cfg b/.kokoro/samples/python3.10/periodic.cfg
new file mode 100644
index 0000000..71cd1e5
--- /dev/null
+++ b/.kokoro/samples/python3.10/periodic.cfg
@@ -0,0 +1,6 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "False"
+}
diff --git a/.kokoro/samples/python3.10/presubmit.cfg b/.kokoro/samples/python3.10/presubmit.cfg
new file mode 100644
index 0000000..a1c8d97
--- /dev/null
+++ b/.kokoro/samples/python3.10/presubmit.cfg
@@ -0,0 +1,6 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "True"
+}
\ No newline at end of file
diff --git a/.kokoro/samples/python3.6/common.cfg b/.kokoro/samples/python3.6/common.cfg
index 32475d7..5633523 100644
--- a/.kokoro/samples/python3.6/common.cfg
+++ b/.kokoro/samples/python3.6/common.cfg
@@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
# Use the trampoline script to run in docker.
-build_file: "python-binary-authorization/.kokoro/trampoline.sh"
\ No newline at end of file
+build_file: "python-binary-authorization/.kokoro/trampoline_v2.sh"
\ No newline at end of file
diff --git a/.kokoro/samples/python3.6/periodic.cfg b/.kokoro/samples/python3.6/periodic.cfg
index 50fec96..71cd1e5 100644
--- a/.kokoro/samples/python3.6/periodic.cfg
+++ b/.kokoro/samples/python3.6/periodic.cfg
@@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
-}
\ No newline at end of file
+}
diff --git a/.kokoro/samples/python3.7/common.cfg b/.kokoro/samples/python3.7/common.cfg
index 8a41266..916e66b 100644
--- a/.kokoro/samples/python3.7/common.cfg
+++ b/.kokoro/samples/python3.7/common.cfg
@@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
# Use the trampoline script to run in docker.
-build_file: "python-binary-authorization/.kokoro/trampoline.sh"
\ No newline at end of file
+build_file: "python-binary-authorization/.kokoro/trampoline_v2.sh"
\ No newline at end of file
diff --git a/.kokoro/samples/python3.7/periodic.cfg b/.kokoro/samples/python3.7/periodic.cfg
index 50fec96..71cd1e5 100644
--- a/.kokoro/samples/python3.7/periodic.cfg
+++ b/.kokoro/samples/python3.7/periodic.cfg
@@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
-}
\ No newline at end of file
+}
diff --git a/.kokoro/samples/python3.8/common.cfg b/.kokoro/samples/python3.8/common.cfg
index 432d880..c624c42 100644
--- a/.kokoro/samples/python3.8/common.cfg
+++ b/.kokoro/samples/python3.8/common.cfg
@@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
# Use the trampoline script to run in docker.
-build_file: "python-binary-authorization/.kokoro/trampoline.sh"
\ No newline at end of file
+build_file: "python-binary-authorization/.kokoro/trampoline_v2.sh"
\ No newline at end of file
diff --git a/.kokoro/samples/python3.8/periodic.cfg b/.kokoro/samples/python3.8/periodic.cfg
index 50fec96..71cd1e5 100644
--- a/.kokoro/samples/python3.8/periodic.cfg
+++ b/.kokoro/samples/python3.8/periodic.cfg
@@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
-}
\ No newline at end of file
+}
diff --git a/.kokoro/samples/python3.9/common.cfg b/.kokoro/samples/python3.9/common.cfg
index ea033d6..920862c 100644
--- a/.kokoro/samples/python3.9/common.cfg
+++ b/.kokoro/samples/python3.9/common.cfg
@@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
# Use the trampoline script to run in docker.
-build_file: "python-binary-authorization/.kokoro/trampoline.sh"
\ No newline at end of file
+build_file: "python-binary-authorization/.kokoro/trampoline_v2.sh"
\ No newline at end of file
diff --git a/.kokoro/samples/python3.9/periodic.cfg b/.kokoro/samples/python3.9/periodic.cfg
index 50fec96..71cd1e5 100644
--- a/.kokoro/samples/python3.9/periodic.cfg
+++ b/.kokoro/samples/python3.9/periodic.cfg
@@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
-}
\ No newline at end of file
+}
diff --git a/.kokoro/test-samples-against-head.sh b/.kokoro/test-samples-against-head.sh
index c581fea..ba3a707 100755
--- a/.kokoro/test-samples-against-head.sh
+++ b/.kokoro/test-samples-against-head.sh
@@ -23,6 +23,4 @@ set -eo pipefail
# Enables `**` to include files nested inside sub-folders
shopt -s globstar
-cd github/python-binary-authorization
-
exec .kokoro/test-samples-impl.sh
diff --git a/.kokoro/test-samples.sh b/.kokoro/test-samples.sh
index fa4baf8..11c042d 100755
--- a/.kokoro/test-samples.sh
+++ b/.kokoro/test-samples.sh
@@ -24,8 +24,6 @@ set -eo pipefail
# Enables `**` to include files nested inside sub-folders
shopt -s globstar
-cd github/python-binary-authorization
-
# Run periodic samples tests at latest release
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
# preserving the test runner implementation.
diff --git a/.repo-metadata.json b/.repo-metadata.json
index b43d7e5..202bf18 100644
--- a/.repo-metadata.json
+++ b/.repo-metadata.json
@@ -10,5 +10,6 @@
"repo": "googleapis/python-binary-authorization",
"distribution_name": "google-cloud-binary-authorization",
"api_id": "binaryauthorization.googleapis.com",
- "codeowner_team": "@googleapis/cicd"
- }
+ "codeowner_team": "@googleapis/cicd",
+ "default_version": "v1"
+}
diff --git a/.trampolinerc b/.trampolinerc
index 383b6ec..0eee72a 100644
--- a/.trampolinerc
+++ b/.trampolinerc
@@ -16,15 +16,26 @@
# Add required env vars here.
required_envvars+=(
- "STAGING_BUCKET"
- "V2_STAGING_BUCKET"
)
# Add env vars which are passed down into the container here.
pass_down_envvars+=(
+ "NOX_SESSION"
+ ###############
+ # Docs builds
+ ###############
"STAGING_BUCKET"
"V2_STAGING_BUCKET"
- "NOX_SESSION"
+ ##################
+ # Samples builds
+ ##################
+ "INSTALL_LIBRARY_FROM_SOURCE"
+ "RUN_TESTS_SESSION"
+ "BUILD_SPECIFIC_GCLOUD_PROJECT"
+ # Target directories.
+ "RUN_TESTS_DIRS"
+ # The nox session to run.
+ "RUN_TESTS_SESSION"
)
# Prevent unintentional override on the default image.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1626de..94e0d23 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog
+## [0.5.0](https://www.github.com/googleapis/python-binary-authorization/compare/v0.4.1...v0.5.0) (2021-10-08)
+
+
+### Features
+
+* add context manager support in client ([#84](https://www.github.com/googleapis/python-binary-authorization/issues/84)) ([0991f56](https://www.github.com/googleapis/python-binary-authorization/commit/0991f564af01dc8b0172693290a9aba566035848))
+
### [0.4.1](https://www.github.com/googleapis/python-binary-authorization/compare/v0.4.0...v0.4.1) (2021-09-30)
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 33e1d4c..5ca20bc 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -22,7 +22,7 @@ In order to add a feature:
documentation.
- The feature must work fully on the following CPython versions:
- 3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows.
+ 3.6, 3.7, 3.8, 3.9 and 3.10 on both UNIX and Windows.
- The feature must not add unnecessary dependencies (where
"unnecessary" is of course subjective, but new dependencies should
@@ -72,7 +72,7 @@ We use `nox `__ to instrument our tests.
- To run a single unit test::
- $ nox -s unit-3.9 -- -k
+ $ nox -s unit-3.10 -- -k
.. note::
@@ -225,11 +225,13 @@ We support:
- `Python 3.7`_
- `Python 3.8`_
- `Python 3.9`_
+- `Python 3.10`_
.. _Python 3.6: https://docs.python.org/3.6/
.. _Python 3.7: https://docs.python.org/3.7/
.. _Python 3.8: https://docs.python.org/3.8/
.. _Python 3.9: https://docs.python.org/3.9/
+.. _Python 3.10: https://docs.python.org/3.10/
Supported versions can be found in our ``noxfile.py`` `config`_.
diff --git a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py
index bbc4840..7b993e4 100644
--- a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py
+++ b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py
@@ -826,6 +826,12 @@ async def delete_attestor(
request, retry=retry, timeout=timeout, metadata=metadata,
)
+ async def __aenter__(self):
+ return self
+
+ async def __aexit__(self, exc_type, exc, tb):
+ await self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py
index 0530a02..0c21b73 100644
--- a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py
+++ b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py
@@ -369,10 +369,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
- always_use_jwt_access=(
- Transport == type(self).get_transport_class("grpc")
- or Transport == type(self).get_transport_class("grpc_asyncio")
- ),
+ always_use_jwt_access=True,
)
def get_policy(
@@ -956,6 +953,19 @@ def delete_attestor(
request, retry=retry, timeout=timeout, metadata=metadata,
)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ """Releases underlying transport's resources.
+
+ .. warning::
+ ONLY use as a context manager if the transport is NOT shared
+ with other clients! Exiting the with block will CLOSE the transport
+ and may cause errors in other clients!
+ """
+ self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py
index 18b3d96..f9205f3 100644
--- a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py
+++ b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py
@@ -251,6 +251,15 @@ 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!
+ """
+ raise NotImplementedError()
+
@property
def get_policy(
self,
diff --git a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py
index 27ec06e..f8b05ff 100644
--- a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py
+++ b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py
@@ -450,5 +450,8 @@ def delete_attestor(
)
return self._stubs["delete_attestor"]
+ def close(self):
+ self.grpc_channel.close()
+
__all__ = ("BinauthzManagementServiceV1GrpcTransport",)
diff --git a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py
index bb5c5b6..db886fe 100644
--- a/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py
+++ b/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py
@@ -459,5 +459,8 @@ def delete_attestor(
)
return self._stubs["delete_attestor"]
+ def close(self):
+ return self.grpc_channel.close()
+
__all__ = ("BinauthzManagementServiceV1GrpcAsyncIOTransport",)
diff --git a/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py b/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py
index 75c81fc..e68b6ea 100644
--- a/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py
+++ b/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py
@@ -235,6 +235,12 @@ async def get_system_policy(
# Done; return the response.
return response
+ async def __aenter__(self):
+ return self
+
+ async def __aexit__(self, exc_type, exc, tb):
+ await self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py b/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py
index 49d6573..003e139 100644
--- a/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py
+++ b/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py
@@ -340,10 +340,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
- always_use_jwt_access=(
- Transport == type(self).get_transport_class("grpc")
- or Transport == type(self).get_transport_class("grpc_asyncio")
- ),
+ always_use_jwt_access=True,
)
def get_system_policy(
@@ -419,6 +416,19 @@ def get_system_policy(
# Done; return the response.
return response
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ """Releases underlying transport's resources.
+
+ .. warning::
+ ONLY use as a context manager if the transport is NOT shared
+ with other clients! Exiting the with block will CLOSE the transport
+ and may cause errors in other clients!
+ """
+ self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py b/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py
index 78d44f8..37e4e41 100644
--- a/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py
+++ b/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py
@@ -160,6 +160,15 @@ 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!
+ """
+ raise NotImplementedError()
+
@property
def get_system_policy(
self,
diff --git a/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py b/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py
index fa5d87e..6697e56 100644
--- a/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py
+++ b/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py
@@ -253,5 +253,8 @@ def get_system_policy(
)
return self._stubs["get_system_policy"]
+ def close(self):
+ self.grpc_channel.close()
+
__all__ = ("SystemPolicyV1GrpcTransport",)
diff --git a/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py
index 92c7b06..ec20312 100644
--- a/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py
+++ b/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py
@@ -256,5 +256,8 @@ def get_system_policy(
)
return self._stubs["get_system_policy"]
+ def close(self):
+ return self.grpc_channel.close()
+
__all__ = ("SystemPolicyV1GrpcAsyncIOTransport",)
diff --git a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py
index 5c55468..5a2600c 100644
--- a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py
+++ b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py
@@ -209,6 +209,12 @@ async def validate_attestation_occurrence(
# Done; return the response.
return response
+ async def __aenter__(self):
+ return self
+
+ async def __aexit__(self, exc_type, exc, tb):
+ await self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py
index 8bdd2ae..75b7af1 100644
--- a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py
+++ b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py
@@ -329,10 +329,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
- always_use_jwt_access=(
- Transport == type(self).get_transport_class("grpc")
- or Transport == type(self).get_transport_class("grpc_asyncio")
- ),
+ always_use_jwt_access=True,
)
def validate_attestation_occurrence(
@@ -388,6 +385,19 @@ def validate_attestation_occurrence(
# Done; return the response.
return response
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ """Releases underlying transport's resources.
+
+ .. warning::
+ ONLY use as a context manager if the transport is NOT shared
+ with other clients! Exiting the with block will CLOSE the transport
+ and may cause errors in other clients!
+ """
+ self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py
index 8460bfc..31133d4 100644
--- a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py
+++ b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py
@@ -161,6 +161,15 @@ 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!
+ """
+ raise NotImplementedError()
+
@property
def validate_attestation_occurrence(
self,
diff --git a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py
index 4aec7f7..96c2474 100644
--- a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py
+++ b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py
@@ -258,5 +258,8 @@ def validate_attestation_occurrence(
)
return self._stubs["validate_attestation_occurrence"]
+ def close(self):
+ self.grpc_channel.close()
+
__all__ = ("ValidationHelperV1GrpcTransport",)
diff --git a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py
index 8d5ea0d..5d33588 100644
--- a/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py
+++ b/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py
@@ -261,5 +261,8 @@ def validate_attestation_occurrence(
)
return self._stubs["validate_attestation_occurrence"]
+ def close(self):
+ return self.grpc_channel.close()
+
__all__ = ("ValidationHelperV1GrpcAsyncIOTransport",)
diff --git a/google/cloud/binaryauthorization_v1/types/service.py b/google/cloud/binaryauthorization_v1/types/service.py
index 862610b..67832b7 100644
--- a/google/cloud/binaryauthorization_v1/types/service.py
+++ b/google/cloud/binaryauthorization_v1/types/service.py
@@ -39,6 +39,7 @@
class GetPolicyRequest(proto.Message):
r"""Request message for [BinauthzManagementService.GetPolicy][].
+
Attributes:
name (str):
Required. The resource name of the
@@ -51,6 +52,7 @@ class GetPolicyRequest(proto.Message):
class UpdatePolicyRequest(proto.Message):
r"""Request message for [BinauthzManagementService.UpdatePolicy][].
+
Attributes:
policy (google.cloud.binaryauthorization_v1.types.Policy):
Required. A new or updated
@@ -66,6 +68,7 @@ class UpdatePolicyRequest(proto.Message):
class CreateAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.CreateAttestor][].
+
Attributes:
parent (str):
Required. The parent of this
@@ -90,6 +93,7 @@ class CreateAttestorRequest(proto.Message):
class GetAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.GetAttestor][].
+
Attributes:
name (str):
Required. The name of the
@@ -102,6 +106,7 @@ class GetAttestorRequest(proto.Message):
class UpdateAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.UpdateAttestor][].
+
Attributes:
attestor (google.cloud.binaryauthorization_v1.types.Attestor):
Required. The updated
@@ -117,6 +122,7 @@ class UpdateAttestorRequest(proto.Message):
class ListAttestorsRequest(proto.Message):
r"""Request message for [BinauthzManagementService.ListAttestors][].
+
Attributes:
parent (str):
Required. The resource name of the project associated with
@@ -142,6 +148,7 @@ class ListAttestorsRequest(proto.Message):
class ListAttestorsResponse(proto.Message):
r"""Response message for [BinauthzManagementService.ListAttestors][].
+
Attributes:
attestors (Sequence[google.cloud.binaryauthorization_v1.types.Attestor]):
The list of
@@ -166,6 +173,7 @@ def raw_page(self):
class DeleteAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.DeleteAttestor][].
+
Attributes:
name (str):
Required. The name of the
@@ -178,6 +186,7 @@ class DeleteAttestorRequest(proto.Message):
class GetSystemPolicyRequest(proto.Message):
r"""Request to read the current system policy.
+
Attributes:
name (str):
Required. The resource name, in the format
diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py
index 6df73a1..ffb2c15 100644
--- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py
+++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py
@@ -837,6 +837,12 @@ async def delete_attestor(
request, retry=retry, timeout=timeout, metadata=metadata,
)
+ async def __aenter__(self):
+ return self
+
+ async def __aexit__(self, exc_type, exc, tb):
+ await self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py
index 610f619..f2dde39 100644
--- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py
+++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py
@@ -374,10 +374,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
- always_use_jwt_access=(
- Transport == type(self).get_transport_class("grpc")
- or Transport == type(self).get_transport_class("grpc_asyncio")
- ),
+ always_use_jwt_access=True,
)
def get_policy(
@@ -965,6 +962,19 @@ def delete_attestor(
request, retry=retry, timeout=timeout, metadata=metadata,
)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ """Releases underlying transport's resources.
+
+ .. warning::
+ ONLY use as a context manager if the transport is NOT shared
+ with other clients! Exiting the with block will CLOSE the transport
+ and may cause errors in other clients!
+ """
+ self.transport.close()
+
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py
index 6e334f8..dcc955d 100644
--- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py
+++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py
@@ -251,6 +251,15 @@ 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!
+ """
+ raise NotImplementedError()
+
@property
def get_policy(
self,
diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py
index 6bb8997..09ef48c 100644
--- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py
+++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py
@@ -456,5 +456,8 @@ def delete_attestor(
)
return self._stubs["delete_attestor"]
+ def close(self):
+ self.grpc_channel.close()
+
__all__ = ("BinauthzManagementServiceV1Beta1GrpcTransport",)
diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py
index 411ed69..cf2fcd7 100644
--- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py
+++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py
@@ -463,5 +463,8 @@ def delete_attestor(
)
return self._stubs["delete_attestor"]
+ def close(self):
+ return self.grpc_channel.close()
+
__all__ = ("BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport",)
diff --git a/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py b/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py
index 4a1818a..2fb7c00 100644
--- a/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py
+++ b/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py
@@ -26,6 +26,7 @@
class ContinuousValidationEvent(proto.Message):
r"""Represents an auditing event from Continuous Validation.
+
Attributes:
pod_event (google.cloud.binaryauthorization_v1beta1.types.ContinuousValidationEvent.ContinuousValidationPodEvent):
Pod event.
@@ -35,6 +36,7 @@ class ContinuousValidationEvent(proto.Message):
class ContinuousValidationPodEvent(proto.Message):
r"""An auditing event for one Pod.
+
Attributes:
pod (str):
The name of the Pod.
@@ -56,6 +58,7 @@ class PolicyConformanceVerdict(proto.Enum):
class ImageDetails(proto.Message):
r"""Container image with auditing details.
+
Attributes:
image (str):
The name of the image.
diff --git a/google/cloud/binaryauthorization_v1beta1/types/service.py b/google/cloud/binaryauthorization_v1beta1/types/service.py
index ccf4e94..f4bc93d 100644
--- a/google/cloud/binaryauthorization_v1beta1/types/service.py
+++ b/google/cloud/binaryauthorization_v1beta1/types/service.py
@@ -35,6 +35,7 @@
class GetPolicyRequest(proto.Message):
r"""Request message for [BinauthzManagementService.GetPolicy][].
+
Attributes:
name (str):
Required. The resource name of the
@@ -47,6 +48,7 @@ class GetPolicyRequest(proto.Message):
class UpdatePolicyRequest(proto.Message):
r"""Request message for [BinauthzManagementService.UpdatePolicy][].
+
Attributes:
policy (google.cloud.binaryauthorization_v1beta1.types.Policy):
Required. A new or updated
@@ -62,6 +64,7 @@ class UpdatePolicyRequest(proto.Message):
class CreateAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.CreateAttestor][].
+
Attributes:
parent (str):
Required. The parent of this
@@ -86,6 +89,7 @@ class CreateAttestorRequest(proto.Message):
class GetAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.GetAttestor][].
+
Attributes:
name (str):
Required. The name of the
@@ -98,6 +102,7 @@ class GetAttestorRequest(proto.Message):
class UpdateAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.UpdateAttestor][].
+
Attributes:
attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor):
Required. The updated
@@ -113,6 +118,7 @@ class UpdateAttestorRequest(proto.Message):
class ListAttestorsRequest(proto.Message):
r"""Request message for [BinauthzManagementService.ListAttestors][].
+
Attributes:
parent (str):
Required. The resource name of the project associated with
@@ -138,6 +144,7 @@ class ListAttestorsRequest(proto.Message):
class ListAttestorsResponse(proto.Message):
r"""Response message for [BinauthzManagementService.ListAttestors][].
+
Attributes:
attestors (Sequence[google.cloud.binaryauthorization_v1beta1.types.Attestor]):
The list of
@@ -162,6 +169,7 @@ def raw_page(self):
class DeleteAttestorRequest(proto.Message):
r"""Request message for [BinauthzManagementService.DeleteAttestor][].
+
Attributes:
name (str):
Required. The name of the
diff --git a/noxfile.py b/noxfile.py
index 2bf3ffd..672b28d 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -29,7 +29,7 @@
DEFAULT_PYTHON_VERSION = "3.8"
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"]
-UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"]
+UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
diff --git a/setup.py b/setup.py
index 3902027..b15ef2e 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,7 @@
import setuptools # type: ignore
-version = "0.4.1"
+version = "0.5.0"
package_root = os.path.abspath(os.path.dirname(__file__))
diff --git a/testing/constraints-3.10.txt b/testing/constraints-3.10.txt
new file mode 100644
index 0000000..e69de29
diff --git a/testing/constraints-3.11.txt b/testing/constraints-3.11.txt
new file mode 100644
index 0000000..e69de29
diff --git a/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py b/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py
index bc3bf1c..fdd3374 100644
--- a/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py
+++ b/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py
@@ -29,6 +29,7 @@
from google.api_core import gapic_v1
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
+from google.api_core import path_template
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.binaryauthorization_v1.services.binauthz_management_service_v1 import (
@@ -2308,6 +2309,9 @@ def test_binauthz_management_service_v1_base_transport():
with pytest.raises(NotImplementedError):
getattr(transport, method)(request=object())
+ with pytest.raises(NotImplementedError):
+ transport.close()
+
@requires_google_auth_gte_1_25_0
def test_binauthz_management_service_v1_base_transport_with_credentials_file():
@@ -2819,3 +2823,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
)
prep.assert_called_once_with(client_info)
+
+
+@pytest.mark.asyncio
+async def test_transport_close_async():
+ client = BinauthzManagementServiceV1AsyncClient(
+ credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio",
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, "grpc_channel")), "close"
+ ) as close:
+ async with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_transport_close():
+ transports = {
+ "grpc": "_grpc_channel",
+ }
+
+ for transport, close_name in transports.items():
+ client = BinauthzManagementServiceV1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, close_name)), "close"
+ ) as close:
+ with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_client_ctx():
+ transports = [
+ "grpc",
+ ]
+ for transport in transports:
+ client = BinauthzManagementServiceV1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ # Test client calls underlying transport.
+ with mock.patch.object(type(client.transport), "close") as close:
+ close.assert_not_called()
+ with client:
+ pass
+ close.assert_called()
diff --git a/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py b/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py
index 546b2a7..5cbd073 100644
--- a/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py
+++ b/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py
@@ -29,6 +29,7 @@
from google.api_core import gapic_v1
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
+from google.api_core import path_template
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.binaryauthorization_v1.services.system_policy_v1 import (
@@ -830,6 +831,9 @@ def test_system_policy_v1_base_transport():
with pytest.raises(NotImplementedError):
getattr(transport, method)(request=object())
+ with pytest.raises(NotImplementedError):
+ transport.close()
+
@requires_google_auth_gte_1_25_0
def test_system_policy_v1_base_transport_with_credentials_file():
@@ -1306,3 +1310,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
)
prep.assert_called_once_with(client_info)
+
+
+@pytest.mark.asyncio
+async def test_transport_close_async():
+ client = SystemPolicyV1AsyncClient(
+ credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio",
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, "grpc_channel")), "close"
+ ) as close:
+ async with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_transport_close():
+ transports = {
+ "grpc": "_grpc_channel",
+ }
+
+ for transport, close_name in transports.items():
+ client = SystemPolicyV1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, close_name)), "close"
+ ) as close:
+ with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_client_ctx():
+ transports = [
+ "grpc",
+ ]
+ for transport in transports:
+ client = SystemPolicyV1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ # Test client calls underlying transport.
+ with mock.patch.object(type(client.transport), "close") as close:
+ close.assert_not_called()
+ with client:
+ pass
+ close.assert_called()
diff --git a/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py b/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py
index 04296e1..050220c 100644
--- a/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py
+++ b/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py
@@ -29,6 +29,7 @@
from google.api_core import gapic_v1
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
+from google.api_core import path_template
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.binaryauthorization_v1.services.validation_helper_v1 import (
@@ -772,6 +773,9 @@ def test_validation_helper_v1_base_transport():
with pytest.raises(NotImplementedError):
getattr(transport, method)(request=object())
+ with pytest.raises(NotImplementedError):
+ transport.close()
+
@requires_google_auth_gte_1_25_0
def test_validation_helper_v1_base_transport_with_credentials_file():
@@ -1232,3 +1236,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
)
prep.assert_called_once_with(client_info)
+
+
+@pytest.mark.asyncio
+async def test_transport_close_async():
+ client = ValidationHelperV1AsyncClient(
+ credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio",
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, "grpc_channel")), "close"
+ ) as close:
+ async with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_transport_close():
+ transports = {
+ "grpc": "_grpc_channel",
+ }
+
+ for transport, close_name in transports.items():
+ client = ValidationHelperV1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, close_name)), "close"
+ ) as close:
+ with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_client_ctx():
+ transports = [
+ "grpc",
+ ]
+ for transport in transports:
+ client = ValidationHelperV1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ # Test client calls underlying transport.
+ with mock.patch.object(type(client.transport), "close") as close:
+ close.assert_not_called()
+ with client:
+ pass
+ close.assert_called()
diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py
index 7bbe748..e553978 100644
--- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py
+++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py
@@ -29,6 +29,7 @@
from google.api_core import gapic_v1
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
+from google.api_core import path_template
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1 import (
@@ -2327,6 +2328,9 @@ def test_binauthz_management_service_v1_beta1_base_transport():
with pytest.raises(NotImplementedError):
getattr(transport, method)(request=object())
+ with pytest.raises(NotImplementedError):
+ transport.close()
+
@requires_google_auth_gte_1_25_0
def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file():
@@ -2846,3 +2850,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
)
prep.assert_called_once_with(client_info)
+
+
+@pytest.mark.asyncio
+async def test_transport_close_async():
+ client = BinauthzManagementServiceV1Beta1AsyncClient(
+ credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio",
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, "grpc_channel")), "close"
+ ) as close:
+ async with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_transport_close():
+ transports = {
+ "grpc": "_grpc_channel",
+ }
+
+ for transport, close_name in transports.items():
+ client = BinauthzManagementServiceV1Beta1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ with mock.patch.object(
+ type(getattr(client.transport, close_name)), "close"
+ ) as close:
+ with client:
+ close.assert_not_called()
+ close.assert_called_once()
+
+
+def test_client_ctx():
+ transports = [
+ "grpc",
+ ]
+ for transport in transports:
+ client = BinauthzManagementServiceV1Beta1Client(
+ credentials=ga_credentials.AnonymousCredentials(), transport=transport
+ )
+ # Test client calls underlying transport.
+ with mock.patch.object(type(client.transport), "close") as close:
+ close.assert_not_called()
+ with client:
+ pass
+ close.assert_called()