Skip to content

Commit 6388dc6

Browse files
committed
reformat tests
1 parent 7a2ddc5 commit 6388dc6

5 files changed

Lines changed: 53 additions & 38 deletions

File tree

tests/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def suite():
1010
return test_suite
1111

1212

13-
if __name__ == '__main__':
13+
if __name__ == "__main__":
1414
runner = unittest.runner.TextTestRunner()
1515
result = runner.run(suite())
1616
sys.exit(not result.wasSuccessful())

tests/test_context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,7 @@ def close():
493493
# put the incoming data on-hold
494494
proto.transport.pause_reading()
495495
# send data
496-
await self.loop.run_in_executor(None,
497-
ssl_sock.send, b'hello')
496+
await self.loop.run_in_executor(None, ssl_sock.send, b"hello")
498497
# After gh-105836 run_in_executor may resolve without
499498
# yielding. This is very noticeable when PYTHONASYNCIODEBUG
500499
# is set. Hence, we yield explicitly so that the sent data

tests/test_pipes.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ async def connect():
107107

108108
os.close(wpipe)
109109
self.loop.run_until_complete(proto.done)
110-
self.assertEqual(["INITIAL", "CONNECTED", "EOF", "CLOSED"], proto.state)
110+
self.assertEqual(
111+
["INITIAL", "CONNECTED", "EOF", "CLOSED"], proto.state
112+
)
111113
# extra info is available
112114
self.assertIsNotNone(proto.transport.get_extra_info("pipe"))
113115

@@ -119,7 +121,9 @@ def test_read_pty_output(self):
119121
master_read_obj = io.open(master, "rb", 0)
120122

121123
async def connect():
122-
t, p = await self.loop.connect_read_pipe(lambda: proto, master_read_obj)
124+
t, p = await self.loop.connect_read_pipe(
125+
lambda: proto, master_read_obj
126+
)
123127
self.assertIs(p, proto)
124128
self.assertIs(t, proto.transport)
125129
self.assertEqual(["INITIAL", "CONNECTED"], proto.state)
@@ -143,7 +147,9 @@ async def connect():
143147
proto.transport.close()
144148
self.loop.run_until_complete(proto.done)
145149

146-
self.assertEqual(["INITIAL", "CONNECTED", "EOF", "CLOSED"], proto.state)
150+
self.assertEqual(
151+
["INITIAL", "CONNECTED", "EOF", "CLOSED"], proto.state
152+
)
147153
# extra info is available
148154
self.assertIsNotNone(proto.transport.get_extra_info("pipe"))
149155

@@ -262,7 +268,9 @@ def reader(data):
262268
self.loop.run_until_complete(proto.done)
263269
self.assertEqual("CLOSED", proto.state)
264270

265-
@unittest.skipIf(sys.platform == "win32", "do not support pipes for Windows")
271+
@unittest.skipIf(
272+
sys.platform == "win32", "do not support pipes for Windows"
273+
)
266274
def test_write_buffer_full(self):
267275
rpipe, wpipe = os.pipe()
268276
pipeobj = io.open(wpipe, "wb", 1024)

tests/test_tcp.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ async def client(addr):
786786
await asyncio.sleep(0.01)
787787

788788
task = asyncio.ensure_future(
789-
self.loop.create_connection(asyncio.Protocol, sock=sock))
789+
self.loop.create_connection(asyncio.Protocol, sock=sock)
790+
)
790791
await asyncio.sleep(0)
791792
task.cancel()
792793
with self.assertRaises(asyncio.CancelledError):
@@ -802,9 +803,7 @@ def _recv_or_abort(sock):
802803
except ConnectionAbortedError:
803804
pass
804805

805-
with self.tcp_server(_recv_or_abort,
806-
max_clients=1,
807-
backlog=1) as srv:
806+
with self.tcp_server(_recv_or_abort, max_clients=1, backlog=1) as srv:
808807
self.loop.run_until_complete(client(srv.addr))
809808

810809
def test_create_connection_sock_cancel_fd_leak(self):
@@ -824,9 +823,8 @@ def test_create_connection_sock_cancel_fd_leak(self):
824823

825824
async def test():
826825
srv = await asyncio.start_server(
827-
lambda r, w: w.close(),
828-
'127.0.0.1', 0,
829-
family=socket.AF_INET)
826+
lambda r, w: w.close(), "127.0.0.1", 0, family=socket.AF_INET
827+
)
830828
addr = srv.sockets[0].getsockname()
831829

832830
# --- Step 1: create_connection with sock= and cancel it ---
@@ -845,15 +843,17 @@ async def test():
845843

846844
# --- Step 2: a victim connection reuses the fd ---
847845
victim_tr, _ = await self.loop.create_connection(
848-
asyncio.Protocol, *addr)
849-
victim_fd = victim_tr.get_extra_info('socket').fileno()
846+
asyncio.Protocol, *addr
847+
)
848+
victim_fd = victim_tr.get_extra_info("socket").fileno()
850849
if victim_fd != stale_fd:
851850
victim_tr.close()
852851
sock.close()
853852
srv.close()
854853
await srv.wait_closed()
855854
raise unittest.SkipTest(
856-
f'fd not reused (got {victim_fd}, need {stale_fd})')
855+
f"fd not reused (got {victim_fd}, need {stale_fd})"
856+
)
857857

