bpo-32410: Make SendfileNotAvailableError exception public (#5243)

This commit is contained in:
Andrew Svetlov 2018-01-19 20:04:29 +02:00 committed by GitHub
parent 2507e29a9e
commit 7464e87a65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 25 deletions

View file

@ -23,6 +23,7 @@
import asyncio
from asyncio import log
from asyncio import base_events
from asyncio import events
from asyncio import unix_events
from test.test_asyncio import utils as test_utils
@ -517,7 +518,7 @@ def test_with_offset_and_count(self):
def test_sendfile_not_available(self):
sock, proto = self.prepare()
with mock.patch('asyncio.unix_events.os', spec=[]):
with self.assertRaisesRegex(base_events._SendfileNotAvailable,
with self.assertRaisesRegex(events.SendfileNotAvailableError,
"os[.]sendfile[(][)] is not available"):
self.run_loop(self.loop._sock_sendfile_native(sock, self.file,
0, None))
@ -526,7 +527,7 @@ def test_sendfile_not_available(self):
def test_sendfile_not_a_file(self):
sock, proto = self.prepare()
f = object()
with self.assertRaisesRegex(base_events._SendfileNotAvailable,
with self.assertRaisesRegex(events.SendfileNotAvailableError,
"not a regular file"):
self.run_loop(self.loop._sock_sendfile_native(sock, f,
0, None))
@ -535,7 +536,7 @@ def test_sendfile_not_a_file(self):
def test_sendfile_iobuffer(self):
sock, proto = self.prepare()
f = io.BytesIO()
with self.assertRaisesRegex(base_events._SendfileNotAvailable,
with self.assertRaisesRegex(events.SendfileNotAvailableError,
"not a regular file"):
self.run_loop(self.loop._sock_sendfile_native(sock, f,
0, None))
@ -545,7 +546,7 @@ def test_sendfile_not_regular_file(self):
sock, proto = self.prepare()
f = mock.Mock()
f.fileno.return_value = -1
with self.assertRaisesRegex(base_events._SendfileNotAvailable,
with self.assertRaisesRegex(events.SendfileNotAvailableError,
"not a regular file"):
self.run_loop(self.loop._sock_sendfile_native(sock, f,
0, None))
@ -631,7 +632,7 @@ def test_os_error_first_call(self):
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
exc = fut.exception()
self.assertIsInstance(exc, base_events._SendfileNotAvailable)
self.assertIsInstance(exc, events.SendfileNotAvailableError)
self.assertEqual(0, self.file.tell())
def test_os_error_next_call(self):
@ -656,7 +657,7 @@ def test_exception(self):
fileno = self.file.fileno()
fut = self.loop.create_future()
err = RuntimeError()
err = events.SendfileNotAvailableError()
with mock.patch('os.sendfile', side_effect=err):
self.loop._sock_sendfile_native_impl(fut, sock.fileno(),
sock, fileno,