Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions Lib/test/test_asyncio/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,11 @@ def prepare(self):
self.run_loop(self.loop.sock_connect(sock, (support.HOST, port)))

def cleanup():
proto.transport.close()
self.run_loop(proto.wait_closed())
if proto.transport is not None:
# can be None if the task was cancelled before
# connection_made callback
proto.transport.close()
self.run_loop(proto.wait_closed())

server.close()
self.run_loop(server.wait_closed())
Expand All @@ -494,7 +497,7 @@ def cleanup():

return sock, proto

def test_success(self):
def test_sock_sendfile_success(self):
sock, proto = self.prepare()
ret = self.run_loop(self.loop.sock_sendfile(sock, self.file))
sock.close()
Expand All @@ -504,7 +507,7 @@ def test_success(self):
self.assertEqual(proto.data, self.DATA)
self.assertEqual(self.file.tell(), len(self.DATA))

def test_with_offset_and_count(self):
def test_sock_sendfile_with_offset_and_count(self):
sock, proto = self.prepare()
ret = self.run_loop(self.loop.sock_sendfile(sock, self.file,
1000, 2000))
Expand All @@ -515,7 +518,7 @@ def test_with_offset_and_count(self):
self.assertEqual(self.file.tell(), 3000)
self.assertEqual(ret, 2000)

def test_sendfile_not_available(self):
def test_sock_sendfile_not_available(self):
sock, proto = self.prepare()
with mock.patch('asyncio.unix_events.os', spec=[]):
with self.assertRaisesRegex(events.SendfileNotAvailableError,
Expand All @@ -524,7 +527,7 @@ def test_sendfile_not_available(self):
0, None))
self.assertEqual(self.file.tell(), 0)

def test_sendfile_not_a_file(self):
def test_sock_sendfile_not_a_file(self):
sock, proto = self.prepare()
f = object()
with self.assertRaisesRegex(events.SendfileNotAvailableError,
Expand All @@ -533,7 +536,7 @@ def test_sendfile_not_a_file(self):
0, None))
self.assertEqual(self.file.tell(), 0)

def test_sendfile_iobuffer(self):
def test_sock_sendfile_iobuffer(self):
sock, proto = self.prepare()
f = io.BytesIO()
with self.assertRaisesRegex(events.SendfileNotAvailableError,
Expand All @@ -542,7 +545,7 @@ def test_sendfile_iobuffer(self):
0, None))
self.assertEqual(self.file.tell(), 0)

def test_sendfile_not_regular_file(self):
def test_sock_sendfile_not_regular_file(self):
sock, proto = self.prepare()
f = mock.Mock()
f.fileno.return_value = -1
Expand All @@ -552,7 +555,7 @@ def test_sendfile_not_regular_file(self):
0, None))
self.assertEqual(self.file.tell(), 0)

def test_sendfile_zero_size(self):
def test_sock_sendfile_zero_size(self):
sock, proto = self.prepare()
fname = support.TESTFN + '.suffix'
with open(fname, 'wb') as f:
Expand All @@ -568,7 +571,7 @@ def test_sendfile_zero_size(self):
self.assertEqual(ret, 0)
self.assertEqual(self.file.tell(), 0)

def test_mix_sendfile_and_regular_send(self):
def test_sock_sendfile_mix_with_regular_send(self):
buf = b'1234567890' * 1024 * 1024 # 10 MB
sock, proto = self.prepare()
self.run_loop(self.loop.sock_sendall(sock, buf))
Expand All @@ -582,7 +585,7 @@ def test_mix_sendfile_and_regular_send(self):
self.assertEqual(proto.data, expected)
self.assertEqual(self.file.tell(), len(self.DATA))

def test_cancel1(self):
def test_sock_sendfile_cancel1(self):
sock, proto = self.prepare()

fut = self.loop.create_future()
Expand All @@ -595,7 +598,7 @@ def test_cancel1(self):
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)

def test_cancel2(self):
def test_sock_sendfile_cancel2(self):
sock, proto = self.prepare()

fut = self.loop.create_future()
Expand All @@ -608,7 +611,7 @@ def test_cancel2(self):
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)

def test_blocking_error(self):
def test_sock_sendfile_blocking_error(self):
sock, proto = self.prepare()

fileno = self.file.fileno()
Expand All @@ -621,7 +624,7 @@ def test_blocking_error(self):
self.assertIsNotNone(key)
fut.add_done_callback.assert_called_once_with(mock.ANY)

def test_os_error_first_call(self):
def test_sock_sendfile_os_error_first_call(self):
sock, proto = self.prepare()

fileno = self.file.fileno()
Expand All @@ -635,7 +638,7 @@ def test_os_error_first_call(self):
self.assertIsInstance(exc, events.SendfileNotAvailableError)
self.assertEqual(0, self.file.tell())

def test_os_error_next_call(self):
def test_sock_sendfile_os_error_next_call(self):
sock, proto = self.prepare()

fileno = self.file.fileno()
Expand All @@ -652,7 +655,7 @@ def test_os_error_next_call(self):
self.assertIs(exc, err)
self.assertEqual(1000, self.file.tell())

def test_exception(self):
def test_sock_sendfile_exception(self):
sock, proto = self.prepare()

fileno = self.file.fileno()
Expand Down