From 8a74b9cefb80ffd1a5b55ce08d87fd80ecbe0052 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 7 Oct 2021 00:40:33 +0000 Subject: [PATCH] feat: add context manager support in client (#104) - [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: https://github.com/googleapis/googleapis/commit/787f8c9a731f44e74a90b9847d48659ca9462d10 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9 --- .../transcoder_service/async_client.py | 6 +++ .../services/transcoder_service/client.py | 18 +++++-- .../transcoder_service/transports/base.py | 9 ++++ .../transcoder_service/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../video/transcoder_v1/types/resources.py | 27 ++++++++++ .../video/transcoder_v1/types/services.py | 9 ++++ .../transcoder_service/async_client.py | 6 +++ .../services/transcoder_service/client.py | 18 +++++-- .../transcoder_service/transports/base.py | 9 ++++ .../transcoder_service/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../transcoder_v1beta1/types/resources.py | 33 ++++++++++++ .../transcoder_v1beta1/types/services.py | 9 ++++ .../transcoder_v1/test_transcoder_service.py | 50 +++++++++++++++++++ .../test_transcoder_service.py | 50 +++++++++++++++++++ 16 files changed, 248 insertions(+), 8 deletions(-) diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/async_client.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/async_client.py index 5d129e79edfa..d7cce70885e7 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/async_client.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/async_client.py @@ -776,6 +776,12 @@ async def delete_job_template( 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/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/client.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/client.py index f2c66a9f6cca..00a223534d3f 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/client.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/client.py @@ -372,10 +372,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 create_job( @@ -979,6 +976,19 @@ def delete_job_template( 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/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/base.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/base.py index c7755d7fac8a..cf9d64611568 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/base.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/base.py @@ -182,6 +182,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 create_job( self, diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc.py index 4853aaceab8f..457c5af24330 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc.py @@ -437,5 +437,8 @@ def delete_job_template( ) return self._stubs["delete_job_template"] + def close(self): + self.grpc_channel.close() + __all__ = ("TranscoderServiceGrpcTransport",) diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc_asyncio.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc_asyncio.py index ae4830b6aec1..512ba3729967 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc_asyncio.py @@ -446,5 +446,8 @@ def delete_job_template( ) return self._stubs["delete_job_template"] + def close(self): + return self.grpc_channel.close() + __all__ = ("TranscoderServiceGrpcAsyncIOTransport",) diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/resources.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/resources.py index e3ad7e595297..2bd732885ced 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/resources.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/resources.py @@ -47,6 +47,7 @@ class Job(proto.Message): r"""Transcoding job resource. + Attributes: name (str): The resource name of the job. Format: @@ -123,6 +124,7 @@ class ProcessingState(proto.Enum): class JobTemplate(proto.Message): r"""Transcoding job template resource. + Attributes: name (str): The resource name of the job template. Format: @@ -137,6 +139,7 @@ class JobTemplate(proto.Message): class JobConfig(proto.Message): r"""Job configuration + Attributes: inputs (Sequence[google.cloud.video.transcoder_v1.types.Input]): List of input assets stored in Cloud Storage. @@ -182,6 +185,7 @@ class JobConfig(proto.Message): class Input(proto.Message): r"""Input asset. + Attributes: key (str): A unique key for this input. Must be @@ -205,6 +209,7 @@ class Input(proto.Message): class Output(proto.Message): r"""Location of output file(s) in a Cloud Storage bucket. + Attributes: uri (str): URI for the output file(s). For example, @@ -217,6 +222,7 @@ class Output(proto.Message): class EditAtom(proto.Message): r"""Edit atom. + Attributes: key (str): A unique key for this atom. Must be specified @@ -246,6 +252,7 @@ class EditAtom(proto.Message): class AdBreak(proto.Message): r"""Ad break. + Attributes: start_time_offset (google.protobuf.duration_pb2.Duration): Start time in seconds for the ad break, relative to the @@ -288,6 +295,7 @@ class ElementaryStream(proto.Message): class MuxStream(proto.Message): r"""Multiplexing settings for output stream. + Attributes: key (str): A unique key for this multiplexed stream. HLS media @@ -326,6 +334,7 @@ class MuxStream(proto.Message): class Manifest(proto.Message): r"""Manifest configuration. + Attributes: file_name (str): The name of the generated file. The default is ``manifest`` @@ -355,6 +364,7 @@ class ManifestType(proto.Enum): class PubsubDestination(proto.Message): r"""A Pub/Sub destination. + Attributes: topic (str): The name of the Pub/Sub topic to publish job completion @@ -454,6 +464,7 @@ class SpriteSheet(proto.Message): class Overlay(proto.Message): r"""Overlay configuration. + Attributes: image (google.cloud.video.transcoder_v1.types.Overlay.Image): Image overlay. @@ -470,6 +481,7 @@ class FadeType(proto.Enum): class NormalizedCoordinate(proto.Message): r"""2D normalized coordinates. Default: ``{0.0, 0.0}`` + Attributes: x (float): Normalized x coordinate. @@ -482,6 +494,7 @@ class NormalizedCoordinate(proto.Message): class Image(proto.Message): r"""Overlaid jpeg image. + Attributes: uri (str): Required. URI of the JPEG image in Cloud Storage. For @@ -507,6 +520,7 @@ class Image(proto.Message): class AnimationStatic(proto.Message): r"""Display static overlay object. + Attributes: xy (google.cloud.video.transcoder_v1.types.Overlay.NormalizedCoordinate): Normalized coordinates based on output video resolution. @@ -529,6 +543,7 @@ class AnimationStatic(proto.Message): class AnimationFade(proto.Message): r"""Display overlay object with fade animation. + Attributes: fade_type (google.cloud.video.transcoder_v1.types.Overlay.FadeType): Required. Type of fade animation: ``FADE_IN`` or @@ -576,6 +591,7 @@ class AnimationEnd(proto.Message): class Animation(proto.Message): r"""Animation types. + Attributes: animation_static (google.cloud.video.transcoder_v1.types.Overlay.AnimationStatic): Display static overlay object. @@ -610,6 +626,7 @@ class Animation(proto.Message): class PreprocessingConfig(proto.Message): r"""Preprocessing configurations. + Attributes: color (google.cloud.video.transcoder_v1.types.PreprocessingConfig.Color): Color preprocessing configuration. @@ -627,6 +644,7 @@ class PreprocessingConfig(proto.Message): class Color(proto.Message): r"""Color preprocessing configuration. + Attributes: saturation (float): Control color saturation of the video. Enter @@ -651,6 +669,7 @@ class Color(proto.Message): class Denoise(proto.Message): r"""Denoise preprocessing configuration. + Attributes: strength (float): Set strength of the denoise. Enter a value @@ -671,6 +690,7 @@ class Denoise(proto.Message): class Deblock(proto.Message): r"""Deblock preprocessing configuration. + Attributes: strength (float): Set strength of the deblocker. Enter a value @@ -686,6 +706,7 @@ class Deblock(proto.Message): class Audio(proto.Message): r"""Audio preprocessing configuration. + Attributes: lufs (float): Specify audio loudness normalization in loudness units @@ -772,6 +793,7 @@ class Pad(proto.Message): class VideoStream(proto.Message): r"""Video stream resource. + Attributes: h264 (google.cloud.video.transcoder_v1.types.VideoStream.H264CodecSettings): H264 codec settings. @@ -783,6 +805,7 @@ class VideoStream(proto.Message): class H264CodecSettings(proto.Message): r"""H264 codec settings. + Attributes: width_pixels (int): The width of the video in pixels. Must be an @@ -931,6 +954,7 @@ class H264CodecSettings(proto.Message): class H265CodecSettings(proto.Message): r"""H265 codec settings. + Attributes: width_pixels (int): The width of the video in pixels. Must be an @@ -1091,6 +1115,7 @@ class H265CodecSettings(proto.Message): class Vp9CodecSettings(proto.Message): r"""VP9 codec settings. + Attributes: width_pixels (int): The width of the video in pixels. Must be an @@ -1193,6 +1218,7 @@ class Vp9CodecSettings(proto.Message): class AudioStream(proto.Message): r"""Audio stream resource. + Attributes: codec (str): The codec for this audio stream. The default is ``aac``. @@ -1318,6 +1344,7 @@ class TextMapping(proto.Message): class SegmentSettings(proto.Message): r"""Segment settings for ``ts``, ``fmp4`` and ``vtt``. + Attributes: segment_duration (google.protobuf.duration_pb2.Duration): Duration of the segments in seconds. The default is diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/services.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/services.py index 835d31b4a828..4d67e835ca21 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/services.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1/types/services.py @@ -37,6 +37,7 @@ class CreateJobRequest(proto.Message): r"""Request message for ``TranscoderService.CreateJob``. + Attributes: parent (str): Required. The parent location to create and process this @@ -81,6 +82,7 @@ class ListJobsRequest(proto.Message): class GetJobRequest(proto.Message): r"""Request message for ``TranscoderService.GetJob``. + Attributes: name (str): Required. The name of the job to retrieve. Format: @@ -92,6 +94,7 @@ class GetJobRequest(proto.Message): class DeleteJobRequest(proto.Message): r"""Request message for ``TranscoderService.DeleteJob``. + Attributes: name (str): Required. The name of the job to delete. Format: @@ -108,6 +111,7 @@ class DeleteJobRequest(proto.Message): class ListJobsResponse(proto.Message): r"""Response message for ``TranscoderService.ListJobs``. + Attributes: jobs (Sequence[google.cloud.video.transcoder_v1.types.Job]): List of jobs in the specified region. @@ -128,6 +132,7 @@ def raw_page(self): class CreateJobTemplateRequest(proto.Message): r"""Request message for ``TranscoderService.CreateJobTemplate``. + Attributes: parent (str): Required. The parent location to create this job template. @@ -152,6 +157,7 @@ class CreateJobTemplateRequest(proto.Message): class ListJobTemplatesRequest(proto.Message): r"""Request message for ``TranscoderService.ListJobTemplates``. + Attributes: parent (str): Required. The parent location from which to retrieve the @@ -180,6 +186,7 @@ class ListJobTemplatesRequest(proto.Message): class GetJobTemplateRequest(proto.Message): r"""Request message for ``TranscoderService.GetJobTemplate``. + Attributes: name (str): Required. The name of the job template to retrieve. Format: @@ -191,6 +198,7 @@ class GetJobTemplateRequest(proto.Message): class DeleteJobTemplateRequest(proto.Message): r"""Request message for ``TranscoderService.DeleteJobTemplate``. + Attributes: name (str): Required. The name of the job template to delete. @@ -207,6 +215,7 @@ class DeleteJobTemplateRequest(proto.Message): class ListJobTemplatesResponse(proto.Message): r"""Response message for ``TranscoderService.ListJobTemplates``. + Attributes: job_templates (Sequence[google.cloud.video.transcoder_v1.types.JobTemplate]): List of job templates in the specified diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/async_client.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/async_client.py index dbdfc0345eb0..192994984eb1 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/async_client.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/async_client.py @@ -775,6 +775,12 @@ async def delete_job_template( 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/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/client.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/client.py index 96e7c28e3b33..a6adc6f12380 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/client.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/client.py @@ -371,10 +371,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 create_job( @@ -978,6 +975,19 @@ def delete_job_template( 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/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/base.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/base.py index c938e19c68ea..35f9e9b67a3f 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/base.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/base.py @@ -182,6 +182,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 create_job( self, diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc.py index ef8e5c78f860..4f4f46f62fc8 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc.py @@ -437,5 +437,8 @@ def delete_job_template( ) return self._stubs["delete_job_template"] + def close(self): + self.grpc_channel.close() + __all__ = ("TranscoderServiceGrpcTransport",) diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc_asyncio.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc_asyncio.py index b66a617475d8..2b5324eb6142 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/services/transcoder_service/transports/grpc_asyncio.py @@ -446,5 +446,8 @@ def delete_job_template( ) return self._stubs["delete_job_template"] + def close(self): + return self.grpc_channel.close() + __all__ = ("TranscoderServiceGrpcAsyncIOTransport",) diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/resources.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/resources.py index ceeefa03b472..50341f1e7bfe 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/resources.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/resources.py @@ -49,6 +49,7 @@ class Job(proto.Message): r"""Transcoding job resource. + Attributes: name (str): The resource name of the job. Format: @@ -132,6 +133,7 @@ class ProcessingState(proto.Enum): class OriginUri(proto.Message): r"""The origin URI. + Attributes: hls (str): HLS manifest URI per @@ -171,6 +173,7 @@ class OriginUri(proto.Message): class JobTemplate(proto.Message): r"""Transcoding job template resource. + Attributes: name (str): The resource name of the job template. Format: @@ -185,6 +188,7 @@ class JobTemplate(proto.Message): class JobConfig(proto.Message): r"""Job configuration + Attributes: inputs (Sequence[google.cloud.video.transcoder_v1beta1.types.Input]): List of input assets stored in Cloud Storage. @@ -230,6 +234,7 @@ class JobConfig(proto.Message): class Input(proto.Message): r"""Input asset. + Attributes: key (str): A unique key for this input. Must be @@ -253,6 +258,7 @@ class Input(proto.Message): class Output(proto.Message): r"""Location of output file(s) in a Cloud Storage bucket. + Attributes: uri (str): URI for the output file(s). For example, @@ -265,6 +271,7 @@ class Output(proto.Message): class EditAtom(proto.Message): r"""Edit atom. + Attributes: key (str): A unique key for this atom. Must be specified @@ -294,6 +301,7 @@ class EditAtom(proto.Message): class AdBreak(proto.Message): r"""Ad break. + Attributes: start_time_offset (google.protobuf.duration_pb2.Duration): Start time in seconds for the ad break, relative to the @@ -336,6 +344,7 @@ class ElementaryStream(proto.Message): class MuxStream(proto.Message): r"""Multiplexing settings for output stream. + Attributes: key (str): A unique key for this multiplexed stream. HLS media @@ -377,6 +386,7 @@ class MuxStream(proto.Message): class Manifest(proto.Message): r"""Manifest configuration. + Attributes: file_name (str): The name of the generated file. The default is @@ -407,6 +417,7 @@ class ManifestType(proto.Enum): class PubsubDestination(proto.Message): r"""A Pub/Sub destination. + Attributes: topic (str): The name of the Pub/Sub topic to publish job completion @@ -506,6 +517,7 @@ class SpriteSheet(proto.Message): class Overlay(proto.Message): r"""Overlay configuration. + Attributes: image (google.cloud.video.transcoder_v1beta1.types.Overlay.Image): Image overlay. @@ -522,6 +534,7 @@ class FadeType(proto.Enum): class NormalizedCoordinate(proto.Message): r"""2D normalized coordinates. Default: ``{0.0, 0.0}`` + Attributes: x (float): Normalized x coordinate. @@ -534,6 +547,7 @@ class NormalizedCoordinate(proto.Message): class Image(proto.Message): r"""Overlaid jpeg image. + Attributes: uri (str): Required. URI of the JPEG image in Cloud Storage. For @@ -559,6 +573,7 @@ class Image(proto.Message): class AnimationStatic(proto.Message): r"""Display static overlay object. + Attributes: xy (google.cloud.video.transcoder_v1beta1.types.Overlay.NormalizedCoordinate): Normalized coordinates based on output video resolution. @@ -581,6 +596,7 @@ class AnimationStatic(proto.Message): class AnimationFade(proto.Message): r"""Display overlay object with fade animation. + Attributes: fade_type (google.cloud.video.transcoder_v1beta1.types.Overlay.FadeType): Required. Type of fade animation: ``FADE_IN`` or @@ -628,6 +644,7 @@ class AnimationEnd(proto.Message): class Animation(proto.Message): r"""Animation types. + Attributes: animation_static (google.cloud.video.transcoder_v1beta1.types.Overlay.AnimationStatic): Display static overlay object. @@ -662,6 +679,7 @@ class Animation(proto.Message): class PreprocessingConfig(proto.Message): r"""Preprocessing configurations. + Attributes: color (google.cloud.video.transcoder_v1beta1.types.PreprocessingConfig.Color): Color preprocessing configuration. @@ -679,6 +697,7 @@ class PreprocessingConfig(proto.Message): class Color(proto.Message): r"""Color preprocessing configuration. + Attributes: saturation (float): Control color saturation of the video. Enter @@ -703,6 +722,7 @@ class Color(proto.Message): class Denoise(proto.Message): r"""Denoise preprocessing configuration. + Attributes: strength (float): Set strength of the denoise. Enter a value @@ -723,6 +743,7 @@ class Denoise(proto.Message): class Deblock(proto.Message): r"""Deblock preprocessing configuration. + Attributes: strength (float): Set strength of the deblocker. Enter a value @@ -738,6 +759,7 @@ class Deblock(proto.Message): class Audio(proto.Message): r"""Audio preprocessing configuration. + Attributes: lufs (float): Specify audio loudness normalization in loudness units @@ -824,6 +846,7 @@ class Pad(proto.Message): class VideoStream(proto.Message): r"""Video stream resource. + Attributes: codec (str): Codec type. The following codecs are supported: @@ -978,6 +1001,7 @@ class VideoStream(proto.Message): class AudioStream(proto.Message): r"""Audio stream resource. + Attributes: codec (str): The codec for this audio stream. The default is ``"aac"``. @@ -1033,6 +1057,7 @@ class AudioAtom(proto.Message): class AudioChannel(proto.Message): r"""The audio channel. + Attributes: inputs (Sequence[google.cloud.video.transcoder_v1beta1.types.AudioStream.AudioAtom.AudioChannel.AudioChannelInput]): List of ``Job.inputs`` for this audio channel. @@ -1120,6 +1145,7 @@ class TextAtom(proto.Message): class TextInput(proto.Message): r"""Identifies which input file and track should be used. + Attributes: key (str): Required. The ``Input.key`` that identifies the input file. @@ -1143,6 +1169,7 @@ class TextInput(proto.Message): class SegmentSettings(proto.Message): r"""Segment settings for ``"ts"``, ``"fmp4"`` and ``"vtt"``. + Attributes: segment_duration (google.protobuf.duration_pb2.Duration): Duration of the segments in seconds. The default is @@ -1163,6 +1190,7 @@ class SegmentSettings(proto.Message): class Encryption(proto.Message): r"""Encryption settings. + Attributes: key (str): Required. 128 bit encryption key represented @@ -1181,6 +1209,7 @@ class Encryption(proto.Message): class Aes128Encryption(proto.Message): r"""Configuration for AES-128 encryption. + Attributes: key_uri (str): Required. URI of the key delivery service. @@ -1191,6 +1220,7 @@ class Aes128Encryption(proto.Message): class SampleAesEncryption(proto.Message): r"""Configuration for SAMPLE-AES encryption. + Attributes: key_uri (str): Required. URI of the key delivery service. @@ -1201,6 +1231,7 @@ class SampleAesEncryption(proto.Message): class MpegCommonEncryption(proto.Message): r"""Configuration for MPEG Common Encryption (MPEG-CENC). + Attributes: key_id (str): Required. 128 bit Key ID represented as @@ -1231,6 +1262,7 @@ class MpegCommonEncryption(proto.Message): class Progress(proto.Message): r"""Estimated fractional progress for each step, from ``0`` to ``1``. + Attributes: analyzed (float): Estimated fractional progress for ``analyzing`` step. @@ -1250,6 +1282,7 @@ class Progress(proto.Message): class FailureDetail(proto.Message): r"""Additional information about the reasons for the failure. + Attributes: description (str): A description of the failure. diff --git a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/services.py b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/services.py index 4255a536763b..fe23b03e4f0f 100644 --- a/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/services.py +++ b/packages/google-cloud-video-transcoder/google/cloud/video/transcoder_v1beta1/types/services.py @@ -37,6 +37,7 @@ class CreateJobRequest(proto.Message): r"""Request message for ``TranscoderService.CreateJob``. + Attributes: parent (str): Required. The parent location to create and process this @@ -72,6 +73,7 @@ class ListJobsRequest(proto.Message): class GetJobRequest(proto.Message): r"""Request message for ``TranscoderService.GetJob``. + Attributes: name (str): Required. The name of the job to retrieve. Format: @@ -83,6 +85,7 @@ class GetJobRequest(proto.Message): class DeleteJobRequest(proto.Message): r"""Request message for ``TranscoderService.DeleteJob``. + Attributes: name (str): Required. The name of the job to delete. Format: @@ -94,6 +97,7 @@ class DeleteJobRequest(proto.Message): class ListJobsResponse(proto.Message): r"""Response message for ``TranscoderService.ListJobs``. + Attributes: jobs (Sequence[google.cloud.video.transcoder_v1beta1.types.Job]): List of jobs in the specified region. @@ -111,6 +115,7 @@ def raw_page(self): class CreateJobTemplateRequest(proto.Message): r"""Request message for ``TranscoderService.CreateJobTemplate``. + Attributes: parent (str): Required. The parent location to create this job template. @@ -135,6 +140,7 @@ class CreateJobTemplateRequest(proto.Message): class ListJobTemplatesRequest(proto.Message): r"""Request message for ``TranscoderService.ListJobTemplates``. + Attributes: parent (str): Required. The parent location from which to retrieve the @@ -154,6 +160,7 @@ class ListJobTemplatesRequest(proto.Message): class GetJobTemplateRequest(proto.Message): r"""Request message for ``TranscoderService.GetJobTemplate``. + Attributes: name (str): Required. The name of the job template to retrieve. Format: @@ -165,6 +172,7 @@ class GetJobTemplateRequest(proto.Message): class DeleteJobTemplateRequest(proto.Message): r"""Request message for ``TranscoderService.DeleteJobTemplate``. + Attributes: name (str): Required. The name of the job template to delete. @@ -176,6 +184,7 @@ class DeleteJobTemplateRequest(proto.Message): class ListJobTemplatesResponse(proto.Message): r"""Response message for ``TranscoderService.ListJobTemplates``. + Attributes: job_templates (Sequence[google.cloud.video.transcoder_v1beta1.types.JobTemplate]): List of job templates in the specified diff --git a/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1/test_transcoder_service.py b/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1/test_transcoder_service.py index 8bb42afabbcc..44a2468eb535 100644 --- a/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1/test_transcoder_service.py +++ b/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1/test_transcoder_service.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.video.transcoder_v1.services.transcoder_service import ( @@ -2594,6 +2595,9 @@ def test_transcoder_service_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_transcoder_service_base_transport_with_credentials_file(): @@ -3100,3 +3104,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 = TranscoderServiceAsyncClient( + 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 = TranscoderServiceClient( + 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 = TranscoderServiceClient( + 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/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1beta1/test_transcoder_service.py b/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1beta1/test_transcoder_service.py index bece6f5763f1..83c15c4c25e6 100644 --- a/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1beta1/test_transcoder_service.py +++ b/packages/google-cloud-video-transcoder/tests/unit/gapic/transcoder_v1beta1/test_transcoder_service.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.video.transcoder_v1beta1.services.transcoder_service import ( @@ -2598,6 +2599,9 @@ def test_transcoder_service_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_transcoder_service_base_transport_with_credentials_file(): @@ -3104,3 +3108,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 = TranscoderServiceAsyncClient( + 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 = TranscoderServiceClient( + 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 = TranscoderServiceClient( + 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()