Skip to content

Commit f1310b9

Browse files
committed
Clean up the asyncio and sync client and server tests.
1 parent 1d12c64 commit f1310b9

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

tests/asyncio/test_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def test_existing_socket(self):
7575
"""Client connects using a pre-existing socket."""
7676
async with serve(*args) as server:
7777
with socket.create_connection(get_host_port(server)) as sock:
78-
# Use a non-existing domain to ensure we connect to sock.
78+
# Use a non-existing domain to ensure we connect via sock.
7979
async with connect("ws://invalid/", sock=sock) as client:
8080
self.assertEqual(client.protocol.state.name, "OPEN")
8181

@@ -341,7 +341,7 @@ def redirect(connection, request):
341341
async with serve(*args, process_request=redirect) as server:
342342
with socket.create_connection(get_host_port(server)) as sock:
343343
with self.assertRaises(ValueError) as raised:
344-
# Use a non-existing domain to ensure we connect to sock.
344+
# Use a non-existing domain to ensure we connect via sock.
345345
async with connect("ws://invalid/redirect", sock=sock):
346346
self.fail("did not raise")
347347

@@ -446,9 +446,11 @@ async def test_junk_handshake(self):
446446
"""Client closes the connection when receiving non-HTTP response from server."""
447447

448448
async def junk(reader, writer):
449-
await asyncio.sleep(MS) # wait for the client to send the handshake request
449+
# Wait for the client to send the handshake request.
450+
await asyncio.sleep(MS)
450451
writer.write(b"220 smtp.invalid ESMTP Postfix\r\n")
451-
await reader.read(4096) # wait for the client to close the connection
452+
# Wait for the client to close the connection.
453+
await reader.read(4096)
452454
writer.close()
453455

454456
server = await asyncio.start_server(junk, "localhost", 0)
@@ -652,7 +654,7 @@ async def test_ignore_proxy_with_existing_socket(self):
652654
"""Client connects using a pre-existing socket."""
653655
async with serve(*args) as server:
654656
with socket.create_connection(get_host_port(server)) as sock:
655-
# Use a non-existing domain to ensure we connect to sock.
657+
# Use a non-existing domain to ensure we connect via sock.
656658
async with connect("ws://invalid/", sock=sock) as client:
657659
self.assertEqual(client.protocol.state.name, "OPEN")
658660
self.assertNumFlows(0)

tests/asyncio/test_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ async def test_connection(self):
568568
async with serve(*args, ssl=SERVER_CONTEXT) as server:
569569
async with connect(get_uri(server), ssl=CLIENT_CONTEXT) as client:
570570
await self.assertEval(client, "ws.protocol.state.name", "OPEN")
571-
await self.assertEval(client, SSL_OBJECT + ".version()[:3]", "TLS")
571+
await self.assertEval(client, f"{SSL_OBJECT}.version()[:3]", "TLS")
572572

573573
async def test_timeout_during_tls_handshake(self):
574574
"""Server times out before receiving TLS handshake request from client."""
@@ -604,7 +604,7 @@ async def test_connection(self):
604604
async with unix_serve(handler, path, ssl=SERVER_CONTEXT):
605605
async with unix_connect(path, ssl=CLIENT_CONTEXT) as client:
606606
await self.assertEval(client, "ws.protocol.state.name", "OPEN")
607-
await self.assertEval(client, SSL_OBJECT + ".version()[:3]", "TLS")
607+
await self.assertEval(client, f"{SSL_OBJECT}.version()[:3]", "TLS")
608608

609609

610610
class ServerUsageErrorsTests(unittest.IsolatedAsyncioTestCase):

tests/sync/test_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_existing_socket(self):
4444
"""Client connects using a pre-existing socket."""
4545
with run_server() as server:
4646
with socket.create_connection(server.socket.getsockname()) as sock:
47-
# Use a non-existing domain to ensure we connect to sock.
47+
# Use a non-existing domain to ensure we connect via sock.
4848
with connect("ws://invalid/", sock=sock) as client:
4949
self.assertEqual(client.protocol.state.name, "OPEN")
5050

@@ -225,9 +225,11 @@ def test_junk_handshake(self):
225225

226226
class JunkHandler(socketserver.BaseRequestHandler):
227227
def handle(self):
228-
time.sleep(MS) # wait for the client to send the handshake request
228+
# Wait for the client to send the handshake request.
229+
time.sleep(MS)
229230
self.request.send(b"220 smtp.invalid ESMTP Postfix\r\n")
230-
self.request.recv(4096) # wait for the client to close the connection
231+
# Wait for the client to close the connection.
232+
self.request.recv(4096)
231233
self.request.close()
232234

233235
server = socketserver.TCPServer(("localhost", 0), JunkHandler)
@@ -401,7 +403,7 @@ def test_ignore_proxy_with_existing_socket(self):
401403
"""Client connects using a pre-existing socket."""
402404
with run_server() as server:
403405
with socket.create_connection(server.socket.getsockname()) as sock:
404-
# Use a non-existing domain to ensure we connect to sock.
406+
# Use a non-existing domain to ensure we connect via sock.
405407
with connect("ws://invalid/", sock=sock) as client:
406408
self.assertEqual(client.protocol.state.name, "OPEN")
407409
self.assertNumFlows(0)
@@ -648,7 +650,7 @@ def test_proxy_ssl_without_https_proxy(self):
648650
connect(
649651
"ws://localhost/",
650652
proxy="http://localhost:8080",
651-
proxy_ssl=True,
653+
proxy_ssl=CLIENT_CONTEXT,
652654
)
653655
self.assertEqual(
654656
str(raised.exception),

0 commit comments

Comments
 (0)