[Python-checkins] bpo-32410: Improve sock_sendfile tests (#5294)
Andrew Svetlov
webhook-mailer at python.org
Wed Jan 24 14:40:38 EST 2018
https://github.com/python/cpython/commit/0a5e71b4c70aab87125a54d7a59765e18d7583a4
commit: 0a5e71b4c70aab87125a54d7a59765e18d7583a4
branch: master
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-01-24T21:40:35+02:00
summary:
bpo-32410: Improve sock_sendfile tests (#5294)
* Rename sock_sendfile test methods
* Make sock_sendfile tests more stable
files:
M Lib/test/test_asyncio/test_unix_events.py
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 8646bf765e9..5bd76d30d2d 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -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())
@@ -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()
@@ -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))
@@ -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,
@@ -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,
@@ -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,
@@ -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
@@ -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:
@@ -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))
@@ -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()
@@ -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()
@@ -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()
@@ -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()
@@ -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()
@@ -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()
More information about the Python-checkins
mailing list