From 96321ed57f923e3310e83fcd4dd03100f5558e94 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Tue, 7 Jan 2020 16:28:24 -0800 Subject: [PATCH] Make sanity tests happy --- .../grpcio/grpc/experimental/aio/_channel.py | 6 +-- src/python/grpcio_tests/tests_aio/tests.json | 1 + .../tests_aio/unit/channel_argument_test.py | 37 +++++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/python/grpcio/grpc/experimental/aio/_channel.py b/src/python/grpcio/grpc/experimental/aio/_channel.py index 9ec235393c8..dfce30edf5e 100644 --- a/src/python/grpcio/grpc/experimental/aio/_channel.py +++ b/src/python/grpcio/grpc/experimental/aio/_channel.py @@ -13,7 +13,7 @@ # limitations under the License. """Invocation-side implementation of gRPC Asyncio Python.""" import asyncio -from typing import Any, Optional, Sequence, Text, Tuple +from typing import Any, Optional, Text import grpc from grpc import _common @@ -188,9 +188,7 @@ class Channel: _channel: cygrpc.AioChannel _unary_unary_interceptors: Optional[Sequence[UnaryUnaryClientInterceptor]] - def __init__(self, - target: Text, - options: Optional[ChannelArgumentType], + def __init__(self, target: Text, options: Optional[ChannelArgumentType], credentials: Optional[grpc.ChannelCredentials], compression: Optional[grpc.Compression], interceptors: Optional[Sequence[UnaryUnaryClientInterceptor]]): diff --git a/src/python/grpcio_tests/tests_aio/tests.json b/src/python/grpcio_tests/tests_aio/tests.json index 26545c29dc9..1a9cbb44f8d 100644 --- a/src/python/grpcio_tests/tests_aio/tests.json +++ b/src/python/grpcio_tests/tests_aio/tests.json @@ -3,6 +3,7 @@ "unit.aio_rpc_error_test.TestAioRpcError", "unit.call_test.TestUnaryStreamCall", "unit.call_test.TestUnaryUnaryCall", + "unit.channel_argument_test.TestChannelArgument", "unit.channel_test.TestChannel", "unit.init_test.TestInsecureChannel", "unit.interceptor_test.TestInterceptedUnaryUnaryCall", diff --git a/src/python/grpcio_tests/tests_aio/unit/channel_argument_test.py b/src/python/grpcio_tests/tests_aio/unit/channel_argument_test.py index 4b8f1680fac..934085d8ba2 100644 --- a/src/python/grpcio_tests/tests_aio/unit/channel_argument_test.py +++ b/src/python/grpcio_tests/tests_aio/unit/channel_argument_test.py @@ -44,6 +44,7 @@ _NUM_SERVER_CREATED = 100 _GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH = 'grpc.max_receive_message_length' _MAX_MESSAGE_LENGTH = 1024 + class _TestPointerWrapper(object): def __int__(self): @@ -58,9 +59,10 @@ _TEST_CHANNEL_ARGS = ( ('arg6', _TestPointerWrapper()), ) - _INVALID_TEST_CHANNEL_ARGS = [ - {'foo': 'bar'}, + { + 'foo': 'bar' + }, (('key',),), 'str', ] @@ -97,13 +99,16 @@ class TestChannelArgument(AioTestBase): try: result = await test_if_reuse_port_enabled(server) if fact == _ENABLE_REUSE_PORT and not result: - self.fail('Enabled reuse port in options, but not observed in socket') + self.fail( + 'Enabled reuse port in options, but not observed in socket' + ) elif fact == _DISABLE_REUSE_PORT and result: - self.fail('Disabled reuse port in options, but observed in socket') + self.fail( + 'Disabled reuse port in options, but observed in socket' + ) finally: await server.stop(None) - async def test_client(self): aio.insecure_channel('[::]:0', options=_TEST_CHANNEL_ARGS) @@ -120,33 +125,35 @@ class TestChannelArgument(AioTestBase): async def test_max_message_length_applied(self): address, server = await start_test_server() - async with aio.insecure_channel(address, options=( - (_GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH, _MAX_MESSAGE_LENGTH), - )) as channel: + async with aio.insecure_channel( + address, + options=((_GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH, + _MAX_MESSAGE_LENGTH),)) as channel: stub = test_pb2_grpc.TestServiceStub(channel) request = messages_pb2.StreamingOutputCallRequest() # First request will pass request.response_parameters.append( - messages_pb2.ResponseParameters(size=_MAX_MESSAGE_LENGTH//2,) - ) + messages_pb2.ResponseParameters(size=_MAX_MESSAGE_LENGTH // 2,)) # Second request should fail request.response_parameters.append( - messages_pb2.ResponseParameters(size=_MAX_MESSAGE_LENGTH*2,) - ) + messages_pb2.ResponseParameters(size=_MAX_MESSAGE_LENGTH * 2,)) call = stub.StreamingOutputCall(request) response = await call.read() - self.assertEqual(_MAX_MESSAGE_LENGTH//2, len(response.payload.body)) + self.assertEqual(_MAX_MESSAGE_LENGTH // 2, + len(response.payload.body)) with self.assertRaises(aio.AioRpcError) as exception_context: await call.read() rpc_error = exception_context.exception - self.assertEqual(grpc.StatusCode.RESOURCE_EXHAUSTED, rpc_error.code()) + self.assertEqual(grpc.StatusCode.RESOURCE_EXHAUSTED, + rpc_error.code()) self.assertIn(str(_MAX_MESSAGE_LENGTH), rpc_error.details()) - self.assertEqual(grpc.StatusCode.RESOURCE_EXHAUSTED, await call.code()) + self.assertEqual(grpc.StatusCode.RESOURCE_EXHAUSTED, await + call.code()) await server.stop(None)