diff --git a/examples/python/interceptors/headers/header_manipulator_client_interceptor.py b/examples/python/interceptors/headers/header_manipulator_client_interceptor.py index ac7c605144f..89b1bef05fc 100644 --- a/examples/python/interceptors/headers/header_manipulator_client_interceptor.py +++ b/examples/python/interceptors/headers/header_manipulator_client_interceptor.py @@ -20,9 +20,10 @@ import generic_client_interceptor class _ClientCallDetails( - collections.namedtuple('_ClientCallDetails', - ('method', 'timeout', 'metadata', - 'credentials')), grpc.ClientCallDetails): + collections.namedtuple( + '_ClientCallDetails', + ('method', 'timeout', 'metadata', 'credentials')), + grpc.ClientCallDetails): pass @@ -33,7 +34,10 @@ def header_adder_interceptor(header, value): metadata = [] if client_call_details.metadata is not None: metadata = list(client_call_details.metadata) - metadata.append((header, value,)) + metadata.append(( + header, + value, + )) client_call_details = _ClientCallDetails( client_call_details.method, client_call_details.timeout, metadata, client_call_details.credentials) diff --git a/examples/python/multiplex/multiplex_client.py b/examples/python/multiplex/multiplex_client.py index 49713f35b7e..9baa10247d3 100644 --- a/examples/python/multiplex/multiplex_client.py +++ b/examples/python/multiplex/multiplex_client.py @@ -46,9 +46,9 @@ def guide_get_one_feature(route_guide_stub, point): def guide_get_feature(route_guide_stub): - guide_get_one_feature( - route_guide_stub, - route_guide_pb2.Point(latitude=409146138, longitude=-746188906)) + guide_get_one_feature(route_guide_stub, + route_guide_pb2.Point( + latitude=409146138, longitude=-746188906)) guide_get_one_feature(route_guide_stub, route_guide_pb2.Point(latitude=0, longitude=0)) @@ -101,8 +101,8 @@ def generate_messages(): def guide_route_chat(route_guide_stub): responses = route_guide_stub.RouteChat(generate_messages()) for response in responses: - print("Received message %s at %s" % - (response.message, response.location)) + print("Received message %s at %s" % (response.message, + response.location)) def run(): diff --git a/examples/python/multiplex/multiplex_server.py b/examples/python/multiplex/multiplex_server.py index e2ff671f972..70dec3c9390 100644 --- a/examples/python/multiplex/multiplex_server.py +++ b/examples/python/multiplex/multiplex_server.py @@ -124,8 +124,8 @@ def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) helloworld_pb2_grpc.add_GreeterServicer_to_server(_GreeterServicer(), server) - route_guide_pb2_grpc.add_RouteGuideServicer_to_server(_RouteGuideServicer(), - server) + route_guide_pb2_grpc.add_RouteGuideServicer_to_server( + _RouteGuideServicer(), server) server.add_insecure_port('[::]:50051') server.start() try: diff --git a/examples/python/multiplex/run_codegen.py b/examples/python/multiplex/run_codegen.py index d960c3cf161..be8915fe201 100644 --- a/examples/python/multiplex/run_codegen.py +++ b/examples/python/multiplex/run_codegen.py @@ -15,7 +15,17 @@ from grpc_tools import protoc -protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.', - '../../protos/helloworld.proto',)) -protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.', - '../../protos/route_guide.proto',)) +protoc.main(( + '', + '-I../../protos', + '--python_out=.', + '--grpc_python_out=.', + '../../protos/helloworld.proto', +)) +protoc.main(( + '', + '-I../../protos', + '--python_out=.', + '--grpc_python_out=.', + '../../protos/route_guide.proto', +)) diff --git a/examples/python/route_guide/route_guide_client.py b/examples/python/route_guide/route_guide_client.py index c9d0e96ad69..f2d4317ef10 100644 --- a/examples/python/route_guide/route_guide_client.py +++ b/examples/python/route_guide/route_guide_client.py @@ -43,8 +43,9 @@ def guide_get_one_feature(stub, point): def guide_get_feature(stub): - guide_get_one_feature( - stub, route_guide_pb2.Point(latitude=409146138, longitude=-746188906)) + guide_get_one_feature(stub, + route_guide_pb2.Point( + latitude=409146138, longitude=-746188906)) guide_get_one_feature(stub, route_guide_pb2.Point(latitude=0, longitude=0)) @@ -94,8 +95,8 @@ def generate_messages(): def guide_route_chat(stub): responses = stub.RouteChat(generate_messages()) for response in responses: - print("Received message %s at %s" % - (response.message, response.location)) + print("Received message %s at %s" % (response.message, + response.location)) def run(): diff --git a/examples/python/route_guide/route_guide_server.py b/examples/python/route_guide/route_guide_server.py index 46f3322a39b..f10008fdec6 100644 --- a/examples/python/route_guide/route_guide_server.py +++ b/examples/python/route_guide/route_guide_server.py @@ -113,8 +113,8 @@ class RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer): def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) - route_guide_pb2_grpc.add_RouteGuideServicer_to_server(RouteGuideServicer(), - server) + route_guide_pb2_grpc.add_RouteGuideServicer_to_server( + RouteGuideServicer(), server) server.add_insecure_port('[::]:50051') server.start() try: diff --git a/examples/python/route_guide/run_codegen.py b/examples/python/route_guide/run_codegen.py index 1ec7fcd51fc..8df562d3497 100644 --- a/examples/python/route_guide/run_codegen.py +++ b/examples/python/route_guide/run_codegen.py @@ -15,5 +15,10 @@ from grpc_tools import protoc -protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.', - '../../protos/route_guide.proto',)) +protoc.main(( + '', + '-I../../protos', + '--python_out=.', + '--grpc_python_out=.', + '../../protos/route_guide.proto', +)) diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 5f28e9101f6..4c2ebaeaea2 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -104,8 +104,8 @@ def _get_grpc_custom_bdist(decorated_basename, target_bdist_basename): with open(bdist_path, 'w') as bdist_file: bdist_file.write(bdist_data) except IOError as error: - raise CommandError('{}\n\nCould not write grpcio bdist: {}' - .format(traceback.format_exc(), error.message)) + raise CommandError('{}\n\nCould not write grpcio bdist: {}'.format( + traceback.format_exc(), error.message)) return bdist_path @@ -141,7 +141,8 @@ class SphinxDocumentation(setuptools.Command): with open(glossary_filepath, 'a') as glossary_filepath: glossary_filepath.write(API_GLOSSARY) sphinx.main( - ['', os.path.join('doc', 'src'), os.path.join('doc', 'build')]) + ['', os.path.join('doc', 'src'), + os.path.join('doc', 'build')]) class BuildProjectMetadata(setuptools.Command): @@ -189,10 +190,11 @@ def check_and_update_cythonization(extensions): for source in extension.sources: base, file_ext = os.path.splitext(source) if file_ext == '.pyx': - generated_pyx_source = next((base + gen_ext - for gen_ext in ('.c', '.cpp',) - if os.path.isfile(base + gen_ext)), - None) + generated_pyx_source = next( + (base + gen_ext for gen_ext in ( + '.c', + '.cpp', + ) if os.path.isfile(base + gen_ext)), None) if generated_pyx_source: generated_pyx_sources.append(generated_pyx_source) else: @@ -299,10 +301,10 @@ class Gather(setuptools.Command): """Command to gather project dependencies.""" description = 'gather dependencies for grpcio' - user_options = [ - ('test', 't', 'flag indicating to gather test dependencies'), - ('install', 'i', 'flag indicating to gather install dependencies') - ] + user_options = [('test', 't', + 'flag indicating to gather test dependencies'), + ('install', 'i', + 'flag indicating to gather install dependencies')] def initialize_options(self): self.test = False diff --git a/src/python/grpcio/grpc/__init__.py b/src/python/grpcio/grpc/__init__.py index 8b913ac9495..db410d307b1 100644 --- a/src/python/grpcio/grpc/__init__.py +++ b/src/python/grpcio/grpc/__init__.py @@ -1376,8 +1376,8 @@ def metadata_call_credentials(metadata_plugin, name=None): A CallCredentials. """ from grpc import _plugin_wrapping # pylint: disable=cyclic-import - return _plugin_wrapping.metadata_plugin_call_credentials(metadata_plugin, - name) + return _plugin_wrapping.metadata_plugin_call_credentials( + metadata_plugin, name) def access_token_call_credentials(access_token): @@ -1631,25 +1631,57 @@ def server(thread_pool, ################################### __all__ ################################# __all__ = ( - 'FutureTimeoutError', 'FutureCancelledError', 'Future', - 'ChannelConnectivity', 'StatusCode', 'RpcError', 'RpcContext', 'Call', - 'ChannelCredentials', 'CallCredentials', 'AuthMetadataContext', - 'AuthMetadataPluginCallback', 'AuthMetadataPlugin', 'ClientCallDetails', - 'ServerCertificateConfiguration', 'ServerCredentials', - 'UnaryUnaryMultiCallable', 'UnaryStreamMultiCallable', - 'StreamUnaryMultiCallable', 'StreamStreamMultiCallable', - 'UnaryUnaryClientInterceptor', 'UnaryStreamClientInterceptor', - 'StreamUnaryClientInterceptor', 'StreamStreamClientInterceptor', 'Channel', - 'ServicerContext', 'RpcMethodHandler', 'HandlerCallDetails', - 'GenericRpcHandler', 'ServiceRpcHandler', 'Server', 'ServerInterceptor', - 'unary_unary_rpc_method_handler', 'unary_stream_rpc_method_handler', - 'stream_unary_rpc_method_handler', 'stream_stream_rpc_method_handler', - 'method_handlers_generic_handler', 'ssl_channel_credentials', - 'metadata_call_credentials', 'access_token_call_credentials', - 'composite_call_credentials', 'composite_channel_credentials', - 'ssl_server_credentials', 'ssl_server_certificate_configuration', - 'dynamic_ssl_server_credentials', 'channel_ready_future', - 'insecure_channel', 'secure_channel', 'intercept_channel', 'server',) + 'FutureTimeoutError', + 'FutureCancelledError', + 'Future', + 'ChannelConnectivity', + 'StatusCode', + 'RpcError', + 'RpcContext', + 'Call', + 'ChannelCredentials', + 'CallCredentials', + 'AuthMetadataContext', + 'AuthMetadataPluginCallback', + 'AuthMetadataPlugin', + 'ClientCallDetails', + 'ServerCertificateConfiguration', + 'ServerCredentials', + 'UnaryUnaryMultiCallable', + 'UnaryStreamMultiCallable', + 'StreamUnaryMultiCallable', + 'StreamStreamMultiCallable', + 'UnaryUnaryClientInterceptor', + 'UnaryStreamClientInterceptor', + 'StreamUnaryClientInterceptor', + 'StreamStreamClientInterceptor', + 'Channel', + 'ServicerContext', + 'RpcMethodHandler', + 'HandlerCallDetails', + 'GenericRpcHandler', + 'ServiceRpcHandler', + 'Server', + 'ServerInterceptor', + 'unary_unary_rpc_method_handler', + 'unary_stream_rpc_method_handler', + 'stream_unary_rpc_method_handler', + 'stream_stream_rpc_method_handler', + 'method_handlers_generic_handler', + 'ssl_channel_credentials', + 'metadata_call_credentials', + 'access_token_call_credentials', + 'composite_call_credentials', + 'composite_channel_credentials', + 'ssl_server_credentials', + 'ssl_server_certificate_configuration', + 'dynamic_ssl_server_credentials', + 'channel_ready_future', + 'insecure_channel', + 'secure_channel', + 'intercept_channel', + 'server', +) ############################### Extension Shims ################################ diff --git a/src/python/grpcio/grpc/_auth.py b/src/python/grpcio/grpc/_auth.py index 9a339b59004..c17824563d7 100644 --- a/src/python/grpcio/grpc/_auth.py +++ b/src/python/grpcio/grpc/_auth.py @@ -54,7 +54,9 @@ class GoogleCallCredentials(grpc.AuthMetadataPlugin): if self._is_jwt: future = self._pool.submit( self._credentials.get_access_token, - additional_claims={'aud': context.service_url}) + additional_claims={ + 'aud': context.service_url + }) else: future = self._pool.submit(self._credentials.get_access_token) future.add_done_callback(_create_get_token_callback(callback)) diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py index 3572737c874..24be042f61f 100644 --- a/src/python/grpcio/grpc/_channel.py +++ b/src/python/grpcio/grpc/_channel.py @@ -29,24 +29,32 @@ _USER_AGENT = 'grpc-python/{}'.format(_grpcio_metadata.__version__) _EMPTY_FLAGS = 0 _INFINITE_FUTURE = cygrpc.Timespec(float('+inf')) -_UNARY_UNARY_INITIAL_DUE = (cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.send_message, - cygrpc.OperationType.send_close_from_client, - cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_message, - cygrpc.OperationType.receive_status_on_client,) -_UNARY_STREAM_INITIAL_DUE = (cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.send_message, - cygrpc.OperationType.send_close_from_client, - cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_status_on_client,) -_STREAM_UNARY_INITIAL_DUE = (cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_message, - cygrpc.OperationType.receive_status_on_client,) -_STREAM_STREAM_INITIAL_DUE = (cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_status_on_client,) +_UNARY_UNARY_INITIAL_DUE = ( + cygrpc.OperationType.send_initial_metadata, + cygrpc.OperationType.send_message, + cygrpc.OperationType.send_close_from_client, + cygrpc.OperationType.receive_initial_metadata, + cygrpc.OperationType.receive_message, + cygrpc.OperationType.receive_status_on_client, +) +_UNARY_STREAM_INITIAL_DUE = ( + cygrpc.OperationType.send_initial_metadata, + cygrpc.OperationType.send_message, + cygrpc.OperationType.send_close_from_client, + cygrpc.OperationType.receive_initial_metadata, + cygrpc.OperationType.receive_status_on_client, +) +_STREAM_UNARY_INITIAL_DUE = ( + cygrpc.OperationType.send_initial_metadata, + cygrpc.OperationType.receive_initial_metadata, + cygrpc.OperationType.receive_message, + cygrpc.OperationType.receive_status_on_client, +) +_STREAM_STREAM_INITIAL_DUE = ( + cygrpc.OperationType.send_initial_metadata, + cygrpc.OperationType.receive_initial_metadata, + cygrpc.OperationType.receive_status_on_client, +) _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE = ( 'Exception calling channel subscription callback!') @@ -457,7 +465,8 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS), cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS), cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS), - cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),) + cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS), + ) return state, operations, deadline, deadline_timespec, None def _blocking(self, request, timeout, metadata, credentials): @@ -538,11 +547,12 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): (cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS),), event_handler) operations = ( - cygrpc.SendInitialMetadataOperation( - metadata, _EMPTY_FLAGS), cygrpc.SendMessageOperation( - serialized_request, _EMPTY_FLAGS), + cygrpc.SendInitialMetadataOperation(metadata, _EMPTY_FLAGS), + cygrpc.SendMessageOperation(serialized_request, + _EMPTY_FLAGS), cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS), - cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),) + cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS), + ) call_error = call.start_client_batch(operations, event_handler) if call_error != cygrpc.CallError.ok: _call_error_set_RPCstate(state, call_error, metadata) @@ -576,7 +586,8 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): operations = ( cygrpc.SendInitialMetadataOperation(metadata, _EMPTY_FLAGS), cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS), - cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),) + cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS), + ) call_error = call.start_client_batch(operations, None) _check_call_error(call_error, metadata) _consume_request_iterator(request_iterator, state, call, @@ -627,7 +638,8 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): operations = ( cygrpc.SendInitialMetadataOperation(metadata, _EMPTY_FLAGS), cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS), - cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),) + cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS), + ) call_error = call.start_client_batch(operations, event_handler) if call_error != cygrpc.CallError.ok: _call_error_set_RPCstate(state, call_error, metadata) @@ -666,7 +678,8 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): event_handler) operations = ( cygrpc.SendInitialMetadataOperation(metadata, _EMPTY_FLAGS), - cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),) + cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS), + ) call_error = call.start_client_batch(operations, event_handler) if call_error != cygrpc.CallError.ok: _call_error_set_RPCstate(state, call_error, metadata) @@ -787,7 +800,11 @@ def _deliver(state, initial_connectivity, initial_callbacks): def _spawn_delivery(state, callbacks): delivering_thread = threading.Thread( - target=_deliver, args=(state, state.connectivity, callbacks,)) + target=_deliver, args=( + state, + state.connectivity, + callbacks, + )) delivering_thread.start() state.delivering = True @@ -862,17 +879,16 @@ def _subscribe(state, callback, try_to_connect): def _unsubscribe(state, callback): with state.lock: - for index, (subscribed_callback, unused_connectivity - ) in enumerate(state.callbacks_and_connectivities): + for index, (subscribed_callback, unused_connectivity) in enumerate( + state.callbacks_and_connectivities): if callback == subscribed_callback: state.callbacks_and_connectivities.pop(index) break def _options(options): - return list(options) + [ - (cygrpc.ChannelArgKey.primary_user_agent_string, _USER_AGENT) - ] + return list(options) + [(cygrpc.ChannelArgKey.primary_user_agent_string, + _USER_AGENT)] class Channel(grpc.Channel): @@ -887,8 +903,8 @@ class Channel(grpc.Channel): credentials: A cygrpc.ChannelCredentials or None. """ self._channel = cygrpc.Channel( - _common.encode(target), - _common.channel_args(_options(options)), credentials) + _common.encode(target), _common.channel_args(_options(options)), + credentials) self._call_state = _ChannelCallState(self._channel) self._connectivity_state = _ChannelConnectivityState(self._channel) @@ -908,8 +924,7 @@ class Channel(grpc.Channel): request_serializer=None, response_deserializer=None): return _UnaryUnaryMultiCallable( - self._channel, - _channel_managed_call_management(self._call_state), + self._channel, _channel_managed_call_management(self._call_state), _common.encode(method), request_serializer, response_deserializer) def unary_stream(self, @@ -917,8 +932,7 @@ class Channel(grpc.Channel): request_serializer=None, response_deserializer=None): return _UnaryStreamMultiCallable( - self._channel, - _channel_managed_call_management(self._call_state), + self._channel, _channel_managed_call_management(self._call_state), _common.encode(method), request_serializer, response_deserializer) def stream_unary(self, @@ -926,8 +940,7 @@ class Channel(grpc.Channel): request_serializer=None, response_deserializer=None): return _StreamUnaryMultiCallable( - self._channel, - _channel_managed_call_management(self._call_state), + self._channel, _channel_managed_call_management(self._call_state), _common.encode(method), request_serializer, response_deserializer) def stream_stream(self, @@ -935,8 +948,7 @@ class Channel(grpc.Channel): request_serializer=None, response_deserializer=None): return _StreamStreamMultiCallable( - self._channel, - _channel_managed_call_management(self._call_state), + self._channel, _channel_managed_call_management(self._call_state), _common.encode(method), request_serializer, response_deserializer) def __del__(self): diff --git a/src/python/grpcio/grpc/_interceptor.py b/src/python/grpcio/grpc/_interceptor.py index fffb2698455..56a280624f1 100644 --- a/src/python/grpcio/grpc/_interceptor.py +++ b/src/python/grpcio/grpc/_interceptor.py @@ -44,9 +44,10 @@ def service_pipeline(interceptors): class _ClientCallDetails( - collections.namedtuple('_ClientCallDetails', - ('method', 'timeout', 'metadata', - 'credentials')), grpc.ClientCallDetails): + collections.namedtuple( + '_ClientCallDetails', + ('method', 'timeout', 'metadata', 'credentials')), + grpc.ClientCallDetails): pass diff --git a/src/python/grpcio/grpc/_plugin_wrapping.py b/src/python/grpcio/grpc/_plugin_wrapping.py index f7287956dcc..6785e5876a6 100644 --- a/src/python/grpcio/grpc/_plugin_wrapping.py +++ b/src/python/grpcio/grpc/_plugin_wrapping.py @@ -23,7 +23,9 @@ from grpc._cython import cygrpc class _AuthMetadataContext( collections.namedtuple('AuthMetadataContext', ( - 'service_url', 'method_name',)), grpc.AuthMetadataContext): + 'service_url', + 'method_name', + )), grpc.AuthMetadataContext): pass @@ -70,8 +72,9 @@ class _Plugin(object): _common.decode(service_url), _common.decode(method_name)) callback_state = _CallbackState() try: - self._metadata_plugin( - context, _AuthMetadataPluginCallback(callback_state, callback)) + self._metadata_plugin(context, + _AuthMetadataPluginCallback( + callback_state, callback)) except Exception as exception: # pylint: disable=broad-except logging.exception( 'AuthMetadataPluginCallback "%s" raised exception!', diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py index 22244b9cecf..1cdb2d45b6c 100644 --- a/src/python/grpcio/grpc/_server.py +++ b/src/python/grpcio/grpc/_server.py @@ -78,7 +78,9 @@ def _details(state): class _HandlerCallDetails( collections.namedtuple('_HandlerCallDetails', ( - 'method', 'invocation_metadata',)), grpc.HandlerCallDetails): + 'method', + 'invocation_metadata', + )), grpc.HandlerCallDetails): pass @@ -130,10 +132,12 @@ def _abort(state, call, code, details): effective_code = _abortion_code(state, code) effective_details = details if state.details is None else state.details if state.initial_metadata_allowed: - operations = (cygrpc.SendInitialMetadataOperation( - None, _EMPTY_FLAGS), cygrpc.SendStatusFromServerOperation( + operations = ( + cygrpc.SendInitialMetadataOperation(None, _EMPTY_FLAGS), + cygrpc.SendStatusFromServerOperation( state.trailing_metadata, effective_code, effective_details, - _EMPTY_FLAGS),) + _EMPTY_FLAGS), + ) token = _SEND_INITIAL_METADATA_AND_SEND_STATUS_FROM_SERVER_TOKEN else: operations = (cygrpc.SendStatusFromServerOperation( @@ -422,15 +426,16 @@ def _send_response(rpc_event, state, serialized_response): return False else: if state.initial_metadata_allowed: - operations = (cygrpc.SendInitialMetadataOperation(None, - _EMPTY_FLAGS), - cygrpc.SendMessageOperation(serialized_response, - _EMPTY_FLAGS),) + operations = ( + cygrpc.SendInitialMetadataOperation(None, _EMPTY_FLAGS), + cygrpc.SendMessageOperation(serialized_response, + _EMPTY_FLAGS), + ) state.initial_metadata_allowed = False token = _SEND_INITIAL_METADATA_AND_SEND_MESSAGE_TOKEN else: - operations = (cygrpc.SendMessageOperation(serialized_response, - _EMPTY_FLAGS),) + operations = (cygrpc.SendMessageOperation( + serialized_response, _EMPTY_FLAGS),) token = _SEND_MESSAGE_TOKEN rpc_event.call.start_server_batch(operations, _send_message(state, token)) @@ -562,10 +567,12 @@ def _find_method_handler(rpc_event, generic_handlers, interceptor_pipeline): def _reject_rpc(rpc_event, status, details): - operations = (cygrpc.SendInitialMetadataOperation(None, _EMPTY_FLAGS), - cygrpc.ReceiveCloseOnServerOperation(_EMPTY_FLAGS), - cygrpc.SendStatusFromServerOperation(None, status, details, - _EMPTY_FLAGS),) + operations = ( + cygrpc.SendInitialMetadataOperation(None, _EMPTY_FLAGS), + cygrpc.ReceiveCloseOnServerOperation(_EMPTY_FLAGS), + cygrpc.SendStatusFromServerOperation(None, status, details, + _EMPTY_FLAGS), + ) rpc_state = _RPCState() rpc_event.call.start_server_batch(operations, lambda ignored_event: (rpc_state, (),)) @@ -798,8 +805,8 @@ class Server(grpc.Server): return _add_insecure_port(self._state, _common.encode(address)) def add_secure_port(self, address, server_credentials): - return _add_secure_port(self._state, - _common.encode(address), server_credentials) + return _add_secure_port(self._state, _common.encode(address), + server_credentials) def start(self): _start(self._state) diff --git a/src/python/grpcio/grpc/_utilities.py b/src/python/grpcio/grpc/_utilities.py index 47cedcc8671..25bd1ceae26 100644 --- a/src/python/grpcio/grpc/_utilities.py +++ b/src/python/grpcio/grpc/_utilities.py @@ -29,9 +29,15 @@ _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE = ( class RpcMethodHandler( collections.namedtuple('_RpcMethodHandler', ( - 'request_streaming', 'response_streaming', 'request_deserializer', - 'response_serializer', 'unary_unary', 'unary_stream', - 'stream_unary', 'stream_stream',)), grpc.RpcMethodHandler): + 'request_streaming', + 'response_streaming', + 'request_deserializer', + 'response_serializer', + 'unary_unary', + 'unary_stream', + 'stream_unary', + 'stream_stream', + )), grpc.RpcMethodHandler): pass diff --git a/src/python/grpcio/grpc/beta/_client_adaptations.py b/src/python/grpcio/grpc/beta/_client_adaptations.py index dcaa0eeaa29..cf200a8c132 100644 --- a/src/python/grpcio/grpc/beta/_client_adaptations.py +++ b/src/python/grpcio/grpc/beta/_client_adaptations.py @@ -51,8 +51,7 @@ def _abortion(rpc_error_call): code = rpc_error_call.code() pair = _STATUS_CODE_TO_ABORTION_KIND_AND_ABORTION_ERROR_CLASS.get(code) error_kind = face.Abortion.Kind.LOCAL_FAILURE if pair is None else pair[0] - return face.Abortion(error_kind, - rpc_error_call.initial_metadata(), + return face.Abortion(error_kind, rpc_error_call.initial_metadata(), rpc_error_call.trailing_metadata(), code, rpc_error_call.details()) @@ -441,9 +440,14 @@ class _GenericStub(face.GenericStub): metadata=None, with_call=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _blocking_unary_unary(self._channel, group, method, timeout, with_call, protocol_options, metadata, self._metadata_transformer, request, @@ -456,9 +460,14 @@ class _GenericStub(face.GenericStub): timeout, metadata=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _future_unary_unary(self._channel, group, method, timeout, protocol_options, metadata, self._metadata_transformer, request, @@ -471,9 +480,14 @@ class _GenericStub(face.GenericStub): timeout, metadata=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _unary_stream(self._channel, group, method, timeout, protocol_options, metadata, self._metadata_transformer, request, @@ -487,9 +501,14 @@ class _GenericStub(face.GenericStub): metadata=None, with_call=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _blocking_stream_unary( self._channel, group, method, timeout, with_call, protocol_options, metadata, self._metadata_transformer, request_iterator, @@ -502,9 +521,14 @@ class _GenericStub(face.GenericStub): timeout, metadata=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _future_stream_unary( self._channel, group, method, timeout, protocol_options, metadata, self._metadata_transformer, request_iterator, request_serializer, @@ -517,9 +541,14 @@ class _GenericStub(face.GenericStub): timeout, metadata=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _stream_stream(self._channel, group, method, timeout, protocol_options, metadata, self._metadata_transformer, request_iterator, @@ -568,33 +597,53 @@ class _GenericStub(face.GenericStub): raise NotImplementedError() def unary_unary(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _UnaryUnaryMultiCallable( self._channel, group, method, self._metadata_transformer, request_serializer, response_deserializer) def unary_stream(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _UnaryStreamMultiCallable( self._channel, group, method, self._metadata_transformer, request_serializer, response_deserializer) def stream_unary(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _StreamUnaryMultiCallable( self._channel, group, method, self._metadata_transformer, request_serializer, response_deserializer) def stream_stream(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, - method,)) + request_serializer = self._request_serializers.get(( + group, + method, + )) + response_deserializer = self._response_deserializers.get(( + group, + method, + )) return _StreamStreamMultiCallable( self._channel, group, method, self._metadata_transformer, request_serializer, response_deserializer) @@ -624,8 +673,8 @@ class _DynamicStub(face.DynamicStub): elif method_cardinality is cardinality.Cardinality.STREAM_STREAM: return self._generic_stub.stream_stream(self._group, attr) else: - raise AttributeError('_DynamicStub object has no attribute "%s"!' % - attr) + raise AttributeError( + '_DynamicStub object has no attribute "%s"!' % attr) def __enter__(self): return self diff --git a/src/python/grpcio/grpc/beta/_metadata.py b/src/python/grpcio/grpc/beta/_metadata.py index e135f4dff4f..b7c85352853 100644 --- a/src/python/grpcio/grpc/beta/_metadata.py +++ b/src/python/grpcio/grpc/beta/_metadata.py @@ -15,7 +15,10 @@ import collections -_Metadatum = collections.namedtuple('_Metadatum', ('key', 'value',)) +_Metadatum = collections.namedtuple('_Metadatum', ( + 'key', + 'value', +)) def _beta_metadatum(key, value): diff --git a/src/python/grpcio/grpc/beta/_server_adaptations.py b/src/python/grpcio/grpc/beta/_server_adaptations.py index 1c22dbe3bbe..3c04fd76396 100644 --- a/src/python/grpcio/grpc/beta/_server_adaptations.py +++ b/src/python/grpcio/grpc/beta/_server_adaptations.py @@ -245,9 +245,15 @@ def _adapt_stream_stream_event(stream_stream_event): class _SimpleMethodHandler( collections.namedtuple('_MethodHandler', ( - 'request_streaming', 'response_streaming', 'request_deserializer', - 'response_serializer', 'unary_unary', 'unary_stream', - 'stream_unary', 'stream_stream',)), grpc.RpcMethodHandler): + 'request_streaming', + 'response_streaming', + 'request_deserializer', + 'response_serializer', + 'unary_unary', + 'unary_stream', + 'stream_unary', + 'stream_stream', + )), grpc.RpcMethodHandler): pass @@ -255,15 +261,17 @@ def _simple_method_handler(implementation, request_deserializer, response_serializer): if implementation.style is style.Service.INLINE: if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY: - return _SimpleMethodHandler( - False, False, request_deserializer, response_serializer, - _adapt_unary_request_inline(implementation.unary_unary_inline), - None, None, None) + return _SimpleMethodHandler(False, False, request_deserializer, + response_serializer, + _adapt_unary_request_inline( + implementation.unary_unary_inline), + None, None, None) elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM: - return _SimpleMethodHandler( - False, True, request_deserializer, response_serializer, None, - _adapt_unary_request_inline(implementation.unary_stream_inline), - None, None) + return _SimpleMethodHandler(False, True, request_deserializer, + response_serializer, None, + _adapt_unary_request_inline( + implementation.unary_stream_inline), + None, None) elif implementation.cardinality is cardinality.Cardinality.STREAM_UNARY: return _SimpleMethodHandler(True, False, request_deserializer, response_serializer, None, None, @@ -278,26 +286,28 @@ def _simple_method_handler(implementation, request_deserializer, implementation.stream_stream_inline)) elif implementation.style is style.Service.EVENT: if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY: - return _SimpleMethodHandler( - False, False, request_deserializer, response_serializer, - _adapt_unary_unary_event(implementation.unary_unary_event), - None, None, None) + return _SimpleMethodHandler(False, False, request_deserializer, + response_serializer, + _adapt_unary_unary_event( + implementation.unary_unary_event), + None, None, None) elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM: - return _SimpleMethodHandler( - False, True, request_deserializer, response_serializer, None, - _adapt_unary_stream_event(implementation.unary_stream_event), - None, None) + return _SimpleMethodHandler(False, True, request_deserializer, + response_serializer, None, + _adapt_unary_stream_event( + implementation.unary_stream_event), + None, None) elif implementation.cardinality is cardinality.Cardinality.STREAM_UNARY: - return _SimpleMethodHandler( - True, False, request_deserializer, response_serializer, None, - None, - _adapt_stream_unary_event(implementation.stream_unary_event), - None) + return _SimpleMethodHandler(True, False, request_deserializer, + response_serializer, None, None, + _adapt_stream_unary_event( + implementation.stream_unary_event), + None) elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM: - return _SimpleMethodHandler( - True, True, request_deserializer, response_serializer, None, - None, None, - _adapt_stream_stream_event(implementation.stream_stream_event)) + return _SimpleMethodHandler(True, True, request_deserializer, + response_serializer, None, None, None, + _adapt_stream_stream_event( + implementation.stream_stream_event)) def _flatten_method_pair_map(method_pair_map): @@ -325,10 +335,11 @@ class _GenericRpcHandler(grpc.GenericRpcHandler): method_implementation = self._method_implementations.get( handler_call_details.method) if method_implementation is not None: - return _simple_method_handler( - method_implementation, - self._request_deserializers.get(handler_call_details.method), - self._response_serializers.get(handler_call_details.method)) + return _simple_method_handler(method_implementation, + self._request_deserializers.get( + handler_call_details.method), + self._response_serializers.get( + handler_call_details.method)) elif self._multi_method_implementation is None: return None else: diff --git a/src/python/grpcio/grpc/beta/implementations.py b/src/python/grpcio/grpc/beta/implementations.py index 312daf033e3..44dbd61c55e 100644 --- a/src/python/grpcio/grpc/beta/implementations.py +++ b/src/python/grpcio/grpc/beta/implementations.py @@ -110,8 +110,8 @@ def insecure_channel(host, port): Returns: A Channel to the remote host through which RPCs may be conducted. """ - channel = grpc.insecure_channel(host - if port is None else '%s:%d' % (host, port)) + channel = grpc.insecure_channel(host if port is None else '%s:%d' % (host, + port)) return Channel(channel) diff --git a/src/python/grpcio/grpc/framework/foundation/callable_util.py b/src/python/grpcio/grpc/framework/foundation/callable_util.py index 5bdfda5301f..b9b9c49f17d 100644 --- a/src/python/grpcio/grpc/framework/foundation/callable_util.py +++ b/src/python/grpcio/grpc/framework/foundation/callable_util.py @@ -50,8 +50,8 @@ class _EasyOutcome( def _call_logging_exceptions(behavior, message, *args, **kwargs): try: - return _EasyOutcome(Outcome.Kind.RETURNED, - behavior(*args, **kwargs), None) + return _EasyOutcome(Outcome.Kind.RETURNED, behavior(*args, **kwargs), + None) except Exception as e: # pylint: disable=broad-except logging.exception(message) return _EasyOutcome(Outcome.Kind.RAISED, None, e) diff --git a/src/python/grpcio/grpc/framework/interfaces/base/utilities.py b/src/python/grpcio/grpc/framework/interfaces/base/utilities.py index a9163d8588c..281db62b5d4 100644 --- a/src/python/grpcio/grpc/framework/interfaces/base/utilities.py +++ b/src/python/grpcio/grpc/framework/interfaces/base/utilities.py @@ -19,15 +19,22 @@ from grpc.framework.interfaces.base import base class _Completion(base.Completion, - collections.namedtuple('_Completion', ('terminal_metadata', - 'code', 'message',))): + collections.namedtuple('_Completion', ( + 'terminal_metadata', + 'code', + 'message', + ))): """A trivial implementation of base.Completion.""" class _Subscription(base.Subscription, collections.namedtuple('_Subscription', ( - 'kind', 'termination_callback', 'allowance', 'operator', - 'protocol_receiver',))): + 'kind', + 'termination_callback', + 'allowance', + 'operator', + 'protocol_receiver', + ))): """A trivial implementation of base.Subscription.""" diff --git a/src/python/grpcio/grpc/framework/interfaces/face/face.py b/src/python/grpcio/grpc/framework/interfaces/face/face.py index 0b93ea0f49c..5b47f11d0d7 100644 --- a/src/python/grpcio/grpc/framework/interfaces/face/face.py +++ b/src/python/grpcio/grpc/framework/interfaces/face/face.py @@ -50,13 +50,20 @@ class NoSuchMethodError(Exception): self.method = method def __repr__(self): - return 'face.NoSuchMethodError(%s, %s)' % (self.group, self.method,) + return 'face.NoSuchMethodError(%s, %s)' % ( + self.group, + self.method, + ) class Abortion( - collections.namedtuple('Abortion', - ('kind', 'initial_metadata', 'terminal_metadata', - 'code', 'details',))): + collections.namedtuple('Abortion', ( + 'kind', + 'initial_metadata', + 'terminal_metadata', + 'code', + 'details', + ))): """A value describing RPC abortion. Attributes: diff --git a/src/python/grpcio_health_checking/health_commands.py b/src/python/grpcio_health_checking/health_commands.py index 19547358a12..933f965aa2d 100644 --- a/src/python/grpcio_health_checking/health_commands.py +++ b/src/python/grpcio_health_checking/health_commands.py @@ -36,9 +36,9 @@ class CopyProtoModules(setuptools.Command): def run(self): if os.path.isfile(HEALTH_PROTO): - shutil.copyfile( - HEALTH_PROTO, - os.path.join(ROOT_DIR, 'grpc_health/v1/health.proto')) + shutil.copyfile(HEALTH_PROTO, + os.path.join(ROOT_DIR, + 'grpc_health/v1/health.proto')) class BuildPackageProtos(setuptools.Command): diff --git a/src/python/grpcio_health_checking/setup.py b/src/python/grpcio_health_checking/setup.py index c105f57509f..60d309ec650 100644 --- a/src/python/grpcio_health_checking/setup.py +++ b/src/python/grpcio_health_checking/setup.py @@ -56,8 +56,10 @@ PACKAGE_DIRECTORIES = { '': '.', } -INSTALL_REQUIRES = ('protobuf>=3.5.0.post1', - 'grpcio>={version}'.format(version=grpc_version.VERSION),) +INSTALL_REQUIRES = ( + 'protobuf>=3.5.0.post1', + 'grpcio>={version}'.format(version=grpc_version.VERSION), +) try: import health_commands as _health_commands diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py index 26a7ba8685f..0c564f10e5b 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py @@ -27,7 +27,8 @@ def _not_found_error(): return reflection_pb2.ServerReflectionResponse( error_response=reflection_pb2.ErrorResponse( error_code=grpc.StatusCode.NOT_FOUND.value[0], - error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(),)) + error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), + )) def _file_descriptor_response(descriptor): @@ -101,10 +102,11 @@ class ReflectionServicer(reflection_pb2_grpc.ServerReflectionServicer): def _list_services(self): return reflection_pb2.ServerReflectionResponse( - list_services_response=reflection_pb2.ListServiceResponse(service=[ - reflection_pb2.ServiceResponse(name=service_name) - for service_name in self._service_names - ])) + list_services_response=reflection_pb2.ListServiceResponse( + service=[ + reflection_pb2.ServiceResponse(name=service_name) + for service_name in self._service_names + ])) def ServerReflectionInfo(self, request_iterator, context): # pylint: disable=unused-argument @@ -128,7 +130,8 @@ class ReflectionServicer(reflection_pb2_grpc.ServerReflectionServicer): error_response=reflection_pb2.ErrorResponse( error_code=grpc.StatusCode.INVALID_ARGUMENT.value[0], error_message=grpc.StatusCode.INVALID_ARGUMENT.value[1] - .encode(),)) + .encode(), + )) def enable_server_reflection(service_names, server, pool=None): diff --git a/src/python/grpcio_reflection/setup.py b/src/python/grpcio_reflection/setup.py index 760b89373af..10c4c38f199 100644 --- a/src/python/grpcio_reflection/setup.py +++ b/src/python/grpcio_reflection/setup.py @@ -57,8 +57,10 @@ PACKAGE_DIRECTORIES = { '': '.', } -INSTALL_REQUIRES = ('protobuf>=3.5.0.post1', - 'grpcio>={version}'.format(version=grpc_version.VERSION),) +INSTALL_REQUIRES = ( + 'protobuf>=3.5.0.post1', + 'grpcio>={version}'.format(version=grpc_version.VERSION), +) try: import reflection_commands as _reflection_commands diff --git a/src/python/grpcio_testing/grpc_testing/_channel/_multi_callable.py b/src/python/grpcio_testing/grpc_testing/_channel/_multi_callable.py index 32b2f361d34..2b2f5761f56 100644 --- a/src/python/grpcio_testing/grpc_testing/_channel/_multi_callable.py +++ b/src/python/grpcio_testing/grpc_testing/_channel/_multi_callable.py @@ -27,20 +27,20 @@ class UnaryUnary(grpc.UnaryUnaryMultiCallable): def __call__(self, request, timeout=None, metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [request], True, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [request], True, timeout) return _invocation.blocking_unary_response(rpc_handler) def with_call(self, request, timeout=None, metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [request], True, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [request], True, timeout) return _invocation.blocking_unary_response_with_call(rpc_handler) def future(self, request, timeout=None, metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [request], True, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [request], True, timeout) return _invocation.future_call(rpc_handler) @@ -52,8 +52,8 @@ class UnaryStream(grpc.StreamStreamMultiCallable): def __call__(self, request, timeout=None, metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [request], True, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [request], True, timeout) return _invocation.ResponseIteratorCall(rpc_handler) @@ -69,8 +69,8 @@ class StreamUnary(grpc.StreamUnaryMultiCallable): metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [], False, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [], False, timeout) _invocation.consume_requests(request_iterator, rpc_handler) return _invocation.blocking_unary_response(rpc_handler) @@ -80,8 +80,8 @@ class StreamUnary(grpc.StreamUnaryMultiCallable): metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [], False, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [], False, timeout) _invocation.consume_requests(request_iterator, rpc_handler) return _invocation.blocking_unary_response_with_call(rpc_handler) @@ -91,8 +91,8 @@ class StreamUnary(grpc.StreamUnaryMultiCallable): metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [], False, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [], False, timeout) _invocation.consume_requests(request_iterator, rpc_handler) return _invocation.future_call(rpc_handler) @@ -109,8 +109,8 @@ class StreamStream(grpc.StreamStreamMultiCallable): metadata=None, credentials=None): rpc_handler = self._channel_handler.invoke_rpc( - self._method_full_rpc_name, - _common.fuss_with_metadata(metadata), [], False, timeout) + self._method_full_rpc_name, _common.fuss_with_metadata(metadata), + [], False, timeout) _invocation.consume_requests(request_iterator, rpc_handler) return _invocation.ResponseIteratorCall(rpc_handler) diff --git a/src/python/grpcio_testing/grpc_testing/_channel/_rpc_state.py b/src/python/grpcio_testing/grpc_testing/_channel/_rpc_state.py index ee0233002dc..009f675e495 100644 --- a/src/python/grpcio_testing/grpc_testing/_channel/_rpc_state.py +++ b/src/python/grpcio_testing/grpc_testing/_channel/_rpc_state.py @@ -179,8 +179,8 @@ class State(_common.ChannelRpcHandler): elif self._code is None: self._condition.wait() else: - raise ValueError( - 'Status code unexpectedly {}!'.format(self._code)) + raise ValueError('Status code unexpectedly {}!'.format( + self._code)) def is_active(self): raise NotImplementedError() diff --git a/src/python/grpcio_testing/grpc_testing/_common.py b/src/python/grpcio_testing/grpc_testing/_common.py index 05327b0ac2e..cebad31b5cc 100644 --- a/src/python/grpcio_testing/grpc_testing/_common.py +++ b/src/python/grpcio_testing/grpc_testing/_common.py @@ -20,9 +20,10 @@ import six def _fuss(tuplified_metadata): - return tuplified_metadata + ( - ('grpc.metadata_added_by_runtime', - 'gRPC is allowed to add metadata in transmission and does so.',),) + return tuplified_metadata + (( + 'grpc.metadata_added_by_runtime', + 'gRPC is allowed to add metadata in transmission and does so.', + ),) FUSSED_EMPTY_METADATA = _fuss(()) @@ -46,9 +47,12 @@ def rpc_names(service_descriptors): class ChannelRpcRead( - collections.namedtuple( - 'ChannelRpcRead', - ('response', 'trailing_metadata', 'code', 'details',))): + collections.namedtuple('ChannelRpcRead', ( + 'response', + 'trailing_metadata', + 'code', + 'details', + ))): pass @@ -100,8 +104,11 @@ class ChannelHandler(six.with_metaclass(abc.ABCMeta)): class ServerRpcRead( - collections.namedtuple('ServerRpcRead', - ('request', 'requests_closed', 'terminated',))): + collections.namedtuple('ServerRpcRead', ( + 'request', + 'requests_closed', + 'terminated', + ))): pass diff --git a/src/python/grpcio_testing/grpc_testing/_server/_handler.py b/src/python/grpcio_testing/grpc_testing/_server/_handler.py index 5e4730e0871..d4f50f6863a 100644 --- a/src/python/grpcio_testing/grpc_testing/_server/_handler.py +++ b/src/python/grpcio_testing/grpc_testing/_server/_handler.py @@ -170,8 +170,12 @@ class _Handler(Handler): if self._unary_response is None: if self._responses: self._unary_response = self._responses.pop(0) - return (self._unary_response, self._trailing_metadata, - self._code, self._details,) + return ( + self._unary_response, + self._trailing_metadata, + self._code, + self._details, + ) def stream_response_termination(self): with self._condition: diff --git a/src/python/grpcio_testing/grpc_testing/_server/_server.py b/src/python/grpcio_testing/grpc_testing/_server/_server.py index 3e358e50a91..c7effb6b554 100644 --- a/src/python/grpcio_testing/grpc_testing/_server/_server.py +++ b/src/python/grpcio_testing/grpc_testing/_server/_server.py @@ -76,7 +76,11 @@ class _Serverish(_common.Serverish): rpc, self._time, deadline) service_thread = threading.Thread( target=service_behavior, - args=(implementation, rpc, servicer_context,)) + args=( + implementation, + rpc, + servicer_context, + )) service_thread.start() def invoke_unary_unary(self, method_descriptor, handler, diff --git a/src/python/grpcio_testing/grpc_testing/_time.py b/src/python/grpcio_testing/grpc_testing/_time.py index 3b1ab4bcd86..afbdad3524e 100644 --- a/src/python/grpcio_testing/grpc_testing/_time.py +++ b/src/python/grpcio_testing/grpc_testing/_time.py @@ -46,9 +46,11 @@ class _State(object): class _Delta( - collections.namedtuple('_Delta', - ('mature_behaviors', 'earliest_mature_time', - 'earliest_immature_time',))): + collections.namedtuple('_Delta', ( + 'mature_behaviors', + 'earliest_mature_time', + 'earliest_immature_time', + ))): pass diff --git a/src/python/grpcio_testing/setup.py b/src/python/grpcio_testing/setup.py index fa40424f6a2..5a9d593ec17 100644 --- a/src/python/grpcio_testing/setup.py +++ b/src/python/grpcio_testing/setup.py @@ -28,8 +28,10 @@ PACKAGE_DIRECTORIES = { '': '.', } -INSTALL_REQUIRES = ('protobuf>=3.5.0.post1', - 'grpcio>={version}'.format(version=grpc_version.VERSION),) +INSTALL_REQUIRES = ( + 'protobuf>=3.5.0.post1', + 'grpcio>={version}'.format(version=grpc_version.VERSION), +) setuptools.setup( name='grpcio-testing', diff --git a/src/python/grpcio_tests/setup.py b/src/python/grpcio_tests/setup.py index aeb4ea9c53d..250df658034 100644 --- a/src/python/grpcio_tests/setup.py +++ b/src/python/grpcio_tests/setup.py @@ -99,4 +99,5 @@ setuptools.setup( tests_require=TESTS_REQUIRE, test_suite=TEST_SUITE, test_loader=TEST_LOADER, - test_runner=TEST_RUNNER,) + test_runner=TEST_RUNNER, +) diff --git a/src/python/grpcio_tests/tests/_loader.py b/src/python/grpcio_tests/tests/_loader.py index 281a23c16e1..31680916b40 100644 --- a/src/python/grpcio_tests/tests/_loader.py +++ b/src/python/grpcio_tests/tests/_loader.py @@ -101,5 +101,5 @@ def iterate_suite_cases(suite): elif isinstance(item, unittest.TestCase): yield item else: - raise ValueError( - 'unexpected suite item of type {}'.format(type(item))) + raise ValueError('unexpected suite item of type {}'.format( + type(item))) diff --git a/src/python/grpcio_tests/tests/_result.py b/src/python/grpcio_tests/tests/_result.py index f26fdefc973..9907c4e1f9f 100644 --- a/src/python/grpcio_tests/tests/_result.py +++ b/src/python/grpcio_tests/tests/_result.py @@ -215,7 +215,8 @@ class AugmentedResult(unittest.TestResult): Args: filter (callable): A unary predicate to filter over CaseResult objects. """ - return (self.cases[case_id] for case_id in self.cases + return (self.cases[case_id] + for case_id in self.cases if filter(self.cases[case_id])) @@ -285,8 +286,8 @@ class TerminalResult(CoverageResult): def startTestRun(self): """See unittest.TestResult.startTestRun.""" super(TerminalResult, self).startTestRun() - self.out.write(_Colors.HEADER + 'Testing gRPC Python...\n' + - _Colors.END) + self.out.write( + _Colors.HEADER + 'Testing gRPC Python...\n' + _Colors.END) def stopTestRun(self): """See unittest.TestResult.stopTestRun.""" @@ -297,43 +298,43 @@ class TerminalResult(CoverageResult): def addError(self, test, error): """See unittest.TestResult.addError.""" super(TerminalResult, self).addError(test, error) - self.out.write(_Colors.FAIL + 'ERROR {}\n'.format(test.id()) + - _Colors.END) + self.out.write( + _Colors.FAIL + 'ERROR {}\n'.format(test.id()) + _Colors.END) self.out.flush() def addFailure(self, test, error): """See unittest.TestResult.addFailure.""" super(TerminalResult, self).addFailure(test, error) - self.out.write(_Colors.FAIL + 'FAILURE {}\n'.format(test.id()) + - _Colors.END) + self.out.write( + _Colors.FAIL + 'FAILURE {}\n'.format(test.id()) + _Colors.END) self.out.flush() def addSuccess(self, test): """See unittest.TestResult.addSuccess.""" super(TerminalResult, self).addSuccess(test) - self.out.write(_Colors.OK + 'SUCCESS {}\n'.format(test.id()) + - _Colors.END) + self.out.write( + _Colors.OK + 'SUCCESS {}\n'.format(test.id()) + _Colors.END) self.out.flush() def addSkip(self, test, reason): """See unittest.TestResult.addSkip.""" super(TerminalResult, self).addSkip(test, reason) - self.out.write(_Colors.INFO + 'SKIP {}\n'.format(test.id()) + - _Colors.END) + self.out.write( + _Colors.INFO + 'SKIP {}\n'.format(test.id()) + _Colors.END) self.out.flush() def addExpectedFailure(self, test, error): """See unittest.TestResult.addExpectedFailure.""" super(TerminalResult, self).addExpectedFailure(test, error) - self.out.write(_Colors.INFO + 'FAILURE_OK {}\n'.format(test.id()) + - _Colors.END) + self.out.write( + _Colors.INFO + 'FAILURE_OK {}\n'.format(test.id()) + _Colors.END) self.out.flush() def addUnexpectedSuccess(self, test): """See unittest.TestResult.addUnexpectedSuccess.""" super(TerminalResult, self).addUnexpectedSuccess(test) - self.out.write(_Colors.INFO + 'UNEXPECTED_OK {}\n'.format(test.id()) + - _Colors.END) + self.out.write( + _Colors.INFO + 'UNEXPECTED_OK {}\n'.format(test.id()) + _Colors.END) self.out.flush() diff --git a/src/python/grpcio_tests/tests/_runner.py b/src/python/grpcio_tests/tests/_runner.py index 8fb4a0e09b2..8e27dc6c6df 100644 --- a/src/python/grpcio_tests/tests/_runner.py +++ b/src/python/grpcio_tests/tests/_runner.py @@ -181,8 +181,8 @@ class Runner(object): # Run the tests result.startTestRun() for augmented_case in augmented_cases: - sys.stdout.write( - 'Running {}\n'.format(augmented_case.case.id())) + sys.stdout.write('Running {}\n'.format( + augmented_case.case.id())) sys.stdout.flush() case_thread = threading.Thread( target=augmented_case.case.run, args=(result,)) @@ -196,8 +196,8 @@ class Runner(object): except: # re-raise the exception after forcing the with-block to end raise - result.set_output(augmented_case.case, - stdout_pipe.output(), stderr_pipe.output()) + result.set_output(augmented_case.case, stdout_pipe.output(), + stderr_pipe.output()) sys.stdout.write(result_out.getvalue()) sys.stdout.flush() result_out.truncate(0) diff --git a/src/python/grpcio_tests/tests/http2/negative_http2_client.py b/src/python/grpcio_tests/tests/http2/negative_http2_client.py index 8dab5b67f1f..e4076827b6c 100644 --- a/src/python/grpcio_tests/tests/http2/negative_http2_client.py +++ b/src/python/grpcio_tests/tests/http2/negative_http2_client.py @@ -32,14 +32,14 @@ def _validate_payload_type_and_length(response, expected_type, expected_length): def _expect_status_code(call, expected_code): if call.code() != expected_code: - raise ValueError('expected code %s, got %s' % - (expected_code, call.code())) + raise ValueError('expected code %s, got %s' % (expected_code, + call.code())) def _expect_status_details(call, expected_details): if call.details() != expected_details: - raise ValueError('expected message %s, got %s' % - (expected_details, call.details())) + raise ValueError('expected message %s, got %s' % (expected_details, + call.details())) def _validate_status_code_and_details(call, expected_code, expected_details): diff --git a/src/python/grpcio_tests/tests/interop/_intraop_test_case.py b/src/python/grpcio_tests/tests/interop/_intraop_test_case.py index ce456a679b7..007db7ab41b 100644 --- a/src/python/grpcio_tests/tests/interop/_intraop_test_case.py +++ b/src/python/grpcio_tests/tests/interop/_intraop_test_case.py @@ -39,8 +39,8 @@ class IntraopTestCase(object): methods.TestCase.PING_PONG.test_interoperability(self.stub, None) def testCancelAfterBegin(self): - methods.TestCase.CANCEL_AFTER_BEGIN.test_interoperability(self.stub, - None) + methods.TestCase.CANCEL_AFTER_BEGIN.test_interoperability( + self.stub, None) def testCancelAfterFirstResponse(self): methods.TestCase.CANCEL_AFTER_FIRST_RESPONSE.test_interoperability( diff --git a/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py b/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py index 6ce8b3715bc..c89135998dc 100644 --- a/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py +++ b/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py @@ -34,15 +34,16 @@ class SecureIntraopTest(_intraop_test_case.IntraopTestCase, unittest.TestCase): self.server) port = self.server.add_secure_port( '[::]:0', - grpc.ssl_server_credentials( - [(resources.private_key(), resources.certificate_chain())])) + grpc.ssl_server_credentials([(resources.private_key(), + resources.certificate_chain())])) self.server.start() self.stub = test_pb2_grpc.TestServiceStub( grpc.secure_channel('localhost:{}'.format(port), grpc.ssl_channel_credentials( - resources.test_root_certificates()), ( - ('grpc.ssl_target_name_override', - _SERVER_HOST_OVERRIDE,),))) + resources.test_root_certificates()), (( + 'grpc.ssl_target_name_override', + _SERVER_HOST_OVERRIDE, + ),))) if __name__ == '__main__': diff --git a/src/python/grpcio_tests/tests/interop/client.py b/src/python/grpcio_tests/tests/interop/client.py index 383b5f033d7..3780ed90203 100644 --- a/src/python/grpcio_tests/tests/interop/client.py +++ b/src/python/grpcio_tests/tests/interop/client.py @@ -104,8 +104,10 @@ def _stub(args): channel_credentials = grpc.composite_channel_credentials( channel_credentials, call_credentials) - channel = grpc.secure_channel(target, channel_credentials, ( - ('grpc.ssl_target_name_override', args.server_host_override,),)) + channel = grpc.secure_channel(target, channel_credentials, (( + 'grpc.ssl_target_name_override', + args.server_host_override, + ),)) else: channel = grpc.insecure_channel(target) if args.test_case == "unimplemented_service": diff --git a/src/python/grpcio_tests/tests/interop/methods.py b/src/python/grpcio_tests/tests/interop/methods.py index ae9a50dd9bd..b728ffd704f 100644 --- a/src/python/grpcio_tests/tests/interop/methods.py +++ b/src/python/grpcio_tests/tests/interop/methods.py @@ -62,9 +62,10 @@ class TestService(test_pb2_grpc.TestServiceServicer): def UnaryCall(self, request, context): _maybe_echo_metadata(context) _maybe_echo_status_and_message(request, context) - return messages_pb2.SimpleResponse(payload=messages_pb2.Payload( - type=messages_pb2.COMPRESSABLE, - body=b'\x00' * request.response_size)) + return messages_pb2.SimpleResponse( + payload=messages_pb2.Payload( + type=messages_pb2.COMPRESSABLE, + body=b'\x00' * request.response_size)) def StreamingOutputCall(self, request, context): _maybe_echo_status_and_message(request, context) @@ -100,14 +101,14 @@ class TestService(test_pb2_grpc.TestServiceServicer): def _expect_status_code(call, expected_code): if call.code() != expected_code: - raise ValueError('expected code %s, got %s' % - (expected_code, call.code())) + raise ValueError('expected code %s, got %s' % (expected_code, + call.code())) def _expect_status_details(call, expected_details): if call.details() != expected_details: - raise ValueError('expected message %s, got %s' % - (expected_details, call.details())) + raise ValueError('expected message %s, got %s' % (expected_details, + call.details())) def _validate_status_code_and_details(call, expected_code, expected_details): @@ -152,26 +153,38 @@ def _large_unary(stub): def _client_streaming(stub): - payload_body_sizes = (27182, 8, 1828, 45904,) + payload_body_sizes = ( + 27182, + 8, + 1828, + 45904, + ) payloads = (messages_pb2.Payload(body=b'\x00' * size) for size in payload_body_sizes) requests = (messages_pb2.StreamingInputCallRequest(payload=payload) for payload in payloads) response = stub.StreamingInputCall(requests) if response.aggregated_payload_size != 74922: - raise ValueError('incorrect size %d!' % - response.aggregated_payload_size) + raise ValueError( + 'incorrect size %d!' % response.aggregated_payload_size) def _server_streaming(stub): - sizes = (31415, 9, 2653, 58979,) + sizes = ( + 31415, + 9, + 2653, + 58979, + ) request = messages_pb2.StreamingOutputCallRequest( response_type=messages_pb2.COMPRESSABLE, - response_parameters=(messages_pb2.ResponseParameters(size=sizes[0]), - messages_pb2.ResponseParameters(size=sizes[1]), - messages_pb2.ResponseParameters(size=sizes[2]), - messages_pb2.ResponseParameters(size=sizes[3]),)) + response_parameters=( + messages_pb2.ResponseParameters(size=sizes[0]), + messages_pb2.ResponseParameters(size=sizes[1]), + messages_pb2.ResponseParameters(size=sizes[2]), + messages_pb2.ResponseParameters(size=sizes[3]), + )) response_iterator = stub.StreamingOutputCall(request) for index, response in enumerate(response_iterator): _validate_payload_type_and_length(response, messages_pb2.COMPRESSABLE, @@ -218,8 +231,18 @@ class _Pipe(object): def _ping_pong(stub): - request_response_sizes = (31415, 9, 2653, 58979,) - request_payload_sizes = (27182, 8, 1828, 45904,) + request_response_sizes = ( + 31415, + 9, + 2653, + 58979, + ) + request_payload_sizes = ( + 27182, + 8, + 1828, + 45904, + ) with _Pipe() as pipe: response_iterator = stub.FullDuplexCall(pipe) @@ -247,8 +270,18 @@ def _cancel_after_begin(stub): def _cancel_after_first_response(stub): - request_response_sizes = (31415, 9, 2653, 58979,) - request_payload_sizes = (27182, 8, 1828, 45904,) + request_response_sizes = ( + 31415, + 9, + 2653, + 58979, + ) + request_payload_sizes = ( + 27182, + 8, + 1828, + 45904, + ) with _Pipe() as pipe: response_iterator = stub.FullDuplexCall(pipe) @@ -331,14 +364,14 @@ def _status_code_and_message(stub): def _unimplemented_method(test_service_stub): - response_future = ( - test_service_stub.UnimplementedCall.future(empty_pb2.Empty())) + response_future = (test_service_stub.UnimplementedCall.future( + empty_pb2.Empty())) _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) def _unimplemented_service(unimplemented_service_stub): - response_future = ( - unimplemented_service_stub.UnimplementedCall.future(empty_pb2.Empty())) + response_future = (unimplemented_service_stub.UnimplementedCall.future( + empty_pb2.Empty())) _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) @@ -392,11 +425,12 @@ def _oauth2_auth_token(stub, args): wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] response = _large_unary_common_behavior(stub, True, True, None) if wanted_email != response.username: - raise ValueError('expected username %s, got %s' % - (wanted_email, response.username)) + raise ValueError('expected username %s, got %s' % (wanted_email, + response.username)) if args.oauth_scope.find(response.oauth_scope) == -1: - raise ValueError('expected to find oauth scope "{}" in received "{}"'. - format(response.oauth_scope, args.oauth_scope)) + raise ValueError( + 'expected to find oauth scope "{}" in received "{}"'.format( + response.oauth_scope, args.oauth_scope)) def _jwt_token_creds(stub, args): @@ -404,8 +438,8 @@ def _jwt_token_creds(stub, args): wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] response = _large_unary_common_behavior(stub, True, False, None) if wanted_email != response.username: - raise ValueError('expected username %s, got %s' % - (wanted_email, response.username)) + raise ValueError('expected username %s, got %s' % (wanted_email, + response.username)) def _per_rpc_creds(stub, args): @@ -419,8 +453,8 @@ def _per_rpc_creds(stub, args): request=google_auth_transport_requests.Request())) response = _large_unary_common_behavior(stub, True, False, call_credentials) if wanted_email != response.username: - raise ValueError('expected username %s, got %s' % - (wanted_email, response.username)) + raise ValueError('expected username %s, got %s' % (wanted_email, + response.username)) @enum.unique @@ -479,5 +513,5 @@ class TestCase(enum.Enum): elif self is TestCase.PER_RPC_CREDS: _per_rpc_creds(stub, args) else: - raise NotImplementedError('Test case "%s" not implemented!' % - self.name) + raise NotImplementedError( + 'Test case "%s" not implemented!' % self.name) diff --git a/src/python/grpcio_tests/tests/interop/server.py b/src/python/grpcio_tests/tests/interop/server.py index dd4f5146e91..0810de2394a 100644 --- a/src/python/grpcio_tests/tests/interop/server.py +++ b/src/python/grpcio_tests/tests/interop/server.py @@ -45,8 +45,8 @@ def serve(): if args.use_tls: private_key = resources.private_key() certificate_chain = resources.certificate_chain() - credentials = grpc.ssl_server_credentials(( - (private_key, certificate_chain),)) + credentials = grpc.ssl_server_credentials(((private_key, + certificate_chain),)) server.add_secure_port('[::]:{}'.format(args.port), credentials) else: server.add_insecure_port('[::]:{}'.format(args.port)) diff --git a/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py b/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py index 8fc539e6415..6d85f431300 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py @@ -119,8 +119,11 @@ class _ServicerMethods(object): class _Service( - collections.namedtuple('_Service', ('servicer_methods', 'server', - 'stub',))): + collections.namedtuple('_Service', ( + 'servicer_methods', + 'server', + 'stub', + ))): """A live and running service. Attributes: @@ -297,8 +300,8 @@ class PythonPluginTest(unittest.TestCase): responses = service.stub.StreamingOutputCall(request) expected_responses = service.servicer_methods.StreamingOutputCall( request, 'not a real RpcContext!') - for expected_response, response in moves.zip_longest(expected_responses, - responses): + for expected_response, response in moves.zip_longest( + expected_responses, responses): self.assertEqual(expected_response, response) def testStreamingOutputCallExpired(self): @@ -388,8 +391,8 @@ class PythonPluginTest(unittest.TestCase): responses = service.stub.FullDuplexCall(_full_duplex_request_iterator()) expected_responses = service.servicer_methods.FullDuplexCall( _full_duplex_request_iterator(), 'not a real RpcContext!') - for expected_response, response in moves.zip_longest(expected_responses, - responses): + for expected_response, response in moves.zip_longest( + expected_responses, responses): self.assertEqual(expected_response, response) def testFullDuplexCallExpired(self): @@ -439,8 +442,8 @@ class PythonPluginTest(unittest.TestCase): responses = service.stub.HalfDuplexCall(half_duplex_request_iterator()) expected_responses = service.servicer_methods.HalfDuplexCall( half_duplex_request_iterator(), 'not a real RpcContext!') - for expected_response, response in moves.zip_longest(expected_responses, - responses): + for expected_response, response in moves.zip_longest( + expected_responses, responses): self.assertEqual(expected_response, response) def testHalfDuplexCallWedged(self): diff --git a/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py b/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py index c732e551089..ab33775ad31 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py @@ -64,8 +64,8 @@ def _massage_proto_content(proto_content, test_name_bytes, messages_proto_relative_file_name_bytes): package_substitution = (b'package grpc_protoc_plugin.invocation_testing.' + test_name_bytes + b';') - common_namespace_substituted = proto_content.replace(_COMMON_NAMESPACE, - package_substitution) + common_namespace_substituted = proto_content.replace( + _COMMON_NAMESPACE, package_substitution) split_namespace_substituted = common_namespace_substituted.replace( _SPLIT_NAMESPACE, package_substitution) message_import_replaced = split_namespace_substituted.replace( @@ -163,8 +163,12 @@ class _GrpcBeforeProtoProtocStyle(object): return pb2_grpc_protoc_exit_code, pb2_protoc_exit_code, -_PROTOC_STYLES = (_Mid2016ProtocStyle(), _SingleProtocExecutionProtocStyle(), - _ProtoBeforeGrpcProtocStyle(), _GrpcBeforeProtoProtocStyle(),) +_PROTOC_STYLES = ( + _Mid2016ProtocStyle(), + _SingleProtocExecutionProtocStyle(), + _ProtoBeforeGrpcProtocStyle(), + _GrpcBeforeProtoProtocStyle(), +) @unittest.skipIf(platform.python_implementation() == 'PyPy', @@ -180,18 +184,22 @@ class _Test(six.with_metaclass(abc.ABCMeta, unittest.TestCase)): os.makedirs(self._python_out) proto_directories_and_names = { - (self.MESSAGES_PROTO_RELATIVE_DIRECTORY_NAMES, - self.MESSAGES_PROTO_FILE_NAME,), - (self.SERVICES_PROTO_RELATIVE_DIRECTORY_NAMES, - self.SERVICES_PROTO_FILE_NAME,), + ( + self.MESSAGES_PROTO_RELATIVE_DIRECTORY_NAMES, + self.MESSAGES_PROTO_FILE_NAME, + ), + ( + self.SERVICES_PROTO_RELATIVE_DIRECTORY_NAMES, + self.SERVICES_PROTO_FILE_NAME, + ), } messages_proto_relative_file_name_forward_slashes = '/'.join( - self.MESSAGES_PROTO_RELATIVE_DIRECTORY_NAMES + ( - self.MESSAGES_PROTO_FILE_NAME,)) - _create_directory_tree(self._proto_path, ( - relative_proto_directory_names - for relative_proto_directory_names, _ in proto_directories_and_names - )) + self.MESSAGES_PROTO_RELATIVE_DIRECTORY_NAMES + + (self.MESSAGES_PROTO_FILE_NAME,)) + _create_directory_tree(self._proto_path, + (relative_proto_directory_names + for relative_proto_directory_names, _ in + proto_directories_and_names)) self._absolute_proto_file_names = set() for relative_directory_names, file_name in proto_directories_and_names: absolute_proto_file_name = path.join( @@ -200,8 +208,7 @@ class _Test(six.with_metaclass(abc.ABCMeta, unittest.TestCase)): 'tests.protoc_plugin.protos.invocation_testing', path.join(*relative_directory_names + (file_name,))) massaged_proto_content = _massage_proto_content( - raw_proto_content, - self.NAME.encode(), + raw_proto_content, self.NAME.encode(), messages_proto_relative_file_name_forward_slashes.encode()) with open(absolute_proto_file_name, 'wb') as proto_file: proto_file.write(massaged_proto_content) @@ -275,7 +282,9 @@ def _create_test_case_class(split_proto, protoc_style): if split_proto: attributes['MESSAGES_PROTO_RELATIVE_DIRECTORY_NAMES'] = ( - 'split_messages', 'sub',) + 'split_messages', + 'sub', + ) attributes['MESSAGES_PROTO_FILE_NAME'] = 'messages.proto' attributes['SERVICES_PROTO_RELATIVE_DIRECTORY_NAMES'] = ( 'split_services',) @@ -301,7 +310,10 @@ def _create_test_case_class(split_proto, protoc_style): def _create_test_case_classes(): - for split_proto in (False, True,): + for split_proto in ( + False, + True, + ): for protoc_style in _PROTOC_STYLES: yield _create_test_case_class(split_proto, protoc_style) diff --git a/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py b/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py index 424b153ff8d..ad0ecf00792 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py @@ -36,10 +36,28 @@ _RELATIVE_PROTO_PATH = 'relative_proto_path' _RELATIVE_PYTHON_OUT = 'relative_python_out' _PROTO_FILES_PATH_COMPONENTS = ( - ('beta_grpc_plugin_test', 'payload', 'test_payload.proto',), - ('beta_grpc_plugin_test', 'requests', 'r', 'test_requests.proto',), - ('beta_grpc_plugin_test', 'responses', 'test_responses.proto',), - ('beta_grpc_plugin_test', 'service', 'test_service.proto',),) + ( + 'beta_grpc_plugin_test', + 'payload', + 'test_payload.proto', + ), + ( + 'beta_grpc_plugin_test', + 'requests', + 'r', + 'test_requests.proto', + ), + ( + 'beta_grpc_plugin_test', + 'responses', + 'test_responses.proto', + ), + ( + 'beta_grpc_plugin_test', + 'service', + 'test_service.proto', + ), +) _PAYLOAD_PB2 = 'beta_grpc_plugin_test.payload.test_payload_pb2' _REQUESTS_PB2 = 'beta_grpc_plugin_test.requests.r.test_requests_pb2' diff --git a/src/python/grpcio_tests/tests/qps/benchmark_client.py b/src/python/grpcio_tests/tests/qps/benchmark_client.py index 17fa61ea366..e6392a8b8c8 100644 --- a/src/python/grpcio_tests/tests/qps/benchmark_client.py +++ b/src/python/grpcio_tests/tests/qps/benchmark_client.py @@ -155,7 +155,8 @@ class _SyncStream(object): _TIMEOUT) for _ in response_stream: self._handle_response( - self, time.time() - self._send_time_queue.get_nowait()) + self, + time.time() - self._send_time_queue.get_nowait()) def stop(self): self._is_streaming = False diff --git a/src/python/grpcio_tests/tests/qps/worker_server.py b/src/python/grpcio_tests/tests/qps/worker_server.py index fef4fb0459b..41e2403c8fc 100644 --- a/src/python/grpcio_tests/tests/qps/worker_server.py +++ b/src/python/grpcio_tests/tests/qps/worker_server.py @@ -72,8 +72,8 @@ class WorkerServer(services_pb2_grpc.WorkerServiceServicer): server = test_common.test_server(max_workers=server_threads) if config.server_type == control_pb2.ASYNC_SERVER: servicer = benchmark_server.BenchmarkServer() - services_pb2_grpc.add_BenchmarkServiceServicer_to_server(servicer, - server) + services_pb2_grpc.add_BenchmarkServiceServicer_to_server( + servicer, server) elif config.server_type == control_pb2.ASYNC_GENERIC_SERVER: resp_size = config.payload_config.bytebuf_params.resp_size servicer = benchmark_server.GenericBenchmarkServer(resp_size) @@ -87,12 +87,12 @@ class WorkerServer(services_pb2_grpc.WorkerServiceServicer): 'grpc.testing.BenchmarkService', method_implementations) server.add_generic_rpc_handlers((handler,)) else: - raise Exception( - 'Unsupported server type {}'.format(config.server_type)) + raise Exception('Unsupported server type {}'.format( + config.server_type)) if config.HasField('security_params'): # Use SSL - server_creds = grpc.ssl_server_credentials(( - (resources.private_key(), resources.certificate_chain()),)) + server_creds = grpc.ssl_server_credentials( + ((resources.private_key(), resources.certificate_chain()),)) port = server.add_secure_port('[::]:{}'.format(config.port), server_creds) else: @@ -156,8 +156,8 @@ class WorkerServer(services_pb2_grpc.WorkerServiceServicer): else: raise Exception('Async streaming client not supported') else: - raise Exception( - 'Unsupported client type {}'.format(config.client_type)) + raise Exception('Unsupported client type {}'.format( + config.client_type)) # In multi-channel tests, we split the load across all channels load_factor = float(config.client_channels) diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py index 86037e258ab..7ffdba6a677 100644 --- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py @@ -33,7 +33,13 @@ _EMPTY_PROTO_SYMBOL_NAME = 'grpc.testing.Empty' _SERVICE_NAMES = ('Angstrom', 'Bohr', 'Curie', 'Dyson', 'Einstein', 'Feynman', 'Galilei') _EMPTY_EXTENSIONS_SYMBOL_NAME = 'grpc.testing.proto2.EmptyWithExtensions' -_EMPTY_EXTENSIONS_NUMBERS = (124, 125, 126, 127, 128,) +_EMPTY_EXTENSIONS_NUMBERS = ( + 124, + 125, + 126, + 127, + 128, +) def _file_descriptor_to_proto(descriptor): @@ -54,10 +60,12 @@ class ReflectionServicerTest(unittest.TestCase): self._stub = reflection_pb2_grpc.ServerReflectionStub(channel) def testFileByName(self): - requests = (reflection_pb2.ServerReflectionRequest( - file_by_filename=_EMPTY_PROTO_FILE_NAME), - reflection_pb2.ServerReflectionRequest( - file_by_filename='i-donut-exist'),) + requests = ( + reflection_pb2.ServerReflectionRequest( + file_by_filename=_EMPTY_PROTO_FILE_NAME), + reflection_pb2.ServerReflectionRequest( + file_by_filename='i-donut-exist'), + ) responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) expected_responses = ( reflection_pb2.ServerReflectionResponse( @@ -70,14 +78,18 @@ class ReflectionServicerTest(unittest.TestCase): error_response=reflection_pb2.ErrorResponse( error_code=grpc.StatusCode.NOT_FOUND.value[0], error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - )),) + )), + ) self.assertSequenceEqual(expected_responses, responses) def testFileBySymbol(self): - requests = (reflection_pb2.ServerReflectionRequest( - file_containing_symbol=_EMPTY_PROTO_SYMBOL_NAME - ), reflection_pb2.ServerReflectionRequest( - file_containing_symbol='i.donut.exist.co.uk.org.net.me.name.foo'),) + requests = ( + reflection_pb2.ServerReflectionRequest( + file_containing_symbol=_EMPTY_PROTO_SYMBOL_NAME), + reflection_pb2.ServerReflectionRequest( + file_containing_symbol='i.donut.exist.co.uk.org.net.me.name.foo' + ), + ) responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) expected_responses = ( reflection_pb2.ServerReflectionResponse( @@ -90,18 +102,23 @@ class ReflectionServicerTest(unittest.TestCase): error_response=reflection_pb2.ErrorResponse( error_code=grpc.StatusCode.NOT_FOUND.value[0], error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - )),) + )), + ) self.assertSequenceEqual(expected_responses, responses) def testFileContainingExtension(self): - requests = (reflection_pb2.ServerReflectionRequest( - file_containing_extension=reflection_pb2.ExtensionRequest( - containing_type=_EMPTY_EXTENSIONS_SYMBOL_NAME, - extension_number=125,), - ), reflection_pb2.ServerReflectionRequest( - file_containing_extension=reflection_pb2.ExtensionRequest( - containing_type='i.donut.exist.co.uk.org.net.me.name.foo', - extension_number=55,),),) + requests = ( + reflection_pb2.ServerReflectionRequest( + file_containing_extension=reflection_pb2.ExtensionRequest( + containing_type=_EMPTY_EXTENSIONS_SYMBOL_NAME, + extension_number=125, + ),), + reflection_pb2.ServerReflectionRequest( + file_containing_extension=reflection_pb2.ExtensionRequest( + containing_type='i.donut.exist.co.uk.org.net.me.name.foo', + extension_number=55, + ),), + ) responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) expected_responses = ( reflection_pb2.ServerReflectionResponse( @@ -114,14 +131,18 @@ class ReflectionServicerTest(unittest.TestCase): error_response=reflection_pb2.ErrorResponse( error_code=grpc.StatusCode.NOT_FOUND.value[0], error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - )),) + )), + ) self.assertSequenceEqual(expected_responses, responses) def testExtensionNumbersOfType(self): - requests = (reflection_pb2.ServerReflectionRequest( - all_extension_numbers_of_type=_EMPTY_EXTENSIONS_SYMBOL_NAME - ), reflection_pb2.ServerReflectionRequest( - all_extension_numbers_of_type='i.donut.exist.co.uk.net.name.foo'),) + requests = ( + reflection_pb2.ServerReflectionRequest( + all_extension_numbers_of_type=_EMPTY_EXTENSIONS_SYMBOL_NAME), + reflection_pb2.ServerReflectionRequest( + all_extension_numbers_of_type='i.donut.exist.co.uk.net.name.foo' + ), + ) responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) expected_responses = ( reflection_pb2.ServerReflectionResponse( @@ -135,12 +156,12 @@ class ReflectionServicerTest(unittest.TestCase): error_response=reflection_pb2.ErrorResponse( error_code=grpc.StatusCode.NOT_FOUND.value[0], error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - )),) + )), + ) self.assertSequenceEqual(expected_responses, responses) def testListServices(self): - requests = (reflection_pb2.ServerReflectionRequest( - list_services='',),) + requests = (reflection_pb2.ServerReflectionRequest(list_services='',),) responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) expected_responses = (reflection_pb2.ServerReflectionResponse( valid_host='', diff --git a/src/python/grpcio_tests/tests/stress/client.py b/src/python/grpcio_tests/tests/stress/client.py index 40caa3926a5..41f2e1b6c2d 100644 --- a/src/python/grpcio_tests/tests/stress/client.py +++ b/src/python/grpcio_tests/tests/stress/client.py @@ -102,8 +102,10 @@ def _get_channel(target, args): root_certificates = None # will load default roots. channel_credentials = grpc.ssl_channel_credentials( root_certificates=root_certificates) - options = (('grpc.ssl_target_name_override', - args.server_host_override,),) + options = (( + 'grpc.ssl_target_name_override', + args.server_host_override, + ),) channel = grpc.secure_channel( target, channel_credentials, options=options) else: diff --git a/src/python/grpcio_tests/tests/testing/_client_application.py b/src/python/grpcio_tests/tests/testing/_client_application.py index aff32fb4dc5..7d0d74c8c4a 100644 --- a/src/python/grpcio_tests/tests/testing/_client_application.py +++ b/src/python/grpcio_tests/tests/testing/_client_application.py @@ -235,8 +235,8 @@ def run(scenario, channel): elif scenario is Scenario.INFINITE_REQUEST_STREAM: return _run_infinite_request_stream(stub) except grpc.RpcError as rpc_error: - return Outcome(Outcome.Kind.RPC_ERROR, - rpc_error.code(), rpc_error.details()) + return Outcome(Outcome.Kind.RPC_ERROR, rpc_error.code(), + rpc_error.details()) _IMPLEMENTATIONS = { @@ -256,5 +256,5 @@ def run(scenario, channel): try: return _IMPLEMENTATIONS[scenario](stub) except grpc.RpcError as rpc_error: - return Outcome(Outcome.Kind.RPC_ERROR, - rpc_error.code(), rpc_error.details()) + return Outcome(Outcome.Kind.RPC_ERROR, rpc_error.code(), + rpc_error.details()) diff --git a/src/python/grpcio_tests/tests/testing/_client_test.py b/src/python/grpcio_tests/tests/testing/_client_test.py index 172f386d7b1..5b051c39390 100644 --- a/src/python/grpcio_tests/tests/testing/_client_test.py +++ b/src/python/grpcio_tests/tests/testing/_client_test.py @@ -193,8 +193,10 @@ class ClientTest(unittest.TestCase): rpc.take_request() rpc.take_request() rpc.requests_closed() - rpc.send_initial_metadata(( - ('my_metadata_key', 'My Metadata Value!',),)) + rpc.send_initial_metadata((( + 'my_metadata_key', + 'My Metadata Value!', + ),)) for rpc in rpcs[:-1]: rpc.terminate(_application_common.STREAM_UNARY_RESPONSE, (), grpc.StatusCode.OK, '') diff --git a/src/python/grpcio_tests/tests/testing/_server_application.py b/src/python/grpcio_tests/tests/testing/_server_application.py index 06f09c8cb48..02769ca68dc 100644 --- a/src/python/grpcio_tests/tests/testing/_server_application.py +++ b/src/python/grpcio_tests/tests/testing/_server_application.py @@ -41,8 +41,10 @@ class FirstServiceServicer(services_pb2_grpc.FirstServiceServicer): yield services_pb2.Strange() def StreUn(self, request_iterator, context): - context.send_initial_metadata(( - ('server_application_metadata_key', 'Hi there!',),)) + context.send_initial_metadata((( + 'server_application_metadata_key', + 'Hi there!', + ),)) for request in request_iterator: if request != _application_common.STREAM_UNARY_REQUEST: context.set_code(grpc.StatusCode.INVALID_ARGUMENT) diff --git a/src/python/grpcio_tests/tests/testing/_server_test.py b/src/python/grpcio_tests/tests/testing/_server_test.py index 7897bcce018..4f4abd77086 100644 --- a/src/python/grpcio_tests/tests/testing/_server_test.py +++ b/src/python/grpcio_tests/tests/testing/_server_test.py @@ -110,14 +110,19 @@ class FirstServiceServicerTest(unittest.TestCase): second_termination = rpc.termination() third_termination = rpc.termination() - for later_initial_metadata in (second_initial_metadata, - third_initial_metadata,): + for later_initial_metadata in ( + second_initial_metadata, + third_initial_metadata, + ): self.assertEqual(first_initial_metadata, later_initial_metadata) response = first_termination[0] terminal_metadata = first_termination[1] code = first_termination[2] details = first_termination[3] - for later_termination in (second_termination, third_termination,): + for later_termination in ( + second_termination, + third_termination, + ): self.assertEqual(response, later_termination[0]) self.assertEqual(terminal_metadata, later_termination[1]) self.assertIs(code, later_termination[2]) diff --git a/src/python/grpcio_tests/tests/testing/_time_test.py b/src/python/grpcio_tests/tests/testing/_time_test.py index 797394ae20f..9dfe36fb830 100644 --- a/src/python/grpcio_tests/tests/testing/_time_test.py +++ b/src/python/grpcio_tests/tests/testing/_time_test.py @@ -105,8 +105,8 @@ class TimeTest(object): test_event.set, _QUANTUM * (2 + random.random())) for _ in range(_MANY): background_noise_futures.append( - self._time.call_in(threading.Event().set, _QUANTUM * 1000 * - random.random())) + self._time.call_in(threading.Event().set, + _QUANTUM * 1000 * random.random())) self._time.sleep_for(_QUANTUM) cancelled = set() for test_event, test_future in possibly_cancelled_futures.items(): diff --git a/src/python/grpcio_tests/tests/unit/_api_test.py b/src/python/grpcio_tests/tests/unit/_api_test.py index d6f44475324..f6245be77d2 100644 --- a/src/python/grpcio_tests/tests/unit/_api_test.py +++ b/src/python/grpcio_tests/tests/unit/_api_test.py @@ -26,28 +26,57 @@ class AllTest(unittest.TestCase): def testAll(self): expected_grpc_code_elements = ( - 'FutureTimeoutError', 'FutureCancelledError', 'Future', - 'ChannelConnectivity', 'StatusCode', 'RpcError', 'RpcContext', - 'Call', 'ChannelCredentials', 'CallCredentials', - 'AuthMetadataContext', 'AuthMetadataPluginCallback', - 'AuthMetadataPlugin', 'ServerCertificateConfiguration', - 'ServerCredentials', 'UnaryUnaryMultiCallable', - 'UnaryStreamMultiCallable', 'StreamUnaryMultiCallable', - 'StreamStreamMultiCallable', 'UnaryUnaryClientInterceptor', - 'UnaryStreamClientInterceptor', 'StreamUnaryClientInterceptor', - 'StreamStreamClientInterceptor', 'Channel', 'ServicerContext', - 'RpcMethodHandler', 'HandlerCallDetails', 'GenericRpcHandler', - 'ServiceRpcHandler', 'Server', 'ServerInterceptor', - 'unary_unary_rpc_method_handler', 'unary_stream_rpc_method_handler', - 'stream_unary_rpc_method_handler', 'ClientCallDetails', + 'FutureTimeoutError', + 'FutureCancelledError', + 'Future', + 'ChannelConnectivity', + 'StatusCode', + 'RpcError', + 'RpcContext', + 'Call', + 'ChannelCredentials', + 'CallCredentials', + 'AuthMetadataContext', + 'AuthMetadataPluginCallback', + 'AuthMetadataPlugin', + 'ServerCertificateConfiguration', + 'ServerCredentials', + 'UnaryUnaryMultiCallable', + 'UnaryStreamMultiCallable', + 'StreamUnaryMultiCallable', + 'StreamStreamMultiCallable', + 'UnaryUnaryClientInterceptor', + 'UnaryStreamClientInterceptor', + 'StreamUnaryClientInterceptor', + 'StreamStreamClientInterceptor', + 'Channel', + 'ServicerContext', + 'RpcMethodHandler', + 'HandlerCallDetails', + 'GenericRpcHandler', + 'ServiceRpcHandler', + 'Server', + 'ServerInterceptor', + 'unary_unary_rpc_method_handler', + 'unary_stream_rpc_method_handler', + 'stream_unary_rpc_method_handler', + 'ClientCallDetails', 'stream_stream_rpc_method_handler', - 'method_handlers_generic_handler', 'ssl_channel_credentials', - 'metadata_call_credentials', 'access_token_call_credentials', - 'composite_call_credentials', 'composite_channel_credentials', - 'ssl_server_credentials', 'ssl_server_certificate_configuration', - 'dynamic_ssl_server_credentials', 'channel_ready_future', - 'insecure_channel', 'secure_channel', 'intercept_channel', - 'server',) + 'method_handlers_generic_handler', + 'ssl_channel_credentials', + 'metadata_call_credentials', + 'access_token_call_credentials', + 'composite_call_credentials', + 'composite_channel_credentials', + 'ssl_server_credentials', + 'ssl_server_certificate_configuration', + 'dynamic_ssl_server_credentials', + 'channel_ready_future', + 'insecure_channel', + 'secure_channel', + 'intercept_channel', + 'server', + ) six.assertCountEqual(self, expected_grpc_code_elements, _from_grpc_import_star.GRPC_ELEMENTS) @@ -56,12 +85,13 @@ class AllTest(unittest.TestCase): class ChannelConnectivityTest(unittest.TestCase): def testChannelConnectivity(self): - self.assertSequenceEqual( - (grpc.ChannelConnectivity.IDLE, grpc.ChannelConnectivity.CONNECTING, - grpc.ChannelConnectivity.READY, - grpc.ChannelConnectivity.TRANSIENT_FAILURE, - grpc.ChannelConnectivity.SHUTDOWN,), - tuple(grpc.ChannelConnectivity)) + self.assertSequenceEqual(( + grpc.ChannelConnectivity.IDLE, + grpc.ChannelConnectivity.CONNECTING, + grpc.ChannelConnectivity.READY, + grpc.ChannelConnectivity.TRANSIENT_FAILURE, + grpc.ChannelConnectivity.SHUTDOWN, + ), tuple(grpc.ChannelConnectivity)) class ChannelTest(unittest.TestCase): diff --git a/src/python/grpcio_tests/tests/unit/_auth_context_test.py b/src/python/grpcio_tests/tests/unit/_auth_context_test.py index ebc04a71e05..468869a03e4 100644 --- a/src/python/grpcio_tests/tests/unit/_auth_context_test.py +++ b/src/python/grpcio_tests/tests/unit/_auth_context_test.py @@ -29,8 +29,12 @@ _RESPONSE = b'\x00\x00\x00' _UNARY_UNARY = '/test/UnaryUnary' _SERVER_HOST_OVERRIDE = 'foo.test.google.fr' -_CLIENT_IDS = (b'*.test.google.fr', b'waterzooi.test.google.be', - b'*.test.youtube.com', b'192.168.1.3',) +_CLIENT_IDS = ( + b'*.test.google.fr', + b'waterzooi.test.google.be', + b'*.test.youtube.com', + b'192.168.1.3', +) _ID = 'id' _ID_KEY = 'id_key' _AUTH_CTX = 'auth_ctx' @@ -39,7 +43,10 @@ _PRIVATE_KEY = resources.private_key() _CERTIFICATE_CHAIN = resources.certificate_chain() _TEST_ROOT_CERTIFICATES = resources.test_root_certificates() _SERVER_CERTS = ((_PRIVATE_KEY, _CERTIFICATE_CHAIN),) -_PROPERTY_OPTIONS = (('grpc.ssl_target_name_override', _SERVER_HOST_OVERRIDE,),) +_PROPERTY_OPTIONS = (( + 'grpc.ssl_target_name_override', + _SERVER_HOST_OVERRIDE, +),) def handle_unary_unary(request, servicer_context): diff --git a/src/python/grpcio_tests/tests/unit/_channel_args_test.py b/src/python/grpcio_tests/tests/unit/_channel_args_test.py index 0a6b512866b..1a2d2c01179 100644 --- a/src/python/grpcio_tests/tests/unit/_channel_args_test.py +++ b/src/python/grpcio_tests/tests/unit/_channel_args_test.py @@ -24,8 +24,13 @@ class TestPointerWrapper(object): return 123456 -TEST_CHANNEL_ARGS = (('arg1', b'bytes_val'), ('arg2', 'str_val'), ('arg3', 1), - (b'arg4', 'str_val'), ('arg6', TestPointerWrapper()),) +TEST_CHANNEL_ARGS = ( + ('arg1', b'bytes_val'), + ('arg2', 'str_val'), + ('arg3', 1), + (b'arg4', 'str_val'), + ('arg6', TestPointerWrapper()), +) class ChannelArgsTest(unittest.TestCase): diff --git a/src/python/grpcio_tests/tests/unit/_compression_test.py b/src/python/grpcio_tests/tests/unit/_compression_test.py index 93e599d8f82..7550cd39ba2 100644 --- a/src/python/grpcio_tests/tests/unit/_compression_test.py +++ b/src/python/grpcio_tests/tests/unit/_compression_test.py @@ -26,16 +26,16 @@ _STREAM_STREAM = '/test/StreamStream' def handle_unary(request, servicer_context): - servicer_context.send_initial_metadata( - [('grpc-internal-encoding-request', 'gzip')]) + servicer_context.send_initial_metadata([('grpc-internal-encoding-request', + 'gzip')]) return request def handle_stream(request_iterator, servicer_context): # TODO(issue:#6891) We should be able to remove this loop, # and replace with return; yield - servicer_context.send_initial_metadata( - [('grpc-internal-encoding-request', 'gzip')]) + servicer_context.send_initial_metadata([('grpc-internal-encoding-request', + 'gzip')]) for request in request_iterator: yield request diff --git a/src/python/grpcio_tests/tests/unit/_credentials_test.py b/src/python/grpcio_tests/tests/unit/_credentials_test.py index 097898b987f..f487fe66a2d 100644 --- a/src/python/grpcio_tests/tests/unit/_credentials_test.py +++ b/src/python/grpcio_tests/tests/unit/_credentials_test.py @@ -26,8 +26,8 @@ class CredentialsTest(unittest.TestCase): third = grpc.access_token_call_credentials('ghi') first_and_second = grpc.composite_call_credentials(first, second) - first_second_and_third = grpc.composite_call_credentials(first, second, - third) + first_second_and_third = grpc.composite_call_credentials( + first, second, third) self.assertIsInstance(first_and_second, grpc.CallCredentials) self.assertIsInstance(first_second_and_third, grpc.CallCredentials) diff --git a/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py b/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py index cdb35724535..b81d6fbc617 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py @@ -81,7 +81,8 @@ class _Handler(object): cygrpc.SendMessageOperation(b'\x79\x57', _EMPTY_FLAGS), cygrpc.SendStatusFromServerOperation( _EMPTY_METADATA, cygrpc.StatusCode.ok, b'test details!', - _EMPTY_FLAGS),) + _EMPTY_FLAGS), + ) self._call.start_server_batch(operations, _SERVER_COMPLETE_CALL_TAG) self._completion_queue.poll() @@ -151,8 +152,12 @@ class CancelManyCallsTest(unittest.TestCase): state = _State() - server_thread_args = (state, server, server_completion_queue, - server_thread_pool,) + server_thread_args = ( + state, + server, + server_completion_queue, + server_thread_pool, + ) server_thread = threading.Thread(target=_serve, args=server_thread_args) server_thread.start() @@ -176,7 +181,8 @@ class CancelManyCallsTest(unittest.TestCase): cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS), cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS), cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS), - cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),) + cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS), + ) tag = 'client_complete_call_{0:04d}_tag'.format(index) client_call.start_client_batch(operations, tag) client_due.add(tag) @@ -193,8 +199,8 @@ class CancelManyCallsTest(unittest.TestCase): state.condition.notify_all() break - client_driver.events(test_constants.RPC_CONCURRENCY * - _SUCCESS_CALL_FRACTION) + client_driver.events( + test_constants.RPC_CONCURRENCY * _SUCCESS_CALL_FRACTION) with client_condition: for client_call in client_calls: client_call.cancel() diff --git a/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py b/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py index 1d57ea7ec1e..4eeb34b92ec 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py @@ -56,7 +56,10 @@ class ChannelTest(unittest.TestCase): def test_single_channel_lonely_connectivity(self): channel, completion_queue = _channel_and_completion_queue() - _in_parallel(_connectivity_loop, (channel, completion_queue,)) + _in_parallel(_connectivity_loop, ( + channel, + completion_queue, + )) completion_queue.shutdown() def test_multiple_channels_lonely_connectivity(self): diff --git a/src/python/grpcio_tests/tests/unit/_cython/_common.py b/src/python/grpcio_tests/tests/unit/_cython/_common.py index c5acd36bf2e..ffd226fa95a 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_common.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_common.py @@ -23,14 +23,20 @@ RPC_COUNT = 4000 INFINITE_FUTURE = cygrpc.Timespec(float('+inf')) EMPTY_FLAGS = 0 -INVOCATION_METADATA = (('client-md-key', 'client-md-key'), - ('client-md-key-bin', b'\x00\x01' * 3000),) +INVOCATION_METADATA = ( + ('client-md-key', 'client-md-key'), + ('client-md-key-bin', b'\x00\x01' * 3000), +) -INITIAL_METADATA = (('server-initial-md-key', 'server-initial-md-value'), - ('server-initial-md-key-bin', b'\x00\x02' * 3000),) +INITIAL_METADATA = ( + ('server-initial-md-key', 'server-initial-md-value'), + ('server-initial-md-key-bin', b'\x00\x02' * 3000), +) -TRAILING_METADATA = (('server-trailing-md-key', 'server-trailing-md-value'), - ('server-trailing-md-key-bin', b'\x00\x03' * 3000),) +TRAILING_METADATA = ( + ('server-trailing-md-key', 'server-trailing-md-value'), + ('server-trailing-md-key-bin', b'\x00\x03' * 3000), +) class QueueDriver(object): @@ -76,7 +82,10 @@ def execute_many_times(behavior): class OperationResult( collections.namedtuple('OperationResult', ( - 'start_batch_result', 'completion_type', 'success',))): + 'start_batch_result', + 'completion_type', + 'success', + ))): pass diff --git a/src/python/grpcio_tests/tests/unit/_cython/_no_messages_server_completion_queue_per_call_test.py b/src/python/grpcio_tests/tests/unit/_cython/_no_messages_server_completion_queue_per_call_test.py index 583136cf236..4ef4ad33e56 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_no_messages_server_completion_queue_per_call_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_no_messages_server_completion_queue_per_call_test.py @@ -101,28 +101,29 @@ class Test(_common.RpcTest, unittest.TestCase): client_complete_rpc_event = self.client_driver.event_with_tag( client_complete_rpc_tag) - return (_common.OperationResult( - server_request_call_start_batch_result, - server_request_call_event.completion_type, - server_request_call_event.success), _common.OperationResult( + return ( + _common.OperationResult(server_request_call_start_batch_result, + server_request_call_event.completion_type, + server_request_call_event.success), + _common.OperationResult( client_receive_initial_metadata_start_batch_result, client_receive_initial_metadata_event.completion_type, client_receive_initial_metadata_event.success), - _common.OperationResult( - client_complete_rpc_start_batch_result, - client_complete_rpc_event.completion_type, - client_complete_rpc_event.success), _common.OperationResult( - server_send_initial_metadata_start_batch_result, - server_send_initial_metadata_event.completion_type, - server_send_initial_metadata_event.success), - _common.OperationResult( - server_complete_rpc_start_batch_result, - server_complete_rpc_event.completion_type, - server_complete_rpc_event.success),) + _common.OperationResult(client_complete_rpc_start_batch_result, + client_complete_rpc_event.completion_type, + client_complete_rpc_event.success), + _common.OperationResult( + server_send_initial_metadata_start_batch_result, + server_send_initial_metadata_event.completion_type, + server_send_initial_metadata_event.success), + _common.OperationResult(server_complete_rpc_start_batch_result, + server_complete_rpc_event.completion_type, + server_complete_rpc_event.success), + ) def test_rpcs(self): - expecteds = [(_common.SUCCESSFUL_OPERATION_RESULT,) * - 5] * _common.RPC_COUNT + expecteds = [( + _common.SUCCESSFUL_OPERATION_RESULT,) * 5] * _common.RPC_COUNT actuallys = _common.execute_many_times(self._do_rpcs) self.assertSequenceEqual(expecteds, actuallys) diff --git a/src/python/grpcio_tests/tests/unit/_cython/_no_messages_single_server_completion_queue_test.py b/src/python/grpcio_tests/tests/unit/_cython/_no_messages_single_server_completion_queue_test.py index c5cf606c904..85395c9680f 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_no_messages_single_server_completion_queue_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_no_messages_single_server_completion_queue_test.py @@ -92,28 +92,29 @@ class Test(_common.RpcTest, unittest.TestCase): client_complete_rpc_event = self.client_driver.event_with_tag( client_complete_rpc_tag) - return (_common.OperationResult( - server_request_call_start_batch_result, - server_request_call_event.completion_type, - server_request_call_event.success), _common.OperationResult( + return ( + _common.OperationResult(server_request_call_start_batch_result, + server_request_call_event.completion_type, + server_request_call_event.success), + _common.OperationResult( client_receive_initial_metadata_start_batch_result, client_receive_initial_metadata_event.completion_type, client_receive_initial_metadata_event.success), - _common.OperationResult( - client_complete_rpc_start_batch_result, - client_complete_rpc_event.completion_type, - client_complete_rpc_event.success), _common.OperationResult( - server_send_initial_metadata_start_batch_result, - server_send_initial_metadata_event.completion_type, - server_send_initial_metadata_event.success), - _common.OperationResult( - server_complete_rpc_start_batch_result, - server_complete_rpc_event.completion_type, - server_complete_rpc_event.success),) + _common.OperationResult(client_complete_rpc_start_batch_result, + client_complete_rpc_event.completion_type, + client_complete_rpc_event.success), + _common.OperationResult( + server_send_initial_metadata_start_batch_result, + server_send_initial_metadata_event.completion_type, + server_send_initial_metadata_event.success), + _common.OperationResult(server_complete_rpc_start_batch_result, + server_complete_rpc_event.completion_type, + server_complete_rpc_event.success), + ) def test_rpcs(self): - expecteds = [(_common.SUCCESSFUL_OPERATION_RESULT,) * - 5] * _common.RPC_COUNT + expecteds = [( + _common.SUCCESSFUL_OPERATION_RESULT,) * 5] * _common.RPC_COUNT actuallys = _common.execute_many_times(self._do_rpcs) self.assertSequenceEqual(expecteds, actuallys) diff --git a/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py b/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py index a5ec54ee594..82ef25b2a7f 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py @@ -137,9 +137,12 @@ class ReadSomeButNotAllResponsesTest(unittest.TestCase): server_send_first_message_tag = 'server_send_first_message_tag' server_send_second_message_tag = 'server_send_second_message_tag' server_complete_rpc_tag = 'server_complete_rpc_tag' - server_call_due = set( - (server_send_initial_metadata_tag, server_send_first_message_tag, - server_send_second_message_tag, server_complete_rpc_tag,)) + server_call_due = set(( + server_send_initial_metadata_tag, + server_send_first_message_tag, + server_send_second_message_tag, + server_complete_rpc_tag, + )) server_call_completion_queue = cygrpc.CompletionQueue() server_call_driver = _QueueDriver(server_call_condition, server_call_completion_queue, diff --git a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py index 5453735f11d..5f9b74ba989 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py @@ -29,8 +29,10 @@ _EMPTY_FLAGS = 0 def _metadata_plugin(context, callback): - callback(((_CALL_CREDENTIALS_METADATA_KEY, - _CALL_CREDENTIALS_METADATA_VALUE,),), cygrpc.StatusCode.ok, b'') + callback((( + _CALL_CREDENTIALS_METADATA_KEY, + _CALL_CREDENTIALS_METADATA_VALUE, + ),), cygrpc.StatusCode.ok, b'') class TypeSmokeTest(unittest.TestCase): @@ -113,13 +115,12 @@ class ServerClientMixin(object): cygrpc.ChannelArg(cygrpc.ChannelArgKey.ssl_target_name_override, host_override) ]) - self.client_channel = cygrpc.Channel( - 'localhost:{}'.format(self.port).encode(), - client_channel_arguments, client_credentials) + self.client_channel = cygrpc.Channel('localhost:{}'.format( + self.port).encode(), client_channel_arguments, + client_credentials) else: - self.client_channel = cygrpc.Channel( - 'localhost:{}'.format(self.port).encode(), - cygrpc.ChannelArgs([])) + self.client_channel = cygrpc.Channel('localhost:{}'.format( + self.port).encode(), cygrpc.ChannelArgs([])) if host_override: self.host_argument = None # default host self.expected_host = host_override @@ -152,8 +153,8 @@ class ServerClientMixin(object): self.assertTrue(event.success) self.assertIs(tag, event.tag) except Exception as error: - raise Exception( - "Error in '{}': {}".format(description, error.message)) + raise Exception("Error in '{}': {}".format( + description, error.message)) return event return test_utilities.SimpleFuture(performer) @@ -189,8 +190,15 @@ class ServerClientMixin(object): None, 0, self.client_completion_queue, METHOD, self.host_argument, cygrpc_deadline) client_initial_metadata = ( - (CLIENT_METADATA_ASCII_KEY, CLIENT_METADATA_ASCII_VALUE,), - (CLIENT_METADATA_BIN_KEY, CLIENT_METADATA_BIN_VALUE,),) + ( + CLIENT_METADATA_ASCII_KEY, + CLIENT_METADATA_ASCII_VALUE, + ), + ( + CLIENT_METADATA_BIN_KEY, + CLIENT_METADATA_BIN_VALUE, + ), + ) client_start_batch_result = client_call.start_client_batch([ cygrpc.SendInitialMetadataOperation(client_initial_metadata, _EMPTY_FLAGS), @@ -220,14 +228,18 @@ class ServerClientMixin(object): server_call_tag = object() server_call = request_event.call - server_initial_metadata = ( - (SERVER_INITIAL_METADATA_KEY, SERVER_INITIAL_METADATA_VALUE,),) - server_trailing_metadata = ( - (SERVER_TRAILING_METADATA_KEY, SERVER_TRAILING_METADATA_VALUE,),) + server_initial_metadata = (( + SERVER_INITIAL_METADATA_KEY, + SERVER_INITIAL_METADATA_VALUE, + ),) + server_trailing_metadata = (( + SERVER_TRAILING_METADATA_KEY, + SERVER_TRAILING_METADATA_VALUE, + ),) server_start_batch_result = server_call.start_server_batch([ - cygrpc.SendInitialMetadataOperation( - server_initial_metadata, - _EMPTY_FLAGS), cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS), + cygrpc.SendInitialMetadataOperation(server_initial_metadata, + _EMPTY_FLAGS), + cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS), cygrpc.SendMessageOperation(RESPONSE, _EMPTY_FLAGS), cygrpc.ReceiveCloseOnServerOperation(_EMPTY_FLAGS), cygrpc.SendStatusFromServerOperation( @@ -377,10 +389,11 @@ class InsecureServerInsecureClient(unittest.TestCase, ServerClientMixin): class SecureServerSecureClient(unittest.TestCase, ServerClientMixin): def setUp(self): - server_credentials = cygrpc.server_credentials_ssl(None, [ - cygrpc.SslPemKeyCertPair(resources.private_key(), - resources.certificate_chain()) - ], False) + server_credentials = cygrpc.server_credentials_ssl( + None, [ + cygrpc.SslPemKeyCertPair(resources.private_key(), + resources.certificate_chain()) + ], False) client_credentials = cygrpc.SSLChannelCredentials( resources.test_root_certificates(), None, None) self.setUpMixin(server_credentials, client_credentials, diff --git a/src/python/grpcio_tests/tests/unit/_empty_message_test.py b/src/python/grpcio_tests/tests/unit/_empty_message_test.py index 14695bc13f8..c55ef61c132 100644 --- a/src/python/grpcio_tests/tests/unit/_empty_message_test.py +++ b/src/python/grpcio_tests/tests/unit/_empty_message_test.py @@ -106,13 +106,13 @@ class EmptyMessageTest(unittest.TestCase): list(response_iterator)) def testStreamUnary(self): - response = self._channel.stream_unary(_STREAM_UNARY)( - iter([_REQUEST] * test_constants.STREAM_LENGTH)) + response = self._channel.stream_unary(_STREAM_UNARY)(iter( + [_REQUEST] * test_constants.STREAM_LENGTH)) self.assertEqual(_RESPONSE, response) def testStreamStream(self): - response_iterator = self._channel.stream_stream(_STREAM_STREAM)( - iter([_REQUEST] * test_constants.STREAM_LENGTH)) + response_iterator = self._channel.stream_stream(_STREAM_STREAM)(iter( + [_REQUEST] * test_constants.STREAM_LENGTH)) self.assertSequenceEqual([_RESPONSE] * test_constants.STREAM_LENGTH, list(response_iterator)) diff --git a/src/python/grpcio_tests/tests/unit/_interceptor_test.py b/src/python/grpcio_tests/tests/unit/_interceptor_test.py index 2aee298df21..3d547b71cd5 100644 --- a/src/python/grpcio_tests/tests/unit/_interceptor_test.py +++ b/src/python/grpcio_tests/tests/unit/_interceptor_test.py @@ -65,7 +65,10 @@ class _Handler(object): def handle_unary_unary(self, request, servicer_context): self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) return request def handle_unary_stream(self, request, servicer_context): @@ -74,7 +77,10 @@ class _Handler(object): yield request self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) def handle_stream_unary(self, request_iterator, servicer_context): if servicer_context is not None: @@ -86,13 +92,19 @@ class _Handler(object): response_elements.append(request) self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) return b''.join(response_elements) def handle_stream_stream(self, request_iterator, servicer_context): self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) for request in request_iterator: self._control.control() yield request @@ -162,9 +174,10 @@ def _stream_stream_multi_callable(channel): class _ClientCallDetails( - collections.namedtuple('_ClientCallDetails', - ('method', 'timeout', 'metadata', - 'credentials')), grpc.ClientCallDetails): + collections.namedtuple( + '_ClientCallDetails', + ('method', 'timeout', 'metadata', 'credentials')), + grpc.ClientCallDetails): pass @@ -262,7 +275,10 @@ def _append_request_header_interceptor(header, value): metadata = [] if client_call_details.metadata: metadata = list(client_call_details.metadata) - metadata.append((header, value,)) + metadata.append(( + header, + value, + )) client_call_details = _ClientCallDetails( client_call_details.method, client_call_details.timeout, metadata, client_call_details.credentials) @@ -306,9 +322,11 @@ class InterceptorTest(unittest.TestCase): self._server = grpc.server( self._server_pool, options=(('grpc.so_reuseport', 0),), - interceptors=(_LoggingInterceptor('s1', self._record), - conditional_interceptor, - _LoggingInterceptor('s2', self._record),)) + interceptors=( + _LoggingInterceptor('s1', self._record), + conditional_interceptor, + _LoggingInterceptor('s2', self._record), + )) port = self._server.add_insecure_port('[::]:0') self._server.add_generic_rpc_handlers((_GenericHandler(self._handler),)) self._server.start() @@ -333,8 +351,8 @@ class InterceptorTest(unittest.TestCase): interceptor = _wrap_request_iterator_stream_interceptor(triple) channel = grpc.intercept_channel(self._channel, interceptor) - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) multi_callable = _stream_stream_multi_callable(channel) response_iterator = multi_callable( @@ -365,8 +383,8 @@ class InterceptorTest(unittest.TestCase): multi_callable = _unary_unary_multi_callable(defective_channel) call_future = multi_callable.future( request, - metadata=( - ('test', 'InterceptedUnaryRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'InterceptedUnaryRequestBlockingUnaryResponse'),)) self.assertIsNotNone(call_future.exception()) self.assertEqual(call_future.code(), grpc.StatusCode.INTERNAL) @@ -374,12 +392,14 @@ class InterceptorTest(unittest.TestCase): def testInterceptedHeaderManipulationWithServerSideVerification(self): request = b'\x07\x08' - channel = grpc.intercept_channel( - self._channel, _append_request_header_interceptor('secret', '42')) - channel = grpc.intercept_channel( - channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _append_request_header_interceptor( + 'secret', '42')) + channel = grpc.intercept_channel(channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) self._record[:] = [] @@ -401,16 +421,17 @@ class InterceptorTest(unittest.TestCase): self._record[:] = [] - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) multi_callable = _unary_unary_multi_callable(channel) multi_callable( request, - metadata=( - ('test', 'InterceptedUnaryRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'InterceptedUnaryRequestBlockingUnaryResponse'),)) self.assertSequenceEqual(self._record, [ 'c1:intercept_unary_unary', 'c2:intercept_unary_unary', @@ -420,10 +441,11 @@ class InterceptorTest(unittest.TestCase): def testInterceptedUnaryRequestBlockingUnaryResponseWithCall(self): request = b'\x07\x08' - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) self._record[:] = [] @@ -443,10 +465,11 @@ class InterceptorTest(unittest.TestCase): request = b'\x07\x08' self._record[:] = [] - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) multi_callable = _unary_unary_multi_callable(channel) response_future = multi_callable.future( @@ -463,10 +486,11 @@ class InterceptorTest(unittest.TestCase): request = b'\x37\x58' self._record[:] = [] - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) multi_callable = _unary_stream_multi_callable(channel) response_iterator = multi_callable( @@ -480,21 +504,22 @@ class InterceptorTest(unittest.TestCase): ]) def testInterceptedStreamRequestBlockingUnaryResponse(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) self._record[:] = [] - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) multi_callable = _stream_unary_multi_callable(channel) multi_callable( request_iterator, - metadata=( - ('test', 'InterceptedStreamRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'InterceptedStreamRequestBlockingUnaryResponse'),)) self.assertSequenceEqual(self._record, [ 'c1:intercept_stream_unary', 'c2:intercept_stream_unary', @@ -502,15 +527,16 @@ class InterceptorTest(unittest.TestCase): ]) def testInterceptedStreamRequestBlockingUnaryResponseWithCall(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) self._record[:] = [] - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) multi_callable = _stream_unary_multi_callable(channel) multi_callable.with_call( @@ -525,15 +551,16 @@ class InterceptorTest(unittest.TestCase): ]) def testInterceptedStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) self._record[:] = [] - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) multi_callable = _stream_unary_multi_callable(channel) response_future = multi_callable.future( @@ -547,15 +574,16 @@ class InterceptorTest(unittest.TestCase): ]) def testInterceptedStreamRequestStreamResponse(self): - requests = tuple(b'\x77\x58' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x77\x58' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) self._record[:] = [] - channel = grpc.intercept_channel( - self._channel, - _LoggingInterceptor('c1', self._record), - _LoggingInterceptor('c2', self._record)) + channel = grpc.intercept_channel(self._channel, + _LoggingInterceptor( + 'c1', self._record), + _LoggingInterceptor( + 'c2', self._record)) multi_callable = _stream_stream_multi_callable(channel) response_iterator = multi_callable( diff --git a/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py b/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py index 8f4c075e2cf..4edf0fc4adc 100644 --- a/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py +++ b/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py @@ -106,8 +106,8 @@ class InvalidMetadataTest(unittest.TestCase): self.assertEqual(response_iterator.code(), grpc.StatusCode.INTERNAL) def testStreamRequestBlockingUnaryResponse(self): - request_iterator = (b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = ( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) metadata = (('InVaLiD', 'StreamRequestBlockingUnaryResponse'),) expected_error_details = "metadata was invalid: %s" % metadata with self.assertRaises(ValueError) as exception_context: @@ -115,8 +115,8 @@ class InvalidMetadataTest(unittest.TestCase): self.assertIn(expected_error_details, str(exception_context.exception)) def testStreamRequestBlockingUnaryResponseWithCall(self): - request_iterator = (b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = ( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) metadata = (('InVaLiD', 'StreamRequestBlockingUnaryResponseWithCall'),) expected_error_details = "metadata was invalid: %s" % metadata multi_callable = _stream_unary_multi_callable(self._channel) @@ -125,8 +125,8 @@ class InvalidMetadataTest(unittest.TestCase): self.assertIn(expected_error_details, str(exception_context.exception)) def testStreamRequestFutureUnaryResponse(self): - request_iterator = (b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = ( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) metadata = (('InVaLiD', 'StreamRequestFutureUnaryResponse'),) expected_error_details = "metadata was invalid: %s" % metadata response_future = self._stream_unary.future( @@ -141,8 +141,8 @@ class InvalidMetadataTest(unittest.TestCase): self.assertEqual(response_future.code(), grpc.StatusCode.INTERNAL) def testStreamRequestStreamResponse(self): - request_iterator = (b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = ( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) metadata = (('InVaLiD', 'StreamRequestStreamResponse'),) expected_error_details = "metadata was invalid: %s" % metadata response_iterator = self._stream_stream( diff --git a/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py b/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py index b46d176d044..e40cca8b24c 100644 --- a/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py +++ b/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py @@ -62,7 +62,10 @@ class _Handler(object): def handle_unary_unary(self, request, servicer_context): self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) return request def handle_unary_stream(self, request, servicer_context): @@ -71,7 +74,10 @@ class _Handler(object): yield request self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) def handle_stream_unary(self, request_iterator, servicer_context): if servicer_context is not None: @@ -83,13 +89,19 @@ class _Handler(object): response_elements.append(request) self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) return b''.join(response_elements) def handle_stream_stream(self, request_iterator, servicer_context): self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) for request in request_iterator: self._control.control() yield request @@ -208,8 +220,8 @@ class InvocationDefectsTest(unittest.TestCase): with self.assertRaises(grpc.RpcError): response = multi_callable( requests, - metadata=( - ('test', 'IterableStreamRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'IterableStreamRequestBlockingUnaryResponse'),)) def testIterableStreamRequestFutureUnaryResponse(self): requests = [b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)] diff --git a/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py b/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py index ec67f99fbc0..bb6ac704970 100644 --- a/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py +++ b/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py @@ -36,16 +36,16 @@ _UNARY_STREAM = 'UnaryStream' _STREAM_UNARY = 'StreamUnary' _STREAM_STREAM = 'StreamStream' -_CLIENT_METADATA = (('client-md-key', 'client-md-key'), - ('client-md-key-bin', b'\x00\x01')) +_CLIENT_METADATA = (('client-md-key', 'client-md-key'), ('client-md-key-bin', + b'\x00\x01')) -_SERVER_INITIAL_METADATA = ( - ('server-initial-md-key', 'server-initial-md-value'), - ('server-initial-md-key-bin', b'\x00\x02')) +_SERVER_INITIAL_METADATA = (('server-initial-md-key', + 'server-initial-md-value'), + ('server-initial-md-key-bin', b'\x00\x02')) -_SERVER_TRAILING_METADATA = ( - ('server-trailing-md-key', 'server-trailing-md-value'), - ('server-trailing-md-key-bin', b'\x00\x03')) +_SERVER_TRAILING_METADATA = (('server-trailing-md-key', + 'server-trailing-md-value'), + ('server-trailing-md-key-bin', b'\x00\x03')) _NON_OK_CODE = grpc.StatusCode.NOT_FOUND _DETAILS = 'Test details!' @@ -193,17 +193,33 @@ class MetadataCodeDetailsTest(unittest.TestCase): channel = grpc.insecure_channel('localhost:{}'.format(port)) self._unary_unary = channel.unary_unary( - '/'.join(('', _SERVICE, _UNARY_UNARY,)), + '/'.join(( + '', + _SERVICE, + _UNARY_UNARY, + )), request_serializer=_REQUEST_SERIALIZER, - response_deserializer=_RESPONSE_DESERIALIZER,) - self._unary_stream = channel.unary_stream( - '/'.join(('', _SERVICE, _UNARY_STREAM,)),) - self._stream_unary = channel.stream_unary( - '/'.join(('', _SERVICE, _STREAM_UNARY,)),) + response_deserializer=_RESPONSE_DESERIALIZER, + ) + self._unary_stream = channel.unary_stream('/'.join(( + '', + _SERVICE, + _UNARY_STREAM, + )),) + self._stream_unary = channel.stream_unary('/'.join(( + '', + _SERVICE, + _STREAM_UNARY, + )),) self._stream_stream = channel.stream_stream( - '/'.join(('', _SERVICE, _STREAM_STREAM,)), + '/'.join(( + '', + _SERVICE, + _STREAM_STREAM, + )), request_serializer=_REQUEST_SERIALIZER, - response_deserializer=_RESPONSE_DESERIALIZER,) + response_deserializer=_RESPONSE_DESERIALIZER, + ) def testSuccessfulUnaryUnary(self): self._servicer.set_details(_DETAILS) diff --git a/src/python/grpcio_tests/tests/unit/_metadata_test.py b/src/python/grpcio_tests/tests/unit/_metadata_test.py index f2dac7bdc54..a918066ea48 100644 --- a/src/python/grpcio_tests/tests/unit/_metadata_test.py +++ b/src/python/grpcio_tests/tests/unit/_metadata_test.py @@ -33,18 +33,50 @@ _UNARY_STREAM = '/test/UnaryStream' _STREAM_UNARY = '/test/StreamUnary' _STREAM_STREAM = '/test/StreamStream' -_INVOCATION_METADATA = ((b'invocation-md-key', u'invocation-md-value',), - (u'invocation-md-key-bin', b'\x00\x01',),) -_EXPECTED_INVOCATION_METADATA = (('invocation-md-key', 'invocation-md-value',), - ('invocation-md-key-bin', b'\x00\x01',),) +_INVOCATION_METADATA = ( + ( + b'invocation-md-key', + u'invocation-md-value', + ), + ( + u'invocation-md-key-bin', + b'\x00\x01', + ), +) +_EXPECTED_INVOCATION_METADATA = ( + ( + 'invocation-md-key', + 'invocation-md-value', + ), + ( + 'invocation-md-key-bin', + b'\x00\x01', + ), +) _INITIAL_METADATA = ((b'initial-md-key', u'initial-md-value'), (u'initial-md-key-bin', b'\x00\x02')) -_EXPECTED_INITIAL_METADATA = (('initial-md-key', 'initial-md-value',), - ('initial-md-key-bin', b'\x00\x02',),) - -_TRAILING_METADATA = (('server-trailing-md-key', 'server-trailing-md-value',), - ('server-trailing-md-key-bin', b'\x00\x03',),) +_EXPECTED_INITIAL_METADATA = ( + ( + 'initial-md-key', + 'initial-md-value', + ), + ( + 'initial-md-key-bin', + b'\x00\x02', + ), +) + +_TRAILING_METADATA = ( + ( + 'server-trailing-md-key', + 'server-trailing-md-value', + ), + ( + 'server-trailing-md-key-bin', + b'\x00\x03', + ), +) _EXPECTED_TRAILING_METADATA = _TRAILING_METADATA @@ -146,8 +178,8 @@ class MetadataTest(unittest.TestCase): def setUp(self): self._server = test_common.test_server() - self._server.add_generic_rpc_handlers( - (_GenericHandler(weakref.proxy(self)),)) + self._server.add_generic_rpc_handlers((_GenericHandler( + weakref.proxy(self)),)) port = self._server.add_insecure_port('[::]:0') self._server.start() self._channel = grpc.insecure_channel( diff --git a/src/python/grpcio_tests/tests/unit/_rpc_test.py b/src/python/grpcio_tests/tests/unit/_rpc_test.py index 1515a87d935..54f01d9f8dd 100644 --- a/src/python/grpcio_tests/tests/unit/_rpc_test.py +++ b/src/python/grpcio_tests/tests/unit/_rpc_test.py @@ -64,7 +64,10 @@ class _Handler(object): def handle_unary_unary(self, request, servicer_context): self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) # TODO(https://github.com/grpc/grpc/issues/8483): test the values # returned by these methods rather than only "smoke" testing that # the return after having been called. @@ -78,7 +81,10 @@ class _Handler(object): yield request self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) def handle_stream_unary(self, request_iterator, servicer_context): if servicer_context is not None: @@ -90,13 +96,19 @@ class _Handler(object): response_elements.append(request) self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) return b''.join(response_elements) def handle_stream_stream(self, request_iterator, servicer_context): self._control.control() if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue', + ),)) for request in request_iterator: self._control.control() yield request @@ -244,8 +256,8 @@ class RPCTest(unittest.TestCase): self.assertSequenceEqual(expected_responses, responses) def testSuccessfulStreamRequestBlockingUnaryResponse(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) expected_response = self._handler.handle_stream_unary( iter(requests), None) request_iterator = iter(requests) @@ -253,14 +265,14 @@ class RPCTest(unittest.TestCase): multi_callable = _stream_unary_multi_callable(self._channel) response = multi_callable( request_iterator, - metadata=( - ('test', 'SuccessfulStreamRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'SuccessfulStreamRequestBlockingUnaryResponse'),)) self.assertEqual(expected_response, response) def testSuccessfulStreamRequestBlockingUnaryResponseWithCall(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) expected_response = self._handler.handle_stream_unary( iter(requests), None) request_iterator = iter(requests) @@ -276,8 +288,8 @@ class RPCTest(unittest.TestCase): self.assertIs(grpc.StatusCode.OK, call.code()) def testSuccessfulStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) expected_response = self._handler.handle_stream_unary( iter(requests), None) request_iterator = iter(requests) @@ -293,8 +305,8 @@ class RPCTest(unittest.TestCase): self.assertIsNone(response_future.traceback()) def testSuccessfulStreamRequestStreamResponse(self): - requests = tuple(b'\x77\x58' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x77\x58' for _ in range(test_constants.STREAM_LENGTH)) expected_responses = tuple( self._handler.handle_stream_stream(iter(requests), None)) request_iterator = iter(requests) @@ -326,8 +338,8 @@ class RPCTest(unittest.TestCase): def testConcurrentBlockingInvocations(self): pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) expected_response = self._handler.handle_stream_unary( iter(requests), None) expected_responses = [expected_response @@ -342,15 +354,15 @@ class RPCTest(unittest.TestCase): request_iterator, metadata=(('test', 'ConcurrentBlockingInvocations'),)) response_futures[index] = response_future - responses = tuple(response_future.result() - for response_future in response_futures) + responses = tuple( + response_future.result() for response_future in response_futures) pool.shutdown(wait=True) self.assertSequenceEqual(expected_responses, responses) def testConcurrentFutureInvocations(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) expected_response = self._handler.handle_stream_unary( iter(requests), None) expected_responses = [expected_response @@ -364,8 +376,8 @@ class RPCTest(unittest.TestCase): request_iterator, metadata=(('test', 'ConcurrentFutureInvocations'),)) response_futures[index] = response_future - responses = tuple(response_future.result() - for response_future in response_futures) + responses = tuple( + response_future.result() for response_future in response_futures) self.assertSequenceEqual(expected_responses, responses) @@ -424,14 +436,14 @@ class RPCTest(unittest.TestCase): multi_callable = _unary_stream_multi_callable(self._channel) response_iterator = multi_callable( request, - metadata=( - ('test', 'ConsumingSomeButNotAllStreamResponsesUnaryRequest'),)) + metadata=(('test', + 'ConsumingSomeButNotAllStreamResponsesUnaryRequest'),)) for _ in range(test_constants.STREAM_LENGTH // 2): next(response_iterator) def testConsumingSomeButNotAllStreamResponsesStreamRequest(self): - requests = tuple(b'\x67\x88' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_stream_multi_callable(self._channel) @@ -443,15 +455,15 @@ class RPCTest(unittest.TestCase): next(response_iterator) def testConsumingTooManyStreamResponsesStreamRequest(self): - requests = tuple(b'\x67\x88' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_stream_multi_callable(self._channel) response_iterator = multi_callable( request_iterator, - metadata=( - ('test', 'ConsumingTooManyStreamResponsesStreamRequest'),)) + metadata=(('test', + 'ConsumingTooManyStreamResponsesStreamRequest'),)) for _ in range(test_constants.STREAM_LENGTH): next(response_iterator) for _ in range(test_constants.STREAM_LENGTH): @@ -503,8 +515,8 @@ class RPCTest(unittest.TestCase): self.assertIsNotNone(response_iterator.trailing_metadata()) def testCancelledStreamRequestUnaryResponse(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_unary_multi_callable(self._channel) @@ -528,8 +540,8 @@ class RPCTest(unittest.TestCase): self.assertIsNotNone(response_future.trailing_metadata()) def testCancelledStreamRequestStreamResponse(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_stream_multi_callable(self._channel) @@ -555,8 +567,8 @@ class RPCTest(unittest.TestCase): multi_callable.with_call( request, timeout=test_constants.SHORT_TIMEOUT, - metadata=( - ('test', 'ExpiredUnaryRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'ExpiredUnaryRequestBlockingUnaryResponse'),)) self.assertIsInstance(exception_context.exception, grpc.Call) self.assertIsNotNone(exception_context.exception.initial_metadata()) @@ -610,8 +622,8 @@ class RPCTest(unittest.TestCase): response_iterator.code()) def testExpiredStreamRequestBlockingUnaryResponse(self): - requests = tuple(b'\x07\x08' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_unary_multi_callable(self._channel) @@ -620,8 +632,8 @@ class RPCTest(unittest.TestCase): multi_callable( request_iterator, timeout=test_constants.SHORT_TIMEOUT, - metadata=( - ('test', 'ExpiredStreamRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'ExpiredStreamRequestBlockingUnaryResponse'),)) self.assertIsInstance(exception_context.exception, grpc.RpcError) self.assertIsInstance(exception_context.exception, grpc.Call) @@ -632,8 +644,8 @@ class RPCTest(unittest.TestCase): self.assertIsNotNone(exception_context.exception.trailing_metadata()) def testExpiredStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x18' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) callback = _Callback() @@ -644,8 +656,8 @@ class RPCTest(unittest.TestCase): timeout=test_constants.SHORT_TIMEOUT, metadata=(('test', 'ExpiredStreamRequestFutureUnaryResponse'),)) with self.assertRaises(grpc.FutureTimeoutError): - response_future.result(timeout=test_constants.SHORT_TIMEOUT / - 2.0) + response_future.result( + timeout=test_constants.SHORT_TIMEOUT / 2.0) response_future.add_done_callback(callback) value_passed_to_callback = callback.value() @@ -663,8 +675,8 @@ class RPCTest(unittest.TestCase): self.assertIsNotNone(response_future.trailing_metadata()) def testExpiredStreamRequestStreamResponse(self): - requests = tuple(b'\x67\x18' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x67\x18' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_stream_multi_callable(self._channel) @@ -689,8 +701,8 @@ class RPCTest(unittest.TestCase): with self.assertRaises(grpc.RpcError) as exception_context: multi_callable.with_call( request, - metadata=( - ('test', 'FailedUnaryRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'FailedUnaryRequestBlockingUnaryResponse'),)) self.assertIs(grpc.StatusCode.UNKNOWN, exception_context.exception.code()) @@ -734,8 +746,8 @@ class RPCTest(unittest.TestCase): exception_context.exception.code()) def testFailedStreamRequestBlockingUnaryResponse(self): - requests = tuple(b'\x47\x58' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x47\x58' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_unary_multi_callable(self._channel) @@ -743,15 +755,15 @@ class RPCTest(unittest.TestCase): with self.assertRaises(grpc.RpcError) as exception_context: multi_callable( request_iterator, - metadata=( - ('test', 'FailedStreamRequestBlockingUnaryResponse'),)) + metadata=(('test', + 'FailedStreamRequestBlockingUnaryResponse'),)) self.assertIs(grpc.StatusCode.UNKNOWN, exception_context.exception.code()) def testFailedStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x18' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) callback = _Callback() @@ -773,8 +785,8 @@ class RPCTest(unittest.TestCase): self.assertIs(response_future, value_passed_to_callback) def testFailedStreamRequestStreamResponse(self): - requests = tuple(b'\x67\x88' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_stream_multi_callable(self._channel) @@ -805,8 +817,8 @@ class RPCTest(unittest.TestCase): request, metadata=(('test', 'IgnoredUnaryRequestStreamResponse'),)) def testIgnoredStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x18' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_unary_multi_callable(self._channel) @@ -815,8 +827,8 @@ class RPCTest(unittest.TestCase): metadata=(('test', 'IgnoredStreamRequestFutureUnaryResponse'),)) def testIgnoredStreamRequestStreamResponse(self): - requests = tuple(b'\x67\x88' - for _ in range(test_constants.STREAM_LENGTH)) + requests = tuple( + b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) request_iterator = iter(requests) multi_callable = _stream_stream_multi_callable(self._channel) diff --git a/src/python/grpcio_tests/tests/unit/_server_ssl_cert_config_test.py b/src/python/grpcio_tests/tests/unit/_server_ssl_cert_config_test.py index 2c513da5d00..0d78034b7be 100644 --- a/src/python/grpcio_tests/tests/unit/_server_ssl_cert_config_test.py +++ b/src/python/grpcio_tests/tests/unit/_server_ssl_cert_config_test.py @@ -74,7 +74,8 @@ def _create_client_stub( expect_success, root_certificates=None, private_key=None, - certificate_chain=None,): + certificate_chain=None, +): channel = grpc.secure_channel('localhost:{}'.format(port), grpc.ssl_channel_credentials( root_certificates=root_certificates, diff --git a/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py b/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py index fe3e71d6868..18f5af058a6 100644 --- a/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py +++ b/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py @@ -52,7 +52,9 @@ class CleanupThreadTest(unittest.TestCase): target=target, name='test-name', args=('arg1', 'arg2'), - kwargs={'arg3': 'arg3'}) + kwargs={ + 'arg3': 'arg3' + }) cleanup_thread.start() cleanup_thread.join() self.assertEqual(cleanup_thread.name, 'test-name') diff --git a/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py b/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py index eb8dc80a6e2..61c03f64bac 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py @@ -163,7 +163,10 @@ class BetaFeaturesTest(unittest.TestCase): self._server = implementations.server( method_implementations, options=server_options) server_credentials = implementations.ssl_server_credentials([ - (resources.private_key(), resources.certificate_chain(),), + ( + resources.private_key(), + resources.certificate_chain(), + ), ]) port = self._server.add_secure_port('[::]:0', server_credentials) self._server.start() @@ -289,7 +292,10 @@ class ContextManagementAndLifecycleTest(unittest.TestCase): self._server_options = implementations.server_options( thread_pool_size=test_constants.POOL_SIZE) self._server_credentials = implementations.ssl_server_credentials([ - (resources.private_key(), resources.certificate_chain(),), + ( + resources.private_key(), + resources.certificate_chain(), + ), ]) self._channel_credentials = implementations.ssl_channel_credentials( resources.test_root_certificates()) diff --git a/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py b/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py index e4b81e7e78f..c99738e085c 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py @@ -32,8 +32,11 @@ _SERVER_HOST_OVERRIDE = 'foo.test.google.fr' class _SerializationBehaviors( collections.namedtuple('_SerializationBehaviors', ( - 'request_serializers', 'request_deserializers', - 'response_serializers', 'response_deserializers',))): + 'request_serializers', + 'request_deserializers', + 'response_serializers', + 'response_deserializers', + ))): pass @@ -73,7 +76,10 @@ class _Implementation(test_interfaces.Implementation): server = implementations.server( method_implementations, options=server_options) server_credentials = implementations.ssl_server_credentials([ - (resources.private_key(), resources.certificate_chain(),), + ( + resources.private_key(), + resources.certificate_chain(), + ), ]) port = server.add_secure_port('[::]:0', server_credentials) server.start() @@ -116,9 +122,10 @@ class _Implementation(test_interfaces.Implementation): def load_tests(loader, tests, pattern): - return unittest.TestSuite(tests=tuple( - loader.loadTestsFromTestCase(test_case_class) - for test_case_class in test_cases.test_cases(_Implementation()))) + return unittest.TestSuite( + tests=tuple( + loader.loadTestsFromTestCase(test_case_class) + for test_case_class in test_cases.test_cases(_Implementation()))) if __name__ == '__main__': diff --git a/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py b/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py index 75a615eeffb..5a53766d297 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py @@ -41,8 +41,8 @@ class CallCredentialsTest(unittest.TestCase): def test_google_call_credentials(self): creds = oauth2client_client.GoogleCredentials( 'token', 'client_id', 'secret', 'refresh_token', - datetime.datetime(2008, 6, 24), 'https://refresh.uri.com/', - 'user_agent') + datetime.datetime(2008, 6, + 24), 'https://refresh.uri.com/', 'user_agent') call_creds = implementations.google_call_credentials(creds) self.assertIsInstance(call_creds, implementations.CallCredentials) diff --git a/src/python/grpcio_tests/tests/unit/beta/test_utilities.py b/src/python/grpcio_tests/tests/unit/beta/test_utilities.py index 65da0f2020d..c8d920d35e9 100644 --- a/src/python/grpcio_tests/tests/unit/beta/test_utilities.py +++ b/src/python/grpcio_tests/tests/unit/beta/test_utilities.py @@ -33,6 +33,8 @@ def not_really_secure_channel(host, port, channel_credentials, conducted. """ target = '%s:%d' % (host, port) - channel = grpc.secure_channel(target, channel_credentials, ( - ('grpc.ssl_target_name_override', server_host_override,),)) + channel = grpc.secure_channel(target, channel_credentials, (( + 'grpc.ssl_target_name_override', + server_host_override, + ),)) return implementations.Channel(channel) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py index 45fd321ed67..5d8679aa62a 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py @@ -70,8 +70,8 @@ class TestCase( self.implementation.destantiate(self._memo) def testSuccessfulUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -81,8 +81,8 @@ class TestCase( test_messages.verify(request, response, self) def testSuccessfulUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_stream_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -93,8 +93,8 @@ class TestCase( test_messages.verify(request, responses, self) def testSuccessfulStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() @@ -104,8 +104,8 @@ class TestCase( test_messages.verify(requests, response, self) def testSuccessfulStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_stream_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() @@ -116,8 +116,8 @@ class TestCase( test_messages.verify(requests, responses, self) def testSequentialInvocations(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: first_request = test_messages.request() second_request = test_messages.request() @@ -134,8 +134,8 @@ class TestCase( def testParallelInvocations(self): pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = [] response_futures = [] @@ -158,8 +158,8 @@ class TestCase( def testWaitingForSomeButNotAllParallelInvocations(self): pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = [] response_futures_to_indices = {} @@ -197,8 +197,8 @@ class TestCase( raise NotImplementedError() def testExpiredUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -208,8 +208,8 @@ class TestCase( request, _3069_test_constant.REALLY_SHORT_TIMEOUT) def testExpiredUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_stream_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -220,33 +220,33 @@ class TestCase( list(response_iterator) def testExpiredStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() with self._control.pause(), self.assertRaises( face.ExpirationError): - self._invoker.blocking(group, method)( - iter(requests), - _3069_test_constant.REALLY_SHORT_TIMEOUT) + self._invoker.blocking( + group, method)(iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) def testExpiredStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_stream_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() with self._control.pause(), self.assertRaises( face.ExpirationError): - response_iterator = self._invoker.blocking(group, method)( - iter(requests), - _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_iterator = self._invoker.blocking( + group, method)(iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) list(response_iterator) def testFailedUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -255,8 +255,8 @@ class TestCase( request, test_constants.LONG_TIMEOUT) def testFailedUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_stream_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -266,8 +266,8 @@ class TestCase( list(response_iterator) def testFailedStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() @@ -276,8 +276,8 @@ class TestCase( iter(requests), test_constants.LONG_TIMEOUT) def testFailedStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_stream_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py index 0e399c4bc44..b1c33da43a8 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py @@ -34,11 +34,15 @@ _IDENTITY = lambda x: x class TestServiceDigest( collections.namedtuple('TestServiceDigest', ( - 'methods', 'inline_method_implementations', - 'event_method_implementations', 'multi_method_implementation', - 'unary_unary_messages_sequences', 'unary_stream_messages_sequences', + 'methods', + 'inline_method_implementations', + 'event_method_implementations', + 'multi_method_implementation', + 'unary_unary_messages_sequences', + 'unary_stream_messages_sequences', 'stream_unary_messages_sequences', - 'stream_stream_messages_sequences',))): + 'stream_stream_messages_sequences', + ))): """A transformation of a service.TestService. Attributes: @@ -421,8 +425,8 @@ def digest(service, control, pool): events.update(stream_unary.events) events.update(stream_stream.events) - return TestServiceDigest( - methods, inlines, events, - _MultiMethodImplementation(adaptations, control, pool), - unary_unary.messages, unary_stream.messages, stream_unary.messages, - stream_stream.messages) + return TestServiceDigest(methods, inlines, events, + _MultiMethodImplementation(adaptations, control, + pool), + unary_unary.messages, unary_stream.messages, + stream_unary.messages, stream_stream.messages) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py index bc65bf4c807..3d9b2816aa7 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py @@ -134,8 +134,8 @@ class TestCase( self._digest_pool.shutdown(wait=True) def testSuccessfulUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() callback = _Callback() @@ -151,8 +151,8 @@ class TestCase( self.assertIsNone(response_future.traceback()) def testSuccessfulUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_stream_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -163,8 +163,8 @@ class TestCase( test_messages.verify(request, responses, self) def testSuccessfulStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() request_iterator = _PauseableIterator(iter(requests)) @@ -185,8 +185,8 @@ class TestCase( self.assertIsNone(response_future.traceback()) def testSuccessfulStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_stream_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() request_iterator = _PauseableIterator(iter(requests)) @@ -201,8 +201,8 @@ class TestCase( test_messages.verify(requests, responses, self) def testSequentialInvocations(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: first_request = test_messages.request() second_request = test_messages.request() @@ -220,8 +220,8 @@ class TestCase( test_messages.verify(second_request, second_response, self) def testParallelInvocations(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: first_request = test_messages.request() second_request = test_messages.request() @@ -236,8 +236,8 @@ class TestCase( test_messages.verify(first_request, first_response, self) test_messages.verify(second_request, second_response, self) - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = [] response_futures = [] @@ -258,8 +258,8 @@ class TestCase( def testWaitingForSomeButNotAllParallelInvocations(self): pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = [] response_futures_to_indices = {} @@ -282,8 +282,8 @@ class TestCase( pool.shutdown(wait=True) def testCancelledUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() callback = _Callback() @@ -305,8 +305,8 @@ class TestCase( response_future.traceback() def testCancelledUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_stream_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -319,8 +319,8 @@ class TestCase( next(response_iterator) def testCancelledStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() callback = _Callback() @@ -342,8 +342,8 @@ class TestCase( response_future.traceback() def testCancelledStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_stream_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() @@ -356,8 +356,8 @@ class TestCase( next(response_iterator) def testExpiredUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() callback = _Callback() @@ -376,8 +376,8 @@ class TestCase( self.assertIsNotNone(response_future.traceback()) def testExpiredUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_stream_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -388,16 +388,16 @@ class TestCase( list(response_iterator) def testExpiredStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() callback = _Callback() with self._control.pause(): - response_future = self._invoker.future(group, method)( - iter(requests), - _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_future = self._invoker.future( + group, method)(iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) response_future.add_done_callback(callback) self.assertIs(callback.future(), response_future) self.assertIsInstance(response_future.exception(), @@ -409,21 +409,21 @@ class TestCase( self.assertIsNotNone(response_future.traceback()) def testExpiredStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_stream_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() with self._control.pause(): - response_iterator = self._invoker.future(group, method)( - iter(requests), - _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_iterator = self._invoker.future( + group, method)(iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) with self.assertRaises(face.ExpirationError): list(response_iterator) def testFailedUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_unary_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() callback = _Callback() @@ -448,8 +448,8 @@ class TestCase( self.assertIsNotNone(abortion_callback.future()) def testFailedUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.unary_stream_messages_sequences)): for test_messages in test_messages_sequence: request = test_messages.request() @@ -464,17 +464,17 @@ class TestCase( list(response_iterator) def testFailedStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_unary_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() callback = _Callback() abortion_callback = _Callback() with self._control.fail(): - response_future = self._invoker.future(group, method)( - iter(requests), - _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_future = self._invoker.future( + group, method)(iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) response_future.add_done_callback(callback) response_future.add_abortion_callback(abortion_callback) @@ -491,8 +491,8 @@ class TestCase( self.assertIsNotNone(abortion_callback.future()) def testFailedStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): + for (group, method), test_messages_sequence in (six.iteritems( + self._digest.stream_stream_messages_sequences)): for test_messages in test_messages_sequence: requests = test_messages.requests() @@ -502,7 +502,7 @@ class TestCase( # expiration of the RPC. with self._control.fail(), self.assertRaises( face.ExpirationError): - response_iterator = self._invoker.future(group, method)( - iter(requests), - _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_iterator = self._invoker.future( + group, method)(iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) list(response_iterator) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py index fd55f4e09ff..efc93d56b0b 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py @@ -191,5 +191,8 @@ def invoker_constructors(): Returns: A sequence of InvokerConstructors. """ - return (_GenericInvokerConstructor(), _MultiCallableInvokerConstructor(), - _DynamicInvokerConstructor(),) + return ( + _GenericInvokerConstructor(), + _MultiCallableInvokerConstructor(), + _DynamicInvokerConstructor(), + ) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py index 69c7ac2d738..a84e02a79a4 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py @@ -33,8 +33,8 @@ def _get_last_trade_price(stock_request, stock_reply_callback, control, active): if active(): stock_reply_callback( stock_pb2.StockReply( - symbol=stock_request.symbol, price=_price( - stock_request.symbol))) + symbol=stock_request.symbol, + price=_price(stock_request.symbol))) else: raise abandonment.Abandoned() diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py index d1c5b8f76b0..cff4b7cdea5 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py @@ -24,7 +24,8 @@ from tests.unit.framework.interfaces.face import test_interfaces # pylint: disa _TEST_CASE_SUPERCLASSES = ( _blocking_invocation_inline_service.TestCase, - _future_invocation_asynchronous_event_service.TestCase,) + _future_invocation_asynchronous_event_service.TestCase, +) def test_cases(implementation): @@ -42,8 +43,9 @@ def test_cases(implementation): for invoker_constructor in _invocation.invoker_constructors(): for super_class in _TEST_CASE_SUPERCLASSES: test_case_classes.append( - type(invoker_constructor.name() + super_class.NAME, ( - super_class,), { + type( + invoker_constructor.name() + super_class.NAME, + (super_class,), { 'implementation': implementation, 'invoker_constructor': invoker_constructor, '__module__': implementation.__module__, diff --git a/src/python/grpcio_tests/tests/unit/resources.py b/src/python/grpcio_tests/tests/unit/resources.py index 11ef9e85656..51a8979f589 100644 --- a/src/python/grpcio_tests/tests/unit/resources.py +++ b/src/python/grpcio_tests/tests/unit/resources.py @@ -58,7 +58,8 @@ def cert_hier_1_client_1_key(): def cert_hier_1_client_1_cert(): return pkg_resources.resource_string( __name__, - 'credentials/certificate_hierarchy_1/intermediate/certs/client.cert.pem') + 'credentials/certificate_hierarchy_1/intermediate/certs/client.cert.pem' + ) def cert_hier_1_server_1_key(): @@ -97,7 +98,8 @@ def cert_hier_2_client_1_key(): def cert_hier_2_client_1_cert(): return pkg_resources.resource_string( __name__, - 'credentials/certificate_hierarchy_2/intermediate/certs/client.cert.pem') + 'credentials/certificate_hierarchy_2/intermediate/certs/client.cert.pem' + ) def cert_hier_2_server_1_key(): diff --git a/src/python/grpcio_tests/tests/unit/test_common.py b/src/python/grpcio_tests/tests/unit/test_common.py index 6334a32b0ed..61717ae1358 100644 --- a/src/python/grpcio_tests/tests/unit/test_common.py +++ b/src/python/grpcio_tests/tests/unit/test_common.py @@ -19,9 +19,21 @@ from concurrent import futures import grpc import six -INVOCATION_INITIAL_METADATA = (('0', 'abc'), ('1', 'def'), ('2', 'ghi'),) -SERVICE_INITIAL_METADATA = (('3', 'jkl'), ('4', 'mno'), ('5', 'pqr'),) -SERVICE_TERMINAL_METADATA = (('6', 'stu'), ('7', 'vwx'), ('8', 'yza'),) +INVOCATION_INITIAL_METADATA = ( + ('0', 'abc'), + ('1', 'def'), + ('2', 'ghi'), +) +SERVICE_INITIAL_METADATA = ( + ('3', 'jkl'), + ('4', 'mno'), + ('5', 'pqr'), +) +SERVICE_TERMINAL_METADATA = ( + ('6', 'stu'), + ('7', 'vwx'), + ('8', 'yza'), +) DETAILS = 'test details' @@ -80,8 +92,10 @@ def test_secure_channel(target, channel_credentials, server_host_override): An implementations.Channel to the remote host through which RPCs may be conducted. """ - channel = grpc.secure_channel(target, channel_credentials, ( - ('grpc.ssl_target_name_override', server_host_override,),)) + channel = grpc.secure_channel(target, channel_credentials, (( + 'grpc.ssl_target_name_override', + server_host_override, + ),)) return channel diff --git a/tools/buildgen/bunch.py b/tools/buildgen/bunch.py index 0ce9a6b233a..f3bfc81102c 100755 --- a/tools/buildgen/bunch.py +++ b/tools/buildgen/bunch.py @@ -48,5 +48,6 @@ def merge_json(dst, add): elif isinstance(dst, list) and isinstance(add, list): dst.extend(add) else: - raise Exception('Tried to merge incompatible objects %s %s\n\n%r\n\n%r' - % (type(dst).__name__, type(add).__name__, dst, add)) + raise Exception( + 'Tried to merge incompatible objects %s %s\n\n%r\n\n%r' % + (type(dst).__name__, type(add).__name__, dst, add)) diff --git a/tools/buildgen/mako_renderer.py b/tools/buildgen/mako_renderer.py index 0569fa14d27..acd72bd2e33 100755 --- a/tools/buildgen/mako_renderer.py +++ b/tools/buildgen/mako_renderer.py @@ -99,10 +99,10 @@ def main(argv): elif opt == '-P': assert not got_preprocessed_input assert json_dict == {} - sys.path.insert( - 0, - os.path.abspath( - os.path.join(os.path.dirname(sys.argv[0]), 'plugins'))) + sys.path.insert(0, + os.path.abspath( + os.path.join( + os.path.dirname(sys.argv[0]), 'plugins'))) with open(arg, 'r') as dict_file: dictionary = pickle.load(dict_file) got_preprocessed_input = True diff --git a/tools/buildgen/plugins/expand_filegroups.py b/tools/buildgen/plugins/expand_filegroups.py index 886a59cdbbc..99d9463b3f9 100755 --- a/tools/buildgen/plugins/expand_filegroups.py +++ b/tools/buildgen/plugins/expand_filegroups.py @@ -104,8 +104,7 @@ def mako_plugin(dictionary): # build reverse dependency map things = {} - for thing in dictionary['libs'] + dictionary['targets'] + dictionary[ - 'filegroups']: + for thing in dictionary['libs'] + dictionary['targets'] + dictionary['filegroups']: things[thing['name']] = thing thing['used_by'] = [] thing_deps = lambda t: t.get('uses', []) + t.get('filegroups', []) + t.get('deps', []) @@ -148,7 +147,7 @@ def mako_plugin(dictionary): lib[lst] = vals lib['plugins'] = plugins if lib.get('generate_plugin_registry', False): - lib['src'].append('src/core/plugin_registry/%s_plugin_registry.cc' % - lib['name']) + lib['src'].append( + 'src/core/plugin_registry/%s_plugin_registry.cc' % lib['name']) for lst in FILEGROUP_LISTS: lib[lst] = uniquify(lib.get(lst, [])) diff --git a/tools/buildgen/plugins/generate_vsprojects.py b/tools/buildgen/plugins/generate_vsprojects.py index f6251d46771..f7ef49288f2 100755 --- a/tools/buildgen/plugins/generate_vsprojects.py +++ b/tools/buildgen/plugins/generate_vsprojects.py @@ -56,11 +56,12 @@ def mako_plugin(dictionary): target['vs_props'] = [] target['vs_proj_dir'] = target.get('vs_proj_dir', default_test_dir) if target.get('vs_project_guid', - None) is None and 'windows' in target.get('platforms', - ['windows']): + None) is None and 'windows' in target.get( + 'platforms', ['windows']): name = target['name'] guid = re.sub('(........)(....)(....)(....)(.*)', - r'{\1-\2-\3-\4-\5}', hashlib.md5(name).hexdigest()) + r'{\1-\2-\3-\4-\5}', + hashlib.md5(name).hexdigest()) target['vs_project_guid'] = guid.upper() # Exclude projects without a visual project guid, such as the tests. projects = [ @@ -69,9 +70,9 @@ def mako_plugin(dictionary): projects = [ project for project in projects - if project['language'] != 'c++' or project['build'] == 'all' or project[ - 'build'] == 'protoc' or (project['language'] == 'c++' and (project[ - 'build'] == 'test' or project['build'] == 'private')) + if project['language'] != 'c++' or project['build'] == 'all' or + project['build'] == 'protoc' or (project['language'] == 'c++' and ( + project['build'] == 'test' or project['build'] == 'private')) ] project_dict = dict([(p['name'], p) for p in projects]) diff --git a/tools/buildgen/plugins/transitive_dependencies.py b/tools/buildgen/plugins/transitive_dependencies.py index 5373bca2d1a..258e10bff58 100644 --- a/tools/buildgen/plugins/transitive_dependencies.py +++ b/tools/buildgen/plugins/transitive_dependencies.py @@ -54,5 +54,5 @@ def mako_plugin(dictionary): target['transitive_deps'] = transitive_deps(target, libs) python_dependencies = dictionary.get('python_dependencies') - python_dependencies['transitive_deps'] = ( - transitive_deps(python_dependencies, libs)) + python_dependencies['transitive_deps'] = (transitive_deps( + python_dependencies, libs)) diff --git a/tools/codegen/core/gen_settings_ids.py b/tools/codegen/core/gen_settings_ids.py index bc4380605a6..5c3f066b154 100755 --- a/tools/codegen/core/gen_settings_ids.py +++ b/tools/codegen/core/gen_settings_ids.py @@ -174,10 +174,13 @@ for decorated_setting in sorted(decorated_settings): print >> C, "{NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR}," i += 1 print >> C, "{\"%s\", %du, %du, %du, GRPC_CHTTP2_%s, GRPC_HTTP2_%s}," % ( - decorated_setting.name, decorated_setting.setting.default, - decorated_setting.setting.min, decorated_setting.setting.max, + decorated_setting.name, + decorated_setting.setting.default, + decorated_setting.setting.min, + decorated_setting.setting.max, decorated_setting.setting.on_error.behavior, - decorated_setting.setting.on_error.code,) + decorated_setting.setting.on_error.code, + ) i += 1 print >> C, "};" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 9d99bbf096f..3a171bbfc2c 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -387,8 +387,8 @@ for i, elem in enumerate(all_strs): print >> H, '#define %s (grpc_static_slice_table[%d])' % ( mangle(elem).upper(), i) print >> H -print >> C, 'static uint8_t g_bytes[] = {%s};' % ( - ','.join('%d' % ord(c) for c in ''.join(all_strs))) +print >> C, 'static uint8_t g_bytes[] = {%s};' % (','.join( + '%d' % ord(c) for c in ''.join(all_strs))) print >> C print >> C, 'static void static_ref(void *unused) {}' print >> C, 'static void static_unref(void *unused) {}' @@ -444,8 +444,8 @@ for i, elem in enumerate(all_elems): print >> H print >> C, ('uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] ' '= {') -print >> C, ' %s' % ','.join('%d' % static_userdata.get(elem, 0) - for elem in all_elems) +print >> C, ' %s' % ','.join( + '%d' % static_userdata.get(elem, 0) for elem in all_elems) print >> C, '};' print >> C @@ -520,8 +520,8 @@ for i, k in enumerate(elem_keys): idxs[h] = i print >> C, 'static const uint16_t elem_keys[] = {%s};' % ','.join( '%d' % k for k in keys) -print >> C, 'static const uint8_t elem_idxs[] = {%s};' % ','.join('%d' % i - for i in idxs) +print >> C, 'static const uint8_t elem_idxs[] = {%s};' % ','.join( + '%d' % i for i in idxs) print >> C print >> H, 'grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b);' @@ -579,8 +579,8 @@ print >> H, 'extern const uint8_t grpc_static_accept_stream_encoding_metadata[%d 1 << len(STREAM_COMPRESSION_ALGORITHMS)) print >> C, 'const uint8_t grpc_static_accept_stream_encoding_metadata[%d] = {' % ( 1 << len(STREAM_COMPRESSION_ALGORITHMS)) -print >> C, '0,%s' % ','.join('%d' % md_idx(elem) - for elem in stream_compression_elems) +print >> C, '0,%s' % ','.join( + '%d' % md_idx(elem) for elem in stream_compression_elems) print >> C, '};' print >> H, '#define GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[grpc_static_accept_stream_encoding_metadata[(algs)]], GRPC_MDELEM_STORAGE_STATIC))' diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 93f2035c458..5c9d9e5ea52 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -28,8 +28,8 @@ REQUIRED_FIELDS = ['name', 'doc'] def make_type(name, fields): - return (collections.namedtuple( - name, ' '.join(list(set(REQUIRED_FIELDS + fields)))), []) + return (collections.namedtuple(name, ' '.join( + list(set(REQUIRED_FIELDS + fields)))), []) def c_str(s, encoding='ascii'): @@ -44,7 +44,10 @@ def c_str(s, encoding='ascii'): return '"' + result + '"' -types = (make_type('Counter', []), make_type('Histogram', ['max', 'buckets']),) +types = ( + make_type('Counter', []), + make_type('Histogram', ['max', 'buckets']), +) inst_map = dict((t[0].__name__, t[1]) for t in types) @@ -349,8 +352,8 @@ with open('src/core/lib/debug/stats_data.cc', 'w') as C: print >> C, "const int grpc_stats_histo_start[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('%s' % x for x in histo_start)) print >> C, "const int *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( - len(inst_map['Histogram']), ','.join('grpc_stats_table_%d' % x - for x in histo_bucket_boundaries)) + len(inst_map['Histogram']), ','.join( + 'grpc_stats_table_%d' % x for x in histo_bucket_boundaries)) print >> C, "void (*const grpc_stats_inc_histogram[%d])(int x) = {%s};" % ( len(inst_map['Histogram']), ','.join( 'grpc_stats_inc_%s' % histogram.name.lower() diff --git a/tools/debug/core/error_ref_leak.py b/tools/debug/core/error_ref_leak.py index 78063386836..7e206c26b26 100644 --- a/tools/debug/core/error_ref_leak.py +++ b/tools/debug/core/error_ref_leak.py @@ -39,7 +39,7 @@ for line in data: elif line[0] == "realloc": errs.remove(line[1]) errs.append(line[3]) - # explicitly look for the last dereference + # explicitly look for the last dereference elif line[1] == "1" and line[3] == "0": assert (err in errs) errs.remove(err) diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py index f6e73624a78..8f782e07c25 100755 --- a/tools/distrib/check_copyright.py +++ b/tools/distrib/check_copyright.py @@ -84,13 +84,15 @@ _EXEMPT = frozenset(( # census.proto copied from github 'tools/grpcz/census.proto', # status.proto copied from googleapis - 'src/proto/grpc/status/status.proto',)) + 'src/proto/grpc/status/status.proto', +)) RE_YEAR = r'Copyright (?P[0-9]+\-)?(?P[0-9]+) gRPC authors.' -RE_LICENSE = dict((k, r'\n'.join( - LICENSE_PREFIX[k] + (RE_YEAR - if re.search(RE_YEAR, line) else re.escape(line)) - for line in LICENSE_NOTICE)) for k, v in LICENSE_PREFIX.iteritems()) +RE_LICENSE = dict( + (k, r'\n'.join(LICENSE_PREFIX[k] + + (RE_YEAR if re.search(RE_YEAR, line) else re.escape(line)) + for line in LICENSE_NOTICE)) + for k, v in LICENSE_PREFIX.iteritems()) if args.precommit: FILE_LIST_COMMAND = 'git status -z | grep -Poz \'(?<=^[MARC][MARCD ] )[^\s]+\'' diff --git a/tools/distrib/check_include_guards.py b/tools/distrib/check_include_guards.py index 24e076afda7..6fc606f2ef9 100755 --- a/tools/distrib/check_include_guards.py +++ b/tools/distrib/check_include_guards.py @@ -95,14 +95,14 @@ class GuardValidator(object): # Does the guard end with a '_H'? running_guard = match.group(1) if not running_guard.endswith('_H'): - fcontents = self.fail(fpath, match.re, match.string, - match.group(1), valid_guard, fix) + fcontents = self.fail(fpath, match.re, match.string, match.group(1), + valid_guard, fix) if fix: save(fpath, fcontents) # Is it the expected one based on the file path? if running_guard != valid_guard: - fcontents = self.fail(fpath, match.re, match.string, - match.group(1), valid_guard, fix) + fcontents = self.fail(fpath, match.re, match.string, match.group(1), + valid_guard, fix) if fix: save(fpath, fcontents) # Is there a #define? Is it the same as the #ifndef one? @@ -114,8 +114,8 @@ class GuardValidator(object): # Is the #define guard the same as the #ifndef guard? if match.group(1) != running_guard: - fcontents = self.fail(fpath, match.re, match.string, - match.group(1), valid_guard, fix) + fcontents = self.fail(fpath, match.re, match.string, match.group(1), + valid_guard, fix) if fix: save(fpath, fcontents) # Is there a properly commented #endif? @@ -138,8 +138,8 @@ class GuardValidator(object): self.fail(fpath, endif_re, flines[-1], '', '', False) elif match.group(1) != running_guard: # Is the #endif guard the same as the #ifndef and #define guards? - fcontents = self.fail(fpath, endif_re, fcontents, - match.group(1), valid_guard, fix) + fcontents = self.fail(fpath, endif_re, fcontents, match.group(1), + valid_guard, fix) if fix: save(fpath, fcontents) return not self.failed # Did the check succeed? (ie, not failed) diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/command.py b/tools/distrib/python/grpcio_tools/grpc_tools/command.py index c0f9d93b0aa..7ede05f1404 100644 --- a/tools/distrib/python/grpcio_tools/grpc_tools/command.py +++ b/tools/distrib/python/grpcio_tools/grpc_tools/command.py @@ -30,8 +30,8 @@ def build_package_protos(package_root): proto_files.append( os.path.abspath(os.path.join(root, filename))) - well_known_protos_include = pkg_resources.resource_filename('grpc_tools', - '_proto') + well_known_protos_include = pkg_resources.resource_filename( + 'grpc_tools', '_proto') for proto_file in proto_files: command = [ diff --git a/tools/distrib/python/grpcio_tools/setup.py b/tools/distrib/python/grpcio_tools/setup.py index 342a220d5ed..c6bcee497f0 100644 --- a/tools/distrib/python/grpcio_tools/setup.py +++ b/tools/distrib/python/grpcio_tools/setup.py @@ -196,7 +196,8 @@ def extension_modules(): language='c++', define_macros=list(DEFINE_MACROS), extra_compile_args=list(EXTRA_COMPILE_ARGS), - extra_link_args=list(EXTRA_LINK_ARGS),) + extra_link_args=list(EXTRA_LINK_ARGS), + ) extensions = [plugin_ext] if BUILD_WITH_CYTHON: from Cython import Build @@ -220,4 +221,5 @@ setuptools.setup( 'protobuf>=3.5.0.post1', 'grpcio>={version}'.format(version=grpc_version.VERSION), ], - package_data=package_data(),) + package_data=package_data(), +) diff --git a/tools/distrib/python/make_grpcio_tools.py b/tools/distrib/python/make_grpcio_tools.py index 216492a2f34..4847233217c 100755 --- a/tools/distrib/python/make_grpcio_tools.py +++ b/tools/distrib/python/make_grpcio_tools.py @@ -107,12 +107,14 @@ def get_deps(): `out_file`.""" cc_files_output = bazel_query(BAZEL_DEPS_PROTOC_LIB_QUERY) cc_files = [ - name[len(PROTOBUF_CC_PREFIX):] for name in cc_files_output + name[len(PROTOBUF_CC_PREFIX):] + for name in cc_files_output if name.endswith('.cc') and name.startswith(PROTOBUF_CC_PREFIX) ] proto_files_output = bazel_query(BAZEL_DEPS_COMMON_PROTOS_QUERY) proto_files = [ - name[len(PROTOBUF_PROTO_PREFIX):] for name in proto_files_output + name[len(PROTOBUF_PROTO_PREFIX):] + for name in proto_files_output if name.endswith('.proto') and name.startswith(PROTOBUF_PROTO_PREFIX) ] commit_hash = protobuf_submodule_commit_hash() diff --git a/tools/distrib/run_clang_tidy.py b/tools/distrib/run_clang_tidy.py index 3ac712ea9e0..72d7956b68e 100755 --- a/tools/distrib/run_clang_tidy.py +++ b/tools/distrib/run_clang_tidy.py @@ -54,7 +54,8 @@ argp.set_defaults(fix=False) args = argp.parse_args() cmdline = [ - clang_tidy, '--checks=-*,%s' % ','.join(GRPC_CHECKS), + clang_tidy, + '--checks=-*,%s' % ','.join(GRPC_CHECKS), '--warnings-as-errors=%s' % ','.join(GRPC_CHECKS) ] + ['--extra-arg-before=%s' % arg for arg in extra_args] @@ -65,6 +66,7 @@ jobs = [] for filename in args.files: jobs.append(jobset.JobSpec( cmdline + [filename], - shortname=filename,)) #verbose_success=True)) + shortname=filename, + )) #verbose_success=True)) jobset.run(jobs, maxjobs=args.jobs) diff --git a/tools/distrib/yapf_code.sh b/tools/distrib/yapf_code.sh index fb14f36c66d..d188a0242c8 100755 --- a/tools/distrib/yapf_code.sh +++ b/tools/distrib/yapf_code.sh @@ -34,7 +34,7 @@ virtualenv $VIRTUALENV PYTHON=$(realpath "${VIRTUALENV}/bin/python") $PYTHON -m pip install --upgrade pip==9.0.1 $PYTHON -m pip install --upgrade futures -$PYTHON -m pip install yapf==0.16.0 +$PYTHON -m pip install yapf==0.20.0 yapf() { local exclusion exclusion_args=() diff --git a/tools/failures/detect_new_failures.py b/tools/failures/detect_new_failures.py index 87fd1d9f02d..4063978fcec 100644 --- a/tools/failures/detect_new_failures.py +++ b/tools/failures/detect_new_failures.py @@ -49,8 +49,8 @@ def gh(url, data=None): if 200 <= response.getcode() < 300: return json.loads(response.read()) else: - raise ValueError('Error ({}) accessing {}'.format(response.getcode(), - response.geturl())) + raise ValueError('Error ({}) accessing {}'.format( + response.getcode(), response.geturl())) def search_gh_issues(search_term, status='open'): @@ -92,11 +92,11 @@ def create_issues(new_flakes, always_create): else: preexisting_issues = search_gh_issues(test_name) if preexisting_issues['total_count'] > 0: - print('\nFound {} issues for "{}":'.format(preexisting_issues[ - 'total_count'], test_name)) + print('\nFound {} issues for "{}":'.format( + preexisting_issues['total_count'], test_name)) for issue in preexisting_issues['items']: - print('\t"{}" ; URL: {}'.format(issue['title'], issue[ - 'html_url'])) + print('\t"{}" ; URL: {}'.format(issue['title'], + issue['html_url'])) else: print( '\nNo preexisting issues found for "{}"'.format(test_name)) @@ -148,10 +148,11 @@ def get_new_failures(dates): rows = page.get('rows') if rows: return { - row['f'][0]['v']: Row(poll_strategy=row['f'][1]['v'], - job_name=row['f'][2]['v'], - build_id=row['f'][3]['v'], - timestamp=row['f'][4]['v']) + row['f'][0]['v']: Row( + poll_strategy=row['f'][1]['v'], + job_name=row['f'][2]['v'], + build_id=row['f'][3]['v'], + timestamp=row['f'][4]['v']) for row in rows } else: @@ -294,13 +295,14 @@ def main(): elif args.format == 'csv': if args.count_only: print('from_date,to_date,count') - print('{},{},{}'.format(dates['reporting']['begin'].isoformat( - ), dates['reporting']['end'].isoformat(), len(new_flakes))) + print('{},{},{}'.format(dates['reporting']['begin'].isoformat(), + dates['reporting']['end'].isoformat(), + len(new_flakes))) else: print_table(new_flakes, 'csv') else: - raise ValueError( - 'Invalid argument for --format: {}'.format(args.format)) + raise ValueError('Invalid argument for --format: {}'.format( + args.format)) if __name__ == '__main__': diff --git a/tools/github/pr_latency.py b/tools/github/pr_latency.py index 0131e60bbc2..34870a53260 100644 --- a/tools/github/pr_latency.py +++ b/tools/github/pr_latency.py @@ -72,9 +72,13 @@ def output(pr, errors)) elif mode == 'csv': print(','.join([ - str(pr), str(base_time), str(test_time), str( - int((test_time - base_time).total_seconds())), str(successes), - str(failures), str(errors) + str(pr), + str(base_time), + str(test_time), + str(int((test_time - base_time).total_seconds())), + str(successes), + str(failures), + str(errors) ])) @@ -117,8 +121,7 @@ def get_status_data(statuses_url, system): if system == 'kokoro': string_in_target_url = 'kokoro' elif system == 'jenkins': string_in_target_url = 'grpc-testing' for status in statuses['statuses']: - if not status['target_url'] or string_in_target_url not in status[ - 'target_url']: + if not status['target_url'] or string_in_target_url not in status['target_url']: continue # Ignore jenkins if status['state'] == 'pending': return None elif status['state'] == 'success': successes += 1 @@ -130,8 +133,8 @@ def get_status_data(statuses_url, system): latest_datetime = max(latest_datetime, parse_timestamp(status['updated_at'])) # First status is the most recent one. - if any([successes, failures, errors]) and sum( - [successes, failures, errors]) > 15: + if any([successes, failures, errors + ]) and sum([successes, failures, errors]) > 15: return { 'latest_datetime': latest_datetime, 'successes': successes, diff --git a/tools/interop_matrix/create_matrix_images.py b/tools/interop_matrix/create_matrix_images.py index ad7bb593311..ef9f6a59905 100755 --- a/tools/interop_matrix/create_matrix_images.py +++ b/tools/interop_matrix/create_matrix_images.py @@ -173,8 +173,8 @@ def build_all_images_for_lang(lang): releases = client_matrix.get_release_tags(lang) else: # Build a particular release. - if args.release not in ['master'] + client_matrix.get_release_tags( - lang): + if args.release not in ['master' + ] + client_matrix.get_release_tags(lang): jobset.message( 'SKIPPED', '%s for %s is not defined' % (args.release, lang), diff --git a/tools/interop_matrix/run_interop_matrix_tests.py b/tools/interop_matrix/run_interop_matrix_tests.py index ff42bd77b0c..3391ef51ccb 100755 --- a/tools/interop_matrix/run_interop_matrix_tests.py +++ b/tools/interop_matrix/run_interop_matrix_tests.py @@ -105,8 +105,8 @@ def find_all_images_for_lang(lang): releases = ['master'] + client_matrix.get_release_tags(lang) else: # Look for a particular release. - if args.release not in ['master'] + client_matrix.get_release_tags( - lang): + if args.release not in ['master' + ] + client_matrix.get_release_tags(lang): jobset.message( 'SKIPPED', '%s for %s is not defined' % (args.release, lang), @@ -136,7 +136,8 @@ def find_all_images_for_lang(lang): 'Skipped images (no-tag/unknown-tag): %d' % skipped, do_newline=True) # Filter tags based on the releases. - images[runtime] = [(tag, '%s:%s' % (image_path, tag)) for tag in tags + images[runtime] = [(tag, '%s:%s' % (image_path, tag)) + for tag in tags if tag in releases] return images diff --git a/tools/line_count/collect-history.py b/tools/line_count/collect-history.py index d2d5c95705d..c8e33c9ed2a 100755 --- a/tools/line_count/collect-history.py +++ b/tools/line_count/collect-history.py @@ -31,7 +31,8 @@ end_date = datetime.date(2017, 3, 29) for dt in daterange(start_date, end_date): dmy = dt.strftime('%Y-%m-%d') sha1 = subprocess.check_output( - ['git', 'rev-list', '-n', '1', '--before=%s' % dmy, 'master']).strip() + ['git', 'rev-list', '-n', '1', + '--before=%s' % dmy, 'master']).strip() subprocess.check_call(['git', 'checkout', sha1]) subprocess.check_call(['git', 'submodule', 'update']) subprocess.check_call(['git', 'clean', '-f', '-x', '-d']) diff --git a/tools/line_count/summarize-history.py b/tools/line_count/summarize-history.py index 80b0ed7a7e8..4a085999a59 100755 --- a/tools/line_count/summarize-history.py +++ b/tools/line_count/summarize-history.py @@ -32,6 +32,7 @@ for dt in daterange(start_date, end_date): dmy = dt.strftime('%Y-%m-%d') print dmy subprocess.check_call([ - 'tools/line_count/yaml2csv.py', '-i', '../count/%s.yaml' % dmy, '-d', - dmy, '-o', '../count/%s.csv' % dmy + 'tools/line_count/yaml2csv.py', '-i', + '../count/%s.yaml' % dmy, '-d', dmy, '-o', + '../count/%s.csv' % dmy ]) diff --git a/tools/mkowners/mkowners.py b/tools/mkowners/mkowners.py index d8b3d3c3326..2ea7265f883 100755 --- a/tools/mkowners/mkowners.py +++ b/tools/mkowners/mkowners.py @@ -47,7 +47,8 @@ args = argp.parse_args() # owners_files = [ - os.path.join(root, 'OWNERS') for root, dirs, files in os.walk(git_root) + os.path.join(root, 'OWNERS') + for root, dirs, files in os.walk(git_root) if 'OWNERS' in files ] diff --git a/tools/profiling/microbenchmarks/bm2bq.py b/tools/profiling/microbenchmarks/bm2bq.py index 746b643b439..e084e28dcf6 100755 --- a/tools/profiling/microbenchmarks/bm2bq.py +++ b/tools/profiling/microbenchmarks/bm2bq.py @@ -28,9 +28,9 @@ import subprocess columns = [] for row in json.loads( - subprocess.check_output([ - 'bq', '--format=json', 'show', 'microbenchmarks.microbenchmarks' - ]))['schema']['fields']: + subprocess.check_output( + ['bq', '--format=json', 'show', + 'microbenchmarks.microbenchmarks']))['schema']['fields']: columns.append((row['name'], row['type'].lower())) SANITIZE = { diff --git a/tools/profiling/microbenchmarks/bm_diff/bm_build.py b/tools/profiling/microbenchmarks/bm_diff/bm_build.py index a4cd61707d3..4197ba3632a 100755 --- a/tools/profiling/microbenchmarks/bm_diff/bm_build.py +++ b/tools/profiling/microbenchmarks/bm_diff/bm_build.py @@ -43,7 +43,8 @@ def _args(): '-n', '--name', type=str, - help='Unique name of this build. To be used as a handle to pass to the other bm* scripts' + help= + 'Unique name of this build. To be used as a handle to pass to the other bm* scripts' ) argp.add_argument('--counters', dest='counters', action='store_true') argp.add_argument('--no-counters', dest='counters', action='store_false') @@ -71,7 +72,8 @@ def build(name, benchmarks, jobs, counters): subprocess.check_call(_make_cmd('counters', benchmarks, jobs)) os.rename( 'bins', - 'bm_diff_%s' % name,) + 'bm_diff_%s' % name, + ) if __name__ == '__main__': diff --git a/tools/profiling/microbenchmarks/bm_diff/bm_constants.py b/tools/profiling/microbenchmarks/bm_diff/bm_constants.py index cff29dbe08e..5719e426204 100644 --- a/tools/profiling/microbenchmarks/bm_diff/bm_constants.py +++ b/tools/profiling/microbenchmarks/bm_diff/bm_constants.py @@ -22,10 +22,12 @@ _AVAILABLE_BENCHMARK_TESTS = [ 'bm_metadata', 'bm_fullstack_trickle' ] -_INTERESTING = ( - 'cpu_time', 'real_time', 'call_initial_size-median', 'locks_per_iteration', - 'allocs_per_iteration', 'writes_per_iteration', 'atm_cas_per_iteration', - 'atm_add_per_iteration', 'nows_per_iteration', - 'cli_transport_stalls_per_iteration', 'cli_stream_stalls_per_iteration', - 'svr_transport_stalls_per_iteration', 'svr_stream_stalls_per_iteration', - 'http2_pings_sent_per_iteration') +_INTERESTING = ('cpu_time', 'real_time', 'call_initial_size-median', + 'locks_per_iteration', 'allocs_per_iteration', + 'writes_per_iteration', 'atm_cas_per_iteration', + 'atm_add_per_iteration', 'nows_per_iteration', + 'cli_transport_stalls_per_iteration', + 'cli_stream_stalls_per_iteration', + 'svr_transport_stalls_per_iteration', + 'svr_stream_stalls_per_iteration', + 'http2_pings_sent_per_iteration') diff --git a/tools/profiling/microbenchmarks/bm_diff/bm_diff.py b/tools/profiling/microbenchmarks/bm_diff/bm_diff.py index b8a3b22861b..f975a8b4022 100755 --- a/tools/profiling/microbenchmarks/bm_diff/bm_diff.py +++ b/tools/profiling/microbenchmarks/bm_diff/bm_diff.py @@ -65,7 +65,8 @@ def _args(): '--loops', type=int, default=20, - help='Number of times to loops the benchmarks. Must match what was passed to bm_run.py' + help= + 'Number of times to loops the benchmarks. Must match what was passed to bm_run.py' ) argp.add_argument( '-r', diff --git a/tools/profiling/microbenchmarks/bm_diff/bm_main.py b/tools/profiling/microbenchmarks/bm_diff/bm_main.py index 137c22bf8e4..96c63ba060e 100755 --- a/tools/profiling/microbenchmarks/bm_diff/bm_main.py +++ b/tools/profiling/microbenchmarks/bm_diff/bm_main.py @@ -78,7 +78,8 @@ def _args(): '--loops', type=int, default=10, - help='Number of times to loops the benchmarks. More loops cuts down on noise' + help= + 'Number of times to loops the benchmarks. More loops cuts down on noise' ) argp.add_argument( '-j', diff --git a/tools/profiling/microbenchmarks/bm_diff/bm_run.py b/tools/profiling/microbenchmarks/bm_diff/bm_run.py index 08894bbe4d3..dfb9b178faf 100755 --- a/tools/profiling/microbenchmarks/bm_diff/bm_run.py +++ b/tools/profiling/microbenchmarks/bm_diff/bm_run.py @@ -51,7 +51,8 @@ def _args(): '-n', '--name', type=str, - help='Unique name of the build to run. Needs to match the handle passed to bm_build.py' + help= + 'Unique name of the build to run. Needs to match the handle passed to bm_build.py' ) argp.add_argument( '-r', @@ -64,7 +65,8 @@ def _args(): '--loops', type=int, default=20, - help='Number of times to loops the benchmarks. More loops cuts down on noise' + help= + 'Number of times to loops the benchmarks. More loops cuts down on noise' ) argp.add_argument('--counters', dest='counters', action='store_true') argp.add_argument('--no-counters', dest='counters', action='store_false') @@ -82,13 +84,14 @@ def _collect_bm_data(bm, cfg, name, regex, idx, loops): 'bm_diff_%s/%s/%s' % (name, cfg, bm), '--benchmark_list_tests', '--benchmark_filter=%s' % regex ]).splitlines(): - stripped_line = line.strip().replace("/", "_").replace( - "<", "_").replace(">", "_").replace(", ", "_") + stripped_line = line.strip().replace("/", + "_").replace("<", "_").replace( + ">", "_").replace(", ", "_") cmd = [ 'bm_diff_%s/%s/%s' % (name, cfg, bm), '--benchmark_filter=^%s$' % line, - '--benchmark_out=%s.%s.%s.%s.%d.json' % - (bm, stripped_line, cfg, name, idx), + '--benchmark_out=%s.%s.%s.%s.%d.json' % (bm, stripped_line, cfg, + name, idx), '--benchmark_out_format=json', ] jobs_list.append( diff --git a/tools/profiling/microbenchmarks/bm_json.py b/tools/profiling/microbenchmarks/bm_json.py index 1dd9f65dbfa..497d7ca8137 100644 --- a/tools/profiling/microbenchmarks/bm_json.py +++ b/tools/profiling/microbenchmarks/bm_json.py @@ -183,7 +183,8 @@ def expand_json(js, js2=None): context = js['context'] if 'label' in bm: labels_list = [ - s.split(':') for s in bm['label'].strip().split(' ') + s.split(':') + for s in bm['label'].strip().split(' ') if len(s) and s[0] != '#' ] for el in labels_list: diff --git a/tools/profiling/qps/qps_diff.py b/tools/profiling/qps/qps_diff.py index 55a81f034d3..393f862b4db 100755 --- a/tools/profiling/qps/qps_diff.py +++ b/tools/profiling/qps/qps_diff.py @@ -48,7 +48,8 @@ def _args(): '--loops', type=int, default=4, - help='Number of loops for each benchmark. More loops cuts down on noise') + help='Number of loops for each benchmark. More loops cuts down on noise' + ) argp.add_argument( '-j', '--jobs', @@ -128,8 +129,8 @@ def diff(scenarios, loops, old, new): rows = [] for sn in scenarios: mdn_diff = abs(_median(new_data[sn]) - _median(old_data[sn])) - print('%s: %s=%r %s=%r mdn_diff=%r' % - (sn, new, new_data[sn], old, old_data[sn], mdn_diff)) + print('%s: %s=%r %s=%r mdn_diff=%r' % (sn, new, new_data[sn], old, + old_data[sn], mdn_diff)) s = bm_speedup.speedup(new_data[sn], old_data[sn], 10e-5) if abs(s) > 3 and mdn_diff > 0.5: rows.append([sn, '%+d%%' % s]) diff --git a/tools/run_tests/artifacts/artifact_targets.py b/tools/run_tests/artifacts/artifact_targets.py index dc0803b3c7e..efc4ca0d8a5 100644 --- a/tools/run_tests/artifacts/artifact_targets.py +++ b/tools/run_tests/artifacts/artifact_targets.py @@ -271,8 +271,8 @@ class PHPArtifact: def build_jobspec(self): if self.platform == 'linux': return create_docker_jobspec( - self.name, - 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch), + self.name, 'tools/dockerfile/grpc_artifact_linux_{}'.format( + self.arch), 'tools/run_tests/artifacts/build_artifact_php.sh') else: return create_jobspec( @@ -337,36 +337,38 @@ def targets(): for Cls in (CSharpExtArtifact, ProtocArtifact) for platform in ('linux', 'macos', 'windows') for arch in ('x86', 'x64') ] + [ - PythonArtifact('linux', 'x86', 'cp27-cp27m'), PythonArtifact( - 'linux', 'x86', 'cp27-cp27mu'), PythonArtifact( - 'linux', 'x86', 'cp34-cp34m'), PythonArtifact( - 'linux', 'x86', 'cp35-cp35m'), PythonArtifact( - 'linux', 'x86', 'cp36-cp36m'), PythonArtifact( - 'linux_extra', 'armv7', '2.7'), PythonArtifact( - 'linux_extra', 'armv7', '3.4'), PythonArtifact( - 'linux_extra', 'armv7', '3.5'), - PythonArtifact('linux_extra', 'armv7', '3.6'), PythonArtifact( - 'linux_extra', 'armv6', '2.7'), PythonArtifact( - 'linux_extra', 'armv6', '3.4'), PythonArtifact( - 'linux_extra', 'armv6', '3.5'), PythonArtifact( - 'linux_extra', 'armv6', '3.6'), PythonArtifact( - 'linux', 'x64', 'cp27-cp27m'), PythonArtifact( - 'linux', 'x64', 'cp27-cp27mu'), PythonArtifact( - 'linux', 'x64', 'cp34-cp34m'), - PythonArtifact('linux', 'x64', 'cp35-cp35m'), PythonArtifact( - 'linux', 'x64', 'cp36-cp36m'), PythonArtifact( - 'macos', 'x64', 'python2.7'), PythonArtifact( - 'macos', 'x64', 'python3.4'), PythonArtifact('macos', 'x64', - 'python3.5'), - PythonArtifact('macos', 'x64', 'python3.6'), PythonArtifact( - 'windows', 'x86', 'Python27_32bits'), PythonArtifact( - 'windows', 'x86', 'Python34_32bits'), PythonArtifact( - 'windows', 'x86', 'Python35_32bits'), PythonArtifact( - 'windows', 'x86', 'Python36_32bits'), PythonArtifact( - 'windows', 'x64', 'Python27'), - PythonArtifact('windows', 'x64', 'Python34'), PythonArtifact( - 'windows', 'x64', 'Python35'), PythonArtifact( - 'windows', 'x64', 'Python36'), RubyArtifact( - 'linux', 'x64'), RubyArtifact('macos', 'x64'), PHPArtifact( - 'linux', 'x64'), PHPArtifact('macos', 'x64') + PythonArtifact('linux', 'x86', 'cp27-cp27m'), + PythonArtifact('linux', 'x86', 'cp27-cp27mu'), + PythonArtifact('linux', 'x86', 'cp34-cp34m'), + PythonArtifact('linux', 'x86', 'cp35-cp35m'), + PythonArtifact('linux', 'x86', 'cp36-cp36m'), + PythonArtifact('linux_extra', 'armv7', '2.7'), + PythonArtifact('linux_extra', 'armv7', '3.4'), + PythonArtifact('linux_extra', 'armv7', '3.5'), + PythonArtifact('linux_extra', 'armv7', '3.6'), + PythonArtifact('linux_extra', 'armv6', '2.7'), + PythonArtifact('linux_extra', 'armv6', '3.4'), + PythonArtifact('linux_extra', 'armv6', '3.5'), + PythonArtifact('linux_extra', 'armv6', '3.6'), + PythonArtifact('linux', 'x64', 'cp27-cp27m'), + PythonArtifact('linux', 'x64', 'cp27-cp27mu'), + PythonArtifact('linux', 'x64', 'cp34-cp34m'), + PythonArtifact('linux', 'x64', 'cp35-cp35m'), + PythonArtifact('linux', 'x64', 'cp36-cp36m'), + PythonArtifact('macos', 'x64', 'python2.7'), + PythonArtifact('macos', 'x64', 'python3.4'), + PythonArtifact('macos', 'x64', 'python3.5'), + PythonArtifact('macos', 'x64', 'python3.6'), + PythonArtifact('windows', 'x86', 'Python27_32bits'), + PythonArtifact('windows', 'x86', 'Python34_32bits'), + PythonArtifact('windows', 'x86', 'Python35_32bits'), + PythonArtifact('windows', 'x86', 'Python36_32bits'), + PythonArtifact('windows', 'x64', 'Python27'), + PythonArtifact('windows', 'x64', 'Python34'), + PythonArtifact('windows', 'x64', 'Python35'), + PythonArtifact('windows', 'x64', 'Python36'), + RubyArtifact('linux', 'x64'), + RubyArtifact('macos', 'x64'), + PHPArtifact('linux', 'x64'), + PHPArtifact('macos', 'x64') ]) diff --git a/tools/run_tests/artifacts/distribtest_targets.py b/tools/run_tests/artifacts/distribtest_targets.py index 94a2d537701..b2cc16acd42 100644 --- a/tools/run_tests/artifacts/distribtest_targets.py +++ b/tools/run_tests/artifacts/distribtest_targets.py @@ -106,8 +106,8 @@ class CSharpDistribTest(object): if self.platform == 'linux': return create_docker_jobspec( self.name, - 'tools/dockerfile/distribtest/csharp_%s_%s' % ( - self.docker_suffix, self.arch), + 'tools/dockerfile/distribtest/csharp_%s_%s' % + (self.docker_suffix, self.arch), 'test/distrib/csharp/run_distrib_test%s.sh' % self.script_suffix, copy_rel_path='test/distrib') @@ -260,8 +260,8 @@ class CppDistribTest(object): def build_jobspec(self): if self.platform == 'linux': return create_docker_jobspec( - self.name, 'tools/dockerfile/distribtest/cpp_%s_%s' % ( - self.docker_suffix, self.arch), + self.name, 'tools/dockerfile/distribtest/cpp_%s_%s' % + (self.docker_suffix, self.arch), 'test/distrib/cpp/run_distrib_test_%s.sh' % self.testcase) elif self.platform == 'windows': return create_jobspec( diff --git a/tools/run_tests/artifacts/package_targets.py b/tools/run_tests/artifacts/package_targets.py index 52908454f2d..abf1b5ebed2 100644 --- a/tools/run_tests/artifacts/package_targets.py +++ b/tools/run_tests/artifacts/package_targets.py @@ -152,6 +152,9 @@ class PHPPackage: def targets(): """Gets list of supported targets""" return [ - CSharpPackage(), CSharpPackage(linux=True), RubyPackage(), - PythonPackage(), PHPPackage() + CSharpPackage(), + CSharpPackage(linux=True), + RubyPackage(), + PythonPackage(), + PHPPackage() ] diff --git a/tools/run_tests/performance/massage_qps_stats.py b/tools/run_tests/performance/massage_qps_stats.py index 37f6e7aae08..790202c43ee 100644 --- a/tools/run_tests/performance/massage_qps_stats.py +++ b/tools/run_tests/performance/massage_qps_stats.py @@ -18,8 +18,7 @@ import massage_qps_stats_helpers def massage_qps_stats(scenario_result): - for stats in scenario_result["serverStats"] + scenario_result[ - "clientStats"]: + for stats in scenario_result["serverStats"] + scenario_result["clientStats"]: if "coreStats" not in stats: return core_stats = stats["coreStats"] del stats["coreStats"] @@ -294,8 +293,8 @@ def massage_qps_stats(scenario_result): core_stats, "cq_ev_queue_transient_pop_failures") h = massage_qps_stats_helpers.histogram(core_stats, "call_initial_size") stats["core_call_initial_size"] = ",".join("%f" % x for x in h.buckets) - stats["core_call_initial_size_bkts"] = ",".join("%f" % x - for x in h.boundaries) + stats["core_call_initial_size_bkts"] = ",".join( + "%f" % x for x in h.boundaries) stats[ "core_call_initial_size_50p"] = massage_qps_stats_helpers.percentile( h.buckets, 50, h.boundaries) @@ -307,8 +306,8 @@ def massage_qps_stats(scenario_result): h.buckets, 99, h.boundaries) h = massage_qps_stats_helpers.histogram(core_stats, "poll_events_returned") - stats["core_poll_events_returned"] = ",".join("%f" % x - for x in h.buckets) + stats["core_poll_events_returned"] = ",".join( + "%f" % x for x in h.buckets) stats["core_poll_events_returned_bkts"] = ",".join( "%f" % x for x in h.boundaries) stats[ @@ -322,8 +321,8 @@ def massage_qps_stats(scenario_result): h.buckets, 99, h.boundaries) h = massage_qps_stats_helpers.histogram(core_stats, "tcp_write_size") stats["core_tcp_write_size"] = ",".join("%f" % x for x in h.buckets) - stats["core_tcp_write_size_bkts"] = ",".join("%f" % x - for x in h.boundaries) + stats["core_tcp_write_size_bkts"] = ",".join( + "%f" % x for x in h.boundaries) stats["core_tcp_write_size_50p"] = massage_qps_stats_helpers.percentile( h.buckets, 50, h.boundaries) stats["core_tcp_write_size_95p"] = massage_qps_stats_helpers.percentile( @@ -333,8 +332,8 @@ def massage_qps_stats(scenario_result): h = massage_qps_stats_helpers.histogram(core_stats, "tcp_write_iov_size") stats["core_tcp_write_iov_size"] = ",".join("%f" % x for x in h.buckets) - stats["core_tcp_write_iov_size_bkts"] = ",".join("%f" % x - for x in h.boundaries) + stats["core_tcp_write_iov_size_bkts"] = ",".join( + "%f" % x for x in h.boundaries) stats[ "core_tcp_write_iov_size_50p"] = massage_qps_stats_helpers.percentile( h.buckets, 50, h.boundaries) @@ -346,8 +345,8 @@ def massage_qps_stats(scenario_result): h.buckets, 99, h.boundaries) h = massage_qps_stats_helpers.histogram(core_stats, "tcp_read_size") stats["core_tcp_read_size"] = ",".join("%f" % x for x in h.buckets) - stats["core_tcp_read_size_bkts"] = ",".join("%f" % x - for x in h.boundaries) + stats["core_tcp_read_size_bkts"] = ",".join( + "%f" % x for x in h.boundaries) stats["core_tcp_read_size_50p"] = massage_qps_stats_helpers.percentile( h.buckets, 50, h.boundaries) stats["core_tcp_read_size_95p"] = massage_qps_stats_helpers.percentile( @@ -356,8 +355,8 @@ def massage_qps_stats(scenario_result): h.buckets, 99, h.boundaries) h = massage_qps_stats_helpers.histogram(core_stats, "tcp_read_offer") stats["core_tcp_read_offer"] = ",".join("%f" % x for x in h.buckets) - stats["core_tcp_read_offer_bkts"] = ",".join("%f" % x - for x in h.boundaries) + stats["core_tcp_read_offer_bkts"] = ",".join( + "%f" % x for x in h.boundaries) stats["core_tcp_read_offer_50p"] = massage_qps_stats_helpers.percentile( h.buckets, 50, h.boundaries) stats["core_tcp_read_offer_95p"] = massage_qps_stats_helpers.percentile( @@ -366,8 +365,8 @@ def massage_qps_stats(scenario_result): h.buckets, 99, h.boundaries) h = massage_qps_stats_helpers.histogram(core_stats, "tcp_read_offer_iov_size") - stats["core_tcp_read_offer_iov_size"] = ",".join("%f" % x - for x in h.buckets) + stats["core_tcp_read_offer_iov_size"] = ",".join( + "%f" % x for x in h.buckets) stats["core_tcp_read_offer_iov_size_bkts"] = ",".join( "%f" % x for x in h.boundaries) stats[ @@ -381,8 +380,8 @@ def massage_qps_stats(scenario_result): h.buckets, 99, h.boundaries) h = massage_qps_stats_helpers.histogram(core_stats, "http2_send_message_size") - stats["core_http2_send_message_size"] = ",".join("%f" % x - for x in h.buckets) + stats["core_http2_send_message_size"] = ",".join( + "%f" % x for x in h.buckets) stats["core_http2_send_message_size_bkts"] = ",".join( "%f" % x for x in h.boundaries) stats[ @@ -457,8 +456,8 @@ def massage_qps_stats(scenario_result): h = massage_qps_stats_helpers.histogram(core_stats, "server_cqs_checked") stats["core_server_cqs_checked"] = ",".join("%f" % x for x in h.buckets) - stats["core_server_cqs_checked_bkts"] = ",".join("%f" % x - for x in h.boundaries) + stats["core_server_cqs_checked_bkts"] = ",".join( + "%f" % x for x in h.boundaries) stats[ "core_server_cqs_checked_50p"] = massage_qps_stats_helpers.percentile( h.buckets, 50, h.boundaries) diff --git a/tools/run_tests/performance/scenario_config.py b/tools/run_tests/performance/scenario_config.py index 7af33f92f0c..f05753154e9 100644 --- a/tools/run_tests/performance/scenario_config.py +++ b/tools/run_tests/performance/scenario_config.py @@ -178,8 +178,8 @@ def _ping_pong_scenario(name, # clamp buffer usage to something reasonable (16 gig for now) MAX_MEMORY_USE = 16 * 1024 * 1024 * 1024 if outstanding_calls * max(req_size, resp_size) > MAX_MEMORY_USE: - outstanding_calls = max(1, MAX_MEMORY_USE / max(req_size, - resp_size)) + outstanding_calls = max(1, + MAX_MEMORY_USE / max(req_size, resp_size)) wide = channels if channels is not None else WIDE deep = int(math.ceil(1.0 * outstanding_calls / wide)) @@ -503,8 +503,8 @@ class CXXLanguage: ]: for synchronicity in ['sync', 'async']: yield _ping_pong_scenario( - 'cpp_protobuf_%s_%s_ping_pong_%s' % - (synchronicity, rpc_type, secstr), + 'cpp_protobuf_%s_%s_ping_pong_%s' % (synchronicity, + rpc_type, secstr), rpc_type=rpc_type.upper(), client_type='%s_CLIENT' % synchronicity.upper(), server_type='%s_SERVER' % synchronicity.upper(), @@ -580,10 +580,10 @@ class CXXLanguage: minimal_stack=not secure, categories=[SWEEP]) - for channels in geometric_progression(1, 20000, - math.sqrt(10)): - for outstanding in geometric_progression(1, 200000, - math.sqrt(10)): + for channels in geometric_progression( + 1, 20000, math.sqrt(10)): + for outstanding in geometric_progression( + 1, 200000, math.sqrt(10)): if synchronicity == 'sync' and outstanding > 1200: continue if outstanding < channels: continue diff --git a/tools/run_tests/python_utils/dockerjob.py b/tools/run_tests/python_utils/dockerjob.py index d2941c08118..2d22dc13a05 100755 --- a/tools/run_tests/python_utils/dockerjob.py +++ b/tools/run_tests/python_utils/dockerjob.py @@ -50,8 +50,8 @@ def docker_mapped_port(cid, port, timeout_seconds=15): return int(output.split(':', 2)[1]) except subprocess.CalledProcessError as e: pass - raise Exception('Failed to get exposed port %s for container %s.' % - (port, cid)) + raise Exception('Failed to get exposed port %s for container %s.' % (port, + cid)) def wait_for_healthy(cid, shortname, timeout_seconds): diff --git a/tools/run_tests/python_utils/filter_pull_request_tests.py b/tools/run_tests/python_utils/filter_pull_request_tests.py index 8e0dc708dd7..4c09b3414e3 100644 --- a/tools/run_tests/python_utils/filter_pull_request_tests.py +++ b/tools/run_tests/python_utils/filter_pull_request_tests.py @@ -124,10 +124,10 @@ def _get_changed_files(base_branch): """ # Get file changes between branch and merge-base of specified branch # Not combined to be Windows friendly - base_commit = check_output( - ["git", "merge-base", base_branch, "HEAD"]).rstrip() - return check_output( - ["git", "diff", base_commit, "--name-only", "HEAD"]).splitlines() + base_commit = check_output(["git", "merge-base", base_branch, + "HEAD"]).rstrip() + return check_output(["git", "diff", base_commit, "--name-only", + "HEAD"]).splitlines() def _can_skip_tests(file_names, triggers): diff --git a/tools/run_tests/python_utils/jobset.py b/tools/run_tests/python_utils/jobset.py index 454d09bf0d9..6a3391337e9 100755 --- a/tools/run_tests/python_utils/jobset.py +++ b/tools/run_tests/python_utils/jobset.py @@ -133,12 +133,13 @@ def message(tag, msg, explanatory_text=None, do_newline=False): logging.info(explanatory_text) logging.info('%s: %s', tag, msg) else: - sys.stdout.write('%s%s%s\x1b[%d;%dm%s\x1b[0m: %s%s' % ( - _BEGINNING_OF_LINE, _CLEAR_LINE, '\n%s' % explanatory_text - if explanatory_text is not None else '', - _COLORS[_TAG_COLOR[tag]][1], _COLORS[_TAG_COLOR[tag]][0], - tag, msg, '\n' - if do_newline or explanatory_text is not None else '')) + sys.stdout.write( + '%s%s%s\x1b[%d;%dm%s\x1b[0m: %s%s' % + (_BEGINNING_OF_LINE, _CLEAR_LINE, '\n%s' % explanatory_text + if explanatory_text is not None else '', + _COLORS[_TAG_COLOR[tag]][1], _COLORS[_TAG_COLOR[tag]][0], + tag, msg, '\n' + if do_newline or explanatory_text is not None else '')) sys.stdout.flush() return except IOError, e: @@ -210,8 +211,8 @@ class JobSpec(object): def __str__(self): return '%s: %s %s' % (self.shortname, ' '.join( - '%s=%s' % kv - for kv in self.environ.items()), ' '.join(self.cmdline)) + '%s=%s' % kv for kv in self.environ.items()), + ' '.join(self.cmdline)) class JobResult(object): @@ -284,8 +285,9 @@ class Job(object): self._process = try_start() break except OSError: - message('WARNING', 'Failed to start %s, retrying in %f seconds' - % (self._spec.shortname, delay)) + message('WARNING', + 'Failed to start %s, retrying in %f seconds' % + (self._spec.shortname, delay)) time.sleep(delay) delay *= 2 else: @@ -343,8 +345,8 @@ class Job(object): if real > 0.5: cores = (user + sys) / real self.result.cpu_measured = float('%.01f' % cores) - self.result.cpu_estimated = float('%.01f' % - self._spec.cpu_cost) + self.result.cpu_estimated = float( + '%.01f' % self._spec.cpu_cost) measurement = '; cpu_cost=%.01f; estimated=%.01f' % ( self.result.cpu_measured, self.result.cpu_estimated) if not self._quiet_success: @@ -378,8 +380,8 @@ class Job(object): else: message( 'TIMEOUT', - '%s [pid=%d, time=%.1fsec]' % - (self._spec.shortname, self._process.pid, elapsed), + '%s [pid=%d, time=%.1fsec]' % (self._spec.shortname, + self._process.pid, elapsed), stdout(), do_newline=True) self.kill() diff --git a/tools/run_tests/python_utils/start_port_server.py b/tools/run_tests/python_utils/start_port_server.py index 5572cdcfe7c..37995acbdfa 100644 --- a/tools/run_tests/python_utils/start_port_server.py +++ b/tools/run_tests/python_utils/start_port_server.py @@ -43,16 +43,16 @@ def start_port_server(): if running: current_version = int( subprocess.check_output([ - sys.executable, os.path.abspath( - 'tools/run_tests/python_utils/port_server.py'), + sys.executable, + os.path.abspath('tools/run_tests/python_utils/port_server.py'), 'dump_version' ])) logging.info('my port server is version %d', current_version) running = (version >= current_version) if not running: logging.info('port_server version mismatch: killing the old one') - urllib.urlopen('http://localhost:%d/quitquitquit' % - _PORT_SERVER_PORT).read() + urllib.urlopen( + 'http://localhost:%d/quitquitquit' % _PORT_SERVER_PORT).read() time.sleep(1) if not running: fd, logfile = tempfile.mkstemp() @@ -61,7 +61,8 @@ def start_port_server(): args = [ sys.executable, os.path.abspath('tools/run_tests/python_utils/port_server.py'), - '-p', '%d' % _PORT_SERVER_PORT, '-l', logfile + '-p', + '%d' % _PORT_SERVER_PORT, '-l', logfile ] env = dict(os.environ) env['BUILD_ID'] = 'pleaseDontKillMeJenkins' @@ -91,8 +92,8 @@ def start_port_server(): # try one final time: maybe another build managed to start one time.sleep(1) try: - urllib.urlopen('http://localhost:%d/get' % - _PORT_SERVER_PORT).read() + urllib.urlopen( + 'http://localhost:%d/get' % _PORT_SERVER_PORT).read() logging.info( 'last ditch attempt to contact port server succeeded') break diff --git a/tools/run_tests/run_build_statistics.py b/tools/run_tests/run_build_statistics.py index 4af00a47a67..405533279e7 100755 --- a/tools/run_tests/run_build_statistics.py +++ b/tools/run_tests/run_build_statistics.py @@ -61,7 +61,7 @@ _BUILDS = { } _URL_BASE = 'https://grpc-testing.appspot.com/job' -# This is a dynamic list where known and active issues should be added. +# This is a dynamic list where known and active issues should be added. # Fixed ones should be removed. # Also try not to add multiple messages from the same failure. _KNOWN_ERRORS = [ @@ -106,8 +106,8 @@ def _scrape_for_known_errors(html): 'description': known_error, 'count': this_error_count }) - print('====> %d failures due to %s' % - (this_error_count, known_error)) + print('====> %d failures due to %s' % (this_error_count, + known_error)) return error_list @@ -116,8 +116,9 @@ def _no_report_files_found(html): def _get_last_processed_buildnumber(build_name): - query = 'SELECT max(build_number) FROM [%s:%s.%s];' % ( - _PROJECT_ID, _DATASET_ID, build_name) + query = 'SELECT max(build_number) FROM [%s:%s.%s];' % (_PROJECT_ID, + _DATASET_ID, + build_name) query_job = big_query_utils.sync_query_job(bq, _PROJECT_ID, query) page = bq.jobs().getQueryResults( pageToken=None, **query_job['jobReference']).execute(num_retries=3) @@ -167,8 +168,8 @@ def _process_build(json_url, console_url): html = urllib.urlopen(console_url).read() build_result['pass_count'] = 0 build_result['failure_count'] = 1 - # In this case, the string doesn't exist in the result html but the fact - # that we fail to parse the result html indicates Jenkins failure and hence + # In this case, the string doesn't exist in the result html but the fact + # that we fail to parse the result html indicates Jenkins failure and hence # no report files were generated. build_result['no_report_files_found'] = True error_list = _scrape_for_known_errors(html) @@ -223,7 +224,7 @@ for build_name in _BUILDS.keys() if 'all' in args.builds else args.builds: if build.get_status() == 'ABORTED': continue # If any build is still running, stop processing this job. Next time, we - # start from where it was left so that all builds are processed + # start from where it was left so that all builds are processed # sequentially. if build.is_running(): print('====> Build %d is still running.' % build_number) diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index 99f42988137..44a6ec26e89 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -685,7 +685,8 @@ def cloud_to_prod_jobspec(language, cmdargs = [ '--server_host=%s' % server_host_detail[0], '--server_host_override=%s' % server_host_detail[1], - '--server_port=443', '--use_tls=true', '--test_case=%s' % test_case + '--server_port=443', '--use_tls=true', + '--test_case=%s' % test_case ] environ = dict(language.cloud_to_prod_env(), **language.global_env()) if auth: @@ -696,18 +697,19 @@ def cloud_to_prod_jobspec(language, cwd = language.client_cwd if docker_image: - container_name = dockerjob.random_name('interop_client_%s' % - language.safename) + container_name = dockerjob.random_name( + 'interop_client_%s' % language.safename) cmdline = docker_run_cmdline( cmdline, image=docker_image, cwd=cwd, environ=environ, - docker_args=['--net=host', '--name=%s' % container_name]) + docker_args=['--net=host', + '--name=%s' % container_name]) if manual_cmd_log is not None: if manual_cmd_log == []: - manual_cmd_log.append('echo "Testing ${docker_image:=%s}"' % - docker_image) + manual_cmd_log.append( + 'echo "Testing ${docker_image:=%s}"' % docker_image) manual_cmd_log.append(manual_cmdline(cmdline, docker_image)) cwd = None environ = None @@ -775,18 +777,19 @@ def cloud_to_cloud_jobspec(language, environ = language.global_env() if docker_image and language.safename != 'objc': # we can't run client in docker for objc. - container_name = dockerjob.random_name('interop_client_%s' % - language.safename) + container_name = dockerjob.random_name( + 'interop_client_%s' % language.safename) cmdline = docker_run_cmdline( cmdline, image=docker_image, environ=environ, cwd=cwd, - docker_args=['--net=host', '--name=%s' % container_name]) + docker_args=['--net=host', + '--name=%s' % container_name]) if manual_cmd_log is not None: if manual_cmd_log == []: - manual_cmd_log.append('echo "Testing ${docker_image:=%s}"' % - docker_image) + manual_cmd_log.append( + 'echo "Testing ${docker_image:=%s}"' % docker_image) manual_cmd_log.append(manual_cmdline(cmdline, docker_image)) cwd = None @@ -807,12 +810,12 @@ def cloud_to_cloud_jobspec(language, def server_jobspec(language, docker_image, insecure=False, manual_cmd_log=None): """Create jobspec for running a server""" - container_name = dockerjob.random_name('interop_server_%s' % - language.safename) + container_name = dockerjob.random_name( + 'interop_server_%s' % language.safename) cmdline = bash_cmdline( language.server_cmd([ - '--port=%s' % _DEFAULT_SERVER_PORT, '--use_tls=%s' % ( - 'false' if insecure else 'true') + '--port=%s' % _DEFAULT_SERVER_PORT, + '--use_tls=%s' % ('false' if insecure else 'true') ])) environ = language.global_env() docker_args = ['--name=%s' % container_name] @@ -821,9 +824,9 @@ def server_jobspec(language, docker_image, insecure=False, manual_cmd_log=None): # with the server port. These ports are used for http2 interop test # (one test case per port). docker_args += list( - itertools.chain.from_iterable(('-p', str(_DEFAULT_SERVER_PORT + i)) - for i in range( - len(_HTTP2_SERVER_TEST_CASES)))) + itertools.chain.from_iterable( + ('-p', str(_DEFAULT_SERVER_PORT + i)) + for i in range(len(_HTTP2_SERVER_TEST_CASES)))) # Enable docker's healthcheck mechanism. # This runs a Python script inside the container every second. The script # pings the http2 server to verify it is ready. The 'health-retries' flag @@ -834,8 +837,8 @@ def server_jobspec(language, docker_image, insecure=False, manual_cmd_log=None): # command line. docker_args += [ '--health-cmd=python test/http2_test/http2_server_health_check.py ' - '--server_host=%s --server_port=%d' % - ('localhost', _DEFAULT_SERVER_PORT), + '--server_host=%s --server_port=%d' % ('localhost', + _DEFAULT_SERVER_PORT), '--health-interval=1s', '--health-retries=5', '--health-timeout=10s', @@ -852,8 +855,8 @@ def server_jobspec(language, docker_image, insecure=False, manual_cmd_log=None): docker_args=docker_args) if manual_cmd_log is not None: if manual_cmd_log == []: - manual_cmd_log.append('echo "Testing ${docker_image:=%s}"' % - docker_image) + manual_cmd_log.append( + 'echo "Testing ${docker_image:=%s}"' % docker_image) manual_cmd_log.append(manual_cmdline(docker_cmdline, docker_image)) server_job = jobset.JobSpec( cmdline=docker_cmdline, @@ -974,7 +977,8 @@ argp.add_argument( '--override_server', action='append', type=lambda kv: kv.split('='), - help='Use servername=HOST:PORT to explicitly specify a server. E.g. csharp=localhost:50000', + help= + 'Use servername=HOST:PORT to explicitly specify a server. E.g. csharp=localhost:50000', default=[]) argp.add_argument( '-t', '--travis', default=False, action='store_const', const=True) @@ -993,7 +997,8 @@ argp.add_argument( default=False, action='store_const', const=True, - help='Allow flaky tests to show as passing (re-runs failed tests up to five times)' + help= + 'Allow flaky tests to show as passing (re-runs failed tests up to five times)' ) argp.add_argument( '--manual_run', @@ -1014,7 +1019,8 @@ argp.add_argument( default=False, action='store_const', const=True, - help='Enable HTTP/2 server edge case testing. (Includes positive and negative tests' + help= + 'Enable HTTP/2 server edge case testing. (Includes positive and negative tests' ) argp.add_argument( '--insecure', @@ -1039,8 +1045,8 @@ args = argp.parse_args() servers = set( s - for s in itertools.chain.from_iterable(_SERVERS if x == 'all' else [x] - for x in args.server)) + for s in itertools.chain.from_iterable( + _SERVERS if x == 'all' else [x] for x in args.server)) if args.use_docker: if not args.travis: @@ -1067,10 +1073,9 @@ if not args.use_docker and servers: # we want to include everything but objc in 'all' # because objc won't run on non-mac platforms all_but_objc = set(six.iterkeys(_LANGUAGES)) - set(['objc']) -languages = set( - _LANGUAGES[l] - for l in itertools.chain.from_iterable(all_but_objc if x == 'all' else [x] - for x in args.language)) +languages = set(_LANGUAGES[l] + for l in itertools.chain.from_iterable( + all_but_objc if x == 'all' else [x] for x in args.language)) languages_http2_clients_for_http2_server_interop = set() if args.http2_server_interop: diff --git a/tools/run_tests/run_microbenchmark.py b/tools/run_tests/run_microbenchmark.py index 561217ceb1f..4e4d05cdcd4 100755 --- a/tools/run_tests/run_microbenchmark.py +++ b/tools/run_tests/run_microbenchmark.py @@ -92,8 +92,9 @@ def collect_latency(bm_name, args): benchmarks.append( jobset.JobSpec( [ - 'bins/basicprof/%s' % bm_name, '--benchmark_filter=^%s$' % - line, '--benchmark_min_time=0.05' + 'bins/basicprof/%s' % bm_name, + '--benchmark_filter=^%s$' % line, + '--benchmark_min_time=0.05' ], environ={'LATENCY_TRACE': '%s.trace' % fnize(line)}, shortname='profile-%s' % fnize(line))) @@ -102,8 +103,9 @@ def collect_latency(bm_name, args): [ sys.executable, 'tools/profiling/latency_profile/profile_analyzer.py', - '--source', '%s.trace' % fnize(line), '--fmt', 'simple', - '--out', 'reports/%s.txt' % fnize(line) + '--source', + '%s.trace' % fnize(line), '--fmt', 'simple', '--out', + 'reports/%s.txt' % fnize(line) ], timeout_seconds=20 * 60, shortname='analyze-%s' % fnize(line))) @@ -116,7 +118,8 @@ def collect_latency(bm_name, args): # run up to half the cpu count: each benchmark can use up to two cores # (one for the microbenchmark, one for the data flush) jobset.run( - benchmarks, maxjobs=max(1, multiprocessing.cpu_count() / 2)) + benchmarks, maxjobs=max(1, + multiprocessing.cpu_count() / 2)) jobset.run(profile_analysis, maxjobs=multiprocessing.cpu_count()) jobset.run(cleanup, maxjobs=multiprocessing.cpu_count()) benchmarks = [] @@ -145,8 +148,9 @@ def collect_perf(bm_name, args): benchmarks.append( jobset.JobSpec( [ - 'perf', 'record', '-o', '%s-perf.data' % fnize( - line), '-g', '-F', '997', 'bins/mutrace/%s' % bm_name, + 'perf', 'record', '-o', + '%s-perf.data' % fnize(line), '-g', '-F', '997', + 'bins/mutrace/%s' % bm_name, '--benchmark_filter=^%s$' % line, '--benchmark_min_time=10' ], shortname='perf-%s' % fnize(line))) @@ -183,12 +187,14 @@ def collect_perf(bm_name, args): def run_summary(bm_name, cfg, base_json_name): subprocess.check_call([ - 'make', bm_name, 'CONFIG=%s' % cfg, '-j', + 'make', bm_name, + 'CONFIG=%s' % cfg, '-j', '%d' % multiprocessing.cpu_count() ]) cmd = [ - 'bins/%s/%s' % (cfg, bm_name), '--benchmark_out=%s.%s.json' % - (base_json_name, cfg), '--benchmark_out_format=json' + 'bins/%s/%s' % (cfg, bm_name), + '--benchmark_out=%s.%s.json' % (base_json_name, cfg), + '--benchmark_out_format=json' ] if args.summary_time is not None: cmd += ['--benchmark_min_time=%d' % args.summary_time] @@ -205,10 +211,12 @@ def collect_summary(bm_name, args): f.write( subprocess.check_output([ 'tools/profiling/microbenchmarks/bm2bq.py', - '%s.counters.json' % bm_name, '%s.opt.json' % bm_name + '%s.counters.json' % bm_name, + '%s.opt.json' % bm_name ])) subprocess.check_call([ - 'bq', 'load', 'microbenchmarks.microbenchmarks', '%s.csv' % bm_name + 'bq', 'load', 'microbenchmarks.microbenchmarks', + '%s.csv' % bm_name ]) diff --git a/tools/run_tests/run_performance_tests.py b/tools/run_tests/run_performance_tests.py index 03b684b318c..9a9f74e9e5a 100755 --- a/tools/run_tests/run_performance_tests.py +++ b/tools/run_tests/run_performance_tests.py @@ -100,7 +100,8 @@ def create_qpsworker_job(language, jobspec = jobset.JobSpec( cmdline=cmdline, shortname=shortname, - timeout_seconds=worker_timeout, # workers get restarted after each scenario + timeout_seconds= + worker_timeout, # workers get restarted after each scenario verbose_success=True) return QpsWorkerJob(jobspec, language, host_and_port, perf_file_base_name) @@ -298,7 +299,8 @@ def create_qpsworkers(languages, worker_hosts, perf_cmd=None): port=worker[1] + language.worker_port_offset(), remote_host=worker[0], perf_cmd=perf_cmd) - for language in languages for worker_idx, worker in enumerate(workers) + for language in languages + for worker_idx, worker in enumerate(workers) ] @@ -367,10 +369,10 @@ def create_scenarios(languages, workers = workers_by_lang[str(language)][:] # 'SERVER_LANGUAGE' is an indicator for this script to pick # a server in different language. - custom_server_lang = scenario_json.get('SERVER_LANGUAGE', - None) - custom_client_lang = scenario_json.get('CLIENT_LANGUAGE', - None) + custom_server_lang = scenario_json.get( + 'SERVER_LANGUAGE', None) + custom_client_lang = scenario_json.get( + 'CLIENT_LANGUAGE', None) scenario_json = scenario_config.remove_nonproto_fields( scenario_json) if custom_server_lang and custom_client_lang: @@ -480,8 +482,8 @@ def main(): argp.add_argument( '--remote_driver_host', default=None, - help='Run QPS driver on given host. By default, QPS driver is run locally.' - ) + help= + 'Run QPS driver on given host. By default, QPS driver is run locally.') argp.add_argument( '--remote_worker_host', nargs='+', @@ -560,7 +562,8 @@ def main(): '--flame_graph_reports', default='perf_reports', type=str, - help='Name of directory to output flame graph profiles to, if any are created.' + help= + 'Name of directory to output flame graph profiles to, if any are created.' ) argp.add_argument( '-u', @@ -662,15 +665,16 @@ def main(): six.iteritems(resultset))) finally: # Consider qps workers that need to be killed as failures - qps_workers_killed += finish_qps_workers(scenario.workers, - qpsworker_jobs) + qps_workers_killed += finish_qps_workers( + scenario.workers, qpsworker_jobs) if perf_cmd and scenario_failures == 0 and not args.skip_generate_flamegraphs: workers_and_base_names = {} for worker in scenario.workers: if not worker.perf_file_base_name: raise Exception( - 'using perf buf perf report filename is unspecified') + 'using perf buf perf report filename is unspecified' + ) workers_and_base_names[ worker.host_and_port] = worker.perf_file_base_name perf_report_failures += run_collect_perf_profile_jobs( diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 3aa9eb87c77..c8e917f1171 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -182,15 +182,15 @@ def get_c_tests(travis, test_lang): js = json.load(f) return [ tgt for tgt in js - if tgt['language'] == test_lang and platform_string() in tgt[ - platforms_str] and not (travis and tgt['flaky']) + if tgt['language'] == test_lang and platform_string() in + tgt[platforms_str] and not (travis and tgt['flaky']) ] def _check_compiler(compiler, supported_compilers): if compiler not in supported_compilers: - raise Exception('Compiler %s not supported (on this platform).' % - compiler) + raise Exception( + 'Compiler %s not supported (on this platform).' % compiler) def _check_arch(arch, supported_archs): @@ -263,9 +263,9 @@ class CLanguage(object): self.config = config self.args = args if self.platform == 'windows': - _check_compiler(self.args.compiler, [ - 'default', 'cmake', 'cmake_vs2015', 'cmake_vs2017' - ]) + _check_compiler( + self.args.compiler, + ['default', 'cmake', 'cmake_vs2015', 'cmake_vs2017']) _check_arch(self.args.arch, ['default', 'x64', 'x86']) self._cmake_generator_option = 'Visual Studio 15 2017' if self.args.compiler == 'cmake_vs2017' else 'Visual Studio 14 2015' self._cmake_arch_option = 'x64' if self.args.arch == 'x64' else 'Win32' @@ -305,9 +305,9 @@ class CLanguage(object): # cmake doesn't build boringssl tests continue auto_timeout_scaling = target.get('auto_timeout_scaling', True) - polling_strategies = ( - _POLLING_STRATEGIES.get(self.platform, ['all']) - if target.get('uses_polling', True) else ['none']) + polling_strategies = (_POLLING_STRATEGIES.get( + self.platform, ['all']) if target.get('uses_polling', True) else + ['none']) if self.args.iomgr_platform == 'uv': polling_strategies = ['all'] for polling_strategy in polling_strategies: @@ -377,7 +377,8 @@ class CLanguage(object): for line in tests.split('\n'): test = line.strip() if not test: continue - cmdline = [binary, '--benchmark_filter=%s$' % test + cmdline = [binary, + '--benchmark_filter=%s$' % test ] + target['args'] out.append( self.config.job_spec( @@ -408,7 +409,8 @@ class CLanguage(object): assert base is not None assert line[1] == ' ' test = base + line.strip() - cmdline = [binary, '--gtest_filter=%s' % test + cmdline = [binary, + '--gtest_filter=%s' % test ] + target['args'] out.append( self.config.job_spec( @@ -445,8 +447,8 @@ class CLanguage(object): # don't build tools on windows just yet return ['buildtests_%s' % self.make_target] return [ - 'buildtests_%s' % self.make_target, 'tools_%s' % self.make_target, - 'check_epollexclusive' + 'buildtests_%s' % self.make_target, + 'tools_%s' % self.make_target, 'check_epollexclusive' ] def make_options(self): @@ -480,14 +482,18 @@ class CLanguage(object): def _clang_make_options(self, version_suffix=''): return [ - 'CC=clang%s' % version_suffix, 'CXX=clang++%s' % version_suffix, - 'LD=clang%s' % version_suffix, 'LDXX=clang++%s' % version_suffix + 'CC=clang%s' % version_suffix, + 'CXX=clang++%s' % version_suffix, + 'LD=clang%s' % version_suffix, + 'LDXX=clang++%s' % version_suffix ] def _gcc_make_options(self, version_suffix): return [ - 'CC=gcc%s' % version_suffix, 'CXX=g++%s' % version_suffix, - 'LD=gcc%s' % version_suffix, 'LDXX=g++%s' % version_suffix + 'CC=gcc%s' % version_suffix, + 'CXX=g++%s' % version_suffix, + 'LD=gcc%s' % version_suffix, + 'LDXX=g++%s' % version_suffix ] def _compiler_options(self, use_docker, compiler): @@ -700,8 +706,8 @@ class PythonLanguage(object): environ=dict( list(environment.items()) + [( 'GRPC_PYTHON_TESTRUNNER_FILTER', str(suite_name))]), - shortname='%s.test.%s' % (config.name, suite_name),) - for suite_name in tests_json for config in self.pythons + shortname='%s.test.%s' % (config.name, suite_name), + ) for suite_name in tests_json for config in self.pythons ] def pre_build_steps(self): @@ -801,7 +807,10 @@ class PythonLanguage(object): if os.name == 'nt': return (python35_config,) else: - return (python27_config, python34_config,) + return ( + python27_config, + python34_config, + ) elif args.compiler == 'python2.7': return (python27_config,) elif args.compiler == 'python3.4': @@ -817,8 +826,12 @@ class PythonLanguage(object): elif args.compiler == 'python_alpine': return (python27_config,) elif args.compiler == 'all_the_cpythons': - return (python27_config, python34_config, python35_config, - python36_config,) + return ( + python27_config, + python34_config, + python35_config, + python36_config, + ) else: raise Exception('Compiler %s not supported.' % args.compiler) @@ -921,13 +934,15 @@ class CSharpLanguage(object): specs = [] for assembly in six.iterkeys(tests_by_assembly): - assembly_file = 'src/csharp/%s/%s/%s%s' % ( - assembly, assembly_subdir, assembly, assembly_extension) + assembly_file = 'src/csharp/%s/%s/%s%s' % (assembly, + assembly_subdir, + assembly, + assembly_extension) if self.config.build_config != 'gcov' or self.platform != 'windows': # normally, run each test as a separate process for test in tests_by_assembly[assembly]: - cmdline = runtime_cmd + [assembly_file, '--test=%s' % test - ] + nunit_args + cmdline = runtime_cmd + [assembly_file, + '--test=%s' % test] + nunit_args specs.append( self.config.job_spec( cmdline, @@ -1147,8 +1162,8 @@ class Sanity(object): # different configurations we can run under with open('tools/run_tests/generated/configs.json') as f: - _CONFIGS = dict((cfg['config'], Config(**cfg)) - for cfg in ast.literal_eval(f.read())) + _CONFIGS = dict( + (cfg['config'], Config(**cfg)) for cfg in ast.literal_eval(f.read())) _LANGUAGES = { 'c++': CLanguage('cxx', 'c++'), @@ -1298,13 +1313,15 @@ argp.add_argument( default=False, action='store_const', const=True, - help='Allow flaky tests to show as passing (re-runs failed tests up to five times)' + help= + 'Allow flaky tests to show as passing (re-runs failed tests up to five times)' ) argp.add_argument( '--arch', choices=['default', 'x86', 'x64'], default='default', - help='Selects architecture to target. For some platforms "default" is the only supported choice.' + help= + 'Selects architecture to target. For some platforms "default" is the only supported choice.' ) argp.add_argument( '--compiler', @@ -1316,7 +1333,8 @@ argp.add_argument( 'cmake_vs2015', 'cmake_vs2017' ], default='default', - help='Selects compiler to use. Allowed values depend on the platform and language.' + help= + 'Selects compiler to use. Allowed values depend on the platform and language.' ) argp.add_argument( '--iomgr_platform', @@ -1339,7 +1357,8 @@ argp.add_argument( '--update_submodules', default=[], nargs='*', - help='Update some submodules before building. If any are updated, also run generate_projects. ' + help= + 'Update some submodules before building. If any are updated, also run generate_projects. ' + 'Submodules are specified as SUBMODULE_NAME:BRANCH; if BRANCH is omitted, master is assumed.' ) @@ -1360,7 +1379,8 @@ argp.add_argument( default=False, action='store_const', const=True, - help='Don\'t print anything when a test passes. Passing tests also will not be reported in XML report. ' + help= + 'Don\'t print anything when a test passes. Passing tests also will not be reported in XML report. ' + 'Useful when running many iterations of each test (argument -n).') argp.add_argument( '--force_default_poller', @@ -1399,8 +1419,8 @@ if not args.disable_auto_set_flakes: if test.flaky: flaky_tests.add(test.name) if test.cpu > 0: shortname_to_cpu[test.name] = test.cpu except: - print("Unexpected error getting flaky tests: %s" % - traceback.format_exc()) + print( + "Unexpected error getting flaky tests: %s" % traceback.format_exc()) if args.force_default_poller: _POLLING_STRATEGIES = {} @@ -1473,7 +1493,8 @@ if any(language.make_options() for language in languages): language_make_options = list( set([ make_option - for lang in languages for make_option in lang.make_options() + for lang in languages + for make_option in lang.make_options() ])) if args.use_docker: @@ -1530,8 +1551,8 @@ def make_jobspec(cfg, targets, makefile='Makefile'): return [ jobset.JobSpec( [ - 'cmake', '--build', '.', '--target', '%s' % target, - '--config', _MSBUILD_CONFIG[cfg] + 'cmake', '--build', '.', '--target', + '%s' % target, '--config', _MSBUILD_CONFIG[cfg] ], cwd=os.path.dirname(makefile), timeout_seconds=None) for target in targets @@ -1541,8 +1562,8 @@ def make_jobspec(cfg, targets, makefile='Makefile'): # With cmake, we've passed all the build configuration in the pre-build step already return [ jobset.JobSpec( - [os.getenv('MAKE', 'make'), '-j', '%d' % args.jobs] + - targets, + [os.getenv('MAKE', 'make'), '-j', + '%d' % args.jobs] + targets, cwd='cmake/build', timeout_seconds=None) ] @@ -1550,10 +1571,11 @@ def make_jobspec(cfg, targets, makefile='Makefile'): return [ jobset.JobSpec( [ - os.getenv('MAKE', 'make'), '-f', makefile, '-j', '%d' % - args.jobs, + os.getenv('MAKE', 'make'), '-f', makefile, '-j', + '%d' % args.jobs, 'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % - args.slowdown, 'CONFIG=%s' % cfg, 'Q=' + args.slowdown, + 'CONFIG=%s' % cfg, 'Q=' ] + language_make_options + ([] if not args.travis else ['JENKINS_BUILD=1']) + targets, timeout_seconds=None) @@ -1565,8 +1587,8 @@ def make_jobspec(cfg, targets, makefile='Makefile'): make_targets = {} for l in languages: makefile = l.makefile_name() - make_targets[makefile] = make_targets.get( - makefile, set()).union(set(l.make_targets())) + make_targets[makefile] = make_targets.get(makefile, set()).union( + set(l.make_targets())) def build_step_environ(cfg): @@ -1581,7 +1603,8 @@ build_steps = list( set( jobset.JobSpec( cmdline, environ=build_step_environ(build_config), flake_retries=2) - for l in languages for cmdline in l.pre_build_steps())) + for l in languages + for cmdline in l.pre_build_steps())) if make_targets: make_commands = itertools.chain.from_iterable( make_jobspec(build_config, list(targets), makefile) @@ -1593,12 +1616,14 @@ build_steps.extend( cmdline, environ=build_step_environ(build_config), timeout_seconds=None) - for l in languages for cmdline in l.build_steps())) + for l in languages + for cmdline in l.build_steps())) post_tests_steps = list( set( jobset.JobSpec(cmdline, environ=build_step_environ(build_config)) - for l in languages for cmdline in l.post_tests_steps())) + for l in languages + for cmdline in l.post_tests_steps())) runs_per_test = args.runs_per_test forever = args.forever @@ -1612,8 +1637,8 @@ def _shut_down_legacy_server(legacy_server_port): except: pass else: - urllib.request.urlopen('http://localhost:%d/quitquitquit' % - legacy_server_port).read() + urllib.request.urlopen( + 'http://localhost:%d/quitquitquit' % legacy_server_port).read() def _calculate_num_runs_failures(list_of_results): @@ -1679,8 +1704,8 @@ def _build_and_run(check_cancelled, return [] if not args.travis and not _has_epollexclusive() and platform_string( - ) in _POLLING_STRATEGIES and 'epollex' in _POLLING_STRATEGIES[ - platform_string()]: + ) in _POLLING_STRATEGIES and 'epollex' in _POLLING_STRATEGIES[platform_string( + )]: print('\n\nOmitting EPOLLEXCLUSIVE tests\n\n') _POLLING_STRATEGIES[platform_string()].remove('epollex') @@ -1694,12 +1719,11 @@ def _build_and_run(check_cancelled, num_test_failures = 0 try: infinite_runs = runs_per_test == 0 - one_run = set(spec - for language in languages - for spec in language.test_specs() - if (re.search(args.regex, spec.shortname) and ( - args.regex_exclude == '' or not re.search( - args.regex_exclude, spec.shortname)))) + one_run = set( + spec for language in languages for spec in language.test_specs() + if (re.search(args.regex, spec.shortname) and + (args.regex_exclude == '' or + not re.search(args.regex_exclude, spec.shortname)))) # When running on travis, we want out test runs to be as similar as possible # for reproducibility purposes. if args.travis and args.max_time <= 0: @@ -1722,8 +1746,9 @@ def _build_and_run(check_cancelled, if infinite_runs: assert len(massaged_one_run ) > 0, 'Must have at least one test for a -n inf run' - runs_sequence = (itertools.repeat(massaged_one_run) if infinite_runs - else itertools.repeat(massaged_one_run, runs_per_test)) + runs_sequence = (itertools.repeat(massaged_one_run) + if infinite_runs else itertools.repeat( + massaged_one_run, runs_per_test)) all_runs = itertools.chain.from_iterable(runs_sequence) if args.quiet_success: @@ -1750,8 +1775,8 @@ def _build_and_run(check_cancelled, else: jobset.message( 'FLAKE', - '%s [%d/%d runs flaked]' % - (k, num_failures, num_runs), + '%s [%d/%d runs flaked]' % (k, num_failures, + num_runs), do_newline=True) finally: for antagonist in antagonists: diff --git a/tools/run_tests/run_tests_matrix.py b/tools/run_tests/run_tests_matrix.py index 49be8f1d7e4..ac90bef5ac0 100755 --- a/tools/run_tests/run_tests_matrix.py +++ b/tools/run_tests/run_tests_matrix.py @@ -65,8 +65,10 @@ def _docker_jobspec(name, test_job = jobset.JobSpec( cmdline=[ 'python', 'tools/run_tests/run_tests.py', '--use_docker', '-t', - '-j', str(inner_jobs), '-x', _report_filename(name), - '--report_suite_name', '%s' % name + '-j', + str(inner_jobs), '-x', + _report_filename(name), '--report_suite_name', + '%s' % name ] + runtests_args, environ=runtests_envs, shortname='run_tests_%s' % name, @@ -90,8 +92,10 @@ def _workspace_jobspec(name, test_job = jobset.JobSpec( cmdline=[ 'bash', 'tools/run_tests/helper_scripts/run_tests_in_workspace.sh', - '-t', '-j', str(inner_jobs), '-x', '../%s' % _report_filename(name), - '--report_suite_name', '%s' % name + '-t', '-j', + str(inner_jobs), '-x', + '../%s' % _report_filename(name), '--report_suite_name', + '%s' % name ] + runtests_args, environ=env, shortname='run_tests_%s' % name, @@ -492,8 +496,8 @@ if __name__ == "__main__": jobs = [] for job in all_jobs: - if not args.filter or all(filter in job.labels - for filter in args.filter): + if not args.filter or all( + filter in job.labels for filter in args.filter): if not any(exclude_label in job.labels for exclude_label in args.exclude): jobs.append(job) diff --git a/tools/run_tests/sanity/check_test_filtering.py b/tools/run_tests/sanity/check_test_filtering.py index c2a6399ae8e..ebbb1a93b38 100755 --- a/tools/run_tests/sanity/check_test_filtering.py +++ b/tools/run_tests/sanity/check_test_filtering.py @@ -80,7 +80,8 @@ class TestFilteringTest(unittest.TestCase): if (label in job.labels): jobs_matching_labels += 1 self.assertEquals( - len(filtered_jobs), len(all_jobs) - jobs_matching_labels) + len(filtered_jobs), + len(all_jobs) - jobs_matching_labels) def test_individual_language_filters(self): # Changing unlisted file should trigger all languages