Yapf. Pylint

pull/20838/head
Richard Belleville 5 years ago
parent a577c75cb1
commit 89fba97892
  1. 3
      src/python/grpcio_tests/tests/unit/_metadata_flags_test.py
  2. 14
      src/python/grpcio_tests/tests/unit/framework/common/__init__.py
  3. 1
      src/python/grpcio_tests/tests_aio/unit/test_base.py

@ -229,7 +229,8 @@ class MetadataFlagsTest(unittest.TestCase):
# Start the server after the connections are waiting # Start the server after the connections are waiting
wg.wait() wg.wait()
server = test_common.test_server() server = test_common.test_server()
server.add_generic_rpc_handlers((_GenericHandler(weakref.proxy(self)),)) server.add_generic_rpc_handlers((_GenericHandler(
weakref.proxy(self)),))
server.add_insecure_port(addr) server.add_insecure_port(addr)
server.start() server.start()

@ -16,7 +16,9 @@ import contextlib
import socket import socket
def get_socket(bind_address='localhost', listen=True, sock_options=(socket.SO_REUSEPORT,)): def get_socket(bind_address='localhost',
listen=True,
sock_options=(socket.SO_REUSEPORT,)):
"""Opens a socket bound to an arbitrary port. """Opens a socket bound to an arbitrary port.
Useful for reserving a port for a system-under-test. Useful for reserving a port for a system-under-test.
@ -44,11 +46,14 @@ def get_socket(bind_address='localhost', listen=True, sock_options=(socket.SO_RE
return bind_address, sock.getsockname()[1], sock return bind_address, sock.getsockname()[1], sock
except socket.error: except socket.error:
continue continue
raise RuntimeError("Failed to find to {} with sock_options {}".format(bind_address, sock_options)) raise RuntimeError("Failed to bind to {} with sock_options {}".format(
bind_address, sock_options))
@contextlib.contextmanager @contextlib.contextmanager
def bound_socket(bind_address='localhost', listen=True, sock_options=(socket.SO_REUSEPORT,)): def bound_socket(bind_address='localhost',
listen=True,
sock_options=(socket.SO_REUSEPORT,)):
"""Opens a socket bound to an arbitrary port. """Opens a socket bound to an arbitrary port.
Useful for reserving a port for a system-under-test. Useful for reserving a port for a system-under-test.
@ -63,7 +68,8 @@ def bound_socket(bind_address='localhost', listen=True, sock_options=(socket.SO_
- the address to which the socket is bound - the address to which the socket is bound
- the port to which the socket is bound - the port to which the socket is bound
""" """
host, port, sock = get_socket(bind_address=bind_address, listen=listen, sock_options=sock_options) host, port, sock = get_socket(
bind_address=bind_address, listen=listen, sock_options=sock_options)
try: try:
yield host, port yield host, port
finally: finally:

@ -24,6 +24,7 @@ from grpc.experimental import aio
from tests_aio.unit import sync_server from tests_aio.unit import sync_server
from tests.unit.framework.common import get_socket from tests.unit.framework.common import get_socket
def _get_free_loopback_tcp_port(): def _get_free_loopback_tcp_port():
host, port, sock = get_socket(listen=False) host, port, sock = get_socket(listen=False)
return sock, "{}:{}".format(host, port) return sock, "{}:{}".format(host, port)

Loading…
Cancel
Save