858858
# --- Step 3: stale sock.close() must NOT kill the victim ---
859859
# Allocate the socketpair BEFORE sock.close() so the pair
@@ -879,12 +879,12 @@ async def test():
879879

880880
# Victim writes. If victim_broken, writev(stale_fd) goes
881881
# to the spy; otherwise it goes to the real connection.
882-
victim_tr.write(b'LEAKED')
882+
victim_tr.write(b"LEAKED")
883883

884884
try:
885885
leaked = spy_b.recv(4096)
886886
except BlockingIOError:
887-
leaked = b''
887+
leaked = b""
888888

889889
if victim_broken:
890890
os.close(stale_fd)
@@ -893,9 +893,11 @@ async def test():
893893
srv.close()
894894
await srv.wait_closed()
895895

896-
self.assertEqual(leaked, b'',
897-
f"Data leaked to an unrelated socket: "
898-
f"got {leaked!r}")
896+
self.assertEqual(
897+
leaked,
898+
b"",
899+
f"Data leaked to an unrelated socket: " f"got {leaked!r}",
900+
)
899901

900902
self.loop.run_until_complete(test())
901903

tests/test_unix.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,10 @@ def test_create_unix_connection_6(self):
423423

424424
def test_create_unix_connection_sock_cancel_detaches(self):
425425
async def test():
426-
srv_path = os.path.join(tempfile.mkdtemp(), 'test.sock')
426+
srv_path = os.path.join(tempfile.mkdtemp(), "test.sock")
427427
srv = await asyncio.start_unix_server(
428-
lambda r, w: w.close(), path=srv_path)
428+
lambda r, w: w.close(), path=srv_path
429+
)
429430

430431
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
431432
sock.setblocking(False)
@@ -436,8 +437,8 @@ async def test():
436437
await asyncio.sleep(0.01)
437438

438439
task = asyncio.ensure_future(
439-
self.loop.create_unix_connection(
440-
asyncio.Protocol, sock=sock))
440+
self.loop.create_unix_connection(asyncio.Protocol, sock=sock)
441+
)
441442
await asyncio.sleep(0)
442443
task.cancel()
443444
with self.assertRaises(asyncio.CancelledError):
@@ -457,18 +458,19 @@ def test_create_unix_connection_sock_cancel_fd_leak(self):
457458
# the create_unix_connection(sock=) path.
458459

459460
async def test():
460-
srv_path = os.path.join(tempfile.mkdtemp(), 'test.sock')
461+
srv_path = os.path.join(tempfile.mkdtemp(), "test.sock")
461462
srv = await asyncio.start_unix_server(
462-
lambda r, w: w.close(), path=srv_path)
463+
lambda r, w: w.close(), path=srv_path
464+
)
463465

464466
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
465467
sock.setblocking(False)
466468
await self.loop.sock_connect(sock, srv_path)
467469
stale_fd = sock.fileno()
468470

469471
task = self.loop.create_task(
470-
self.loop.create_unix_connection(
471-
asyncio.Protocol, sock=sock))
472+
self.loop.create_unix_connection(asyncio.Protocol, sock=sock)
473+
)
472474
await asyncio.sleep(0)
473475
task.cancel()
474476
with self.assertRaises(asyncio.CancelledError):
@@ -479,8 +481,9 @@ async def test():
479481
victim_sock.setblocking(False)
480482
await self.loop.sock_connect(victim_sock, srv_path)
481483
victim_tr, _ = await self.loop.create_unix_connection(
482-
asyncio.Protocol, sock=victim_sock)
483-
victim_fd = victim_tr.get_extra_info('socket').fileno()
484+
asyncio.Protocol, sock=victim_sock
485+
)
486+
victim_fd = victim_tr.get_extra_info("socket").fileno()
484487
if victim_fd != stale_fd:
485488
victim_tr.close()
486489
sock.close()
@@ -489,7 +492,8 @@ async def test():
489492
if os.path.exists(srv_path):
490493
os.unlink(srv_path)
491494
raise unittest.SkipTest(
492-
f'fd not reused (got {victim_fd}, need {stale_fd})')
495+
f"fd not reused (got {victim_fd}, need {stale_fd})"
496+
)
493497

494498
spy_a, spy_b = socket.socketpair()
495499
spy_b.setblocking(False)
@@ -506,12 +510,12 @@ async def test():
506510
os.dup2(spy_a.fileno(), stale_fd)
507511
spy_a.close()
508512

509-
victim_tr.write(b'LEAKED')
513+
victim_tr.write(b"LEAKED")
510514

511515
try:
512516
leaked = spy_b.recv(4096)
513517
except BlockingIOError:
514-
leaked = b''
518+
leaked = b""
515519

516520
if victim_broken:
517521
os.close(stale_fd)
@@ -526,9 +530,11 @@ async def test():
526530
if os.path.exists(srv_path):
527531
os.unlink(srv_path)
528532

529-
self.assertEqual(leaked, b'',
530-
f"Data leaked to an unrelated socket: "
531-
f"got {leaked!r}")
533+
self.assertEqual(
534+
leaked,
535+
b"",
536+
f"Data leaked to an unrelated socket: " f"got {leaked!r}",
537+
)
532538

533539
self.loop.run_until_complete(test())
534540

0 commit comments

Comments
 (0)