mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
asyncio: Better-looking errors when ssl module cannot be imported. In part by Arnaud Faure.
This commit is contained in:
parent
a8d630a6e6
commit
28dff0d823
3 changed files with 41 additions and 12 deletions
|
@ -43,6 +43,7 @@ class BaseSelectorEventLoopTests(unittest.TestCase):
|
|||
self.assertIsInstance(
|
||||
self.loop._make_socket_transport(m, m), _SelectorSocketTransport)
|
||||
|
||||
@unittest.skipIf(ssl is None, 'No ssl module')
|
||||
def test_make_ssl_transport(self):
|
||||
m = unittest.mock.Mock()
|
||||
self.loop.add_reader = unittest.mock.Mock()
|
||||
|
@ -52,6 +53,16 @@ class BaseSelectorEventLoopTests(unittest.TestCase):
|
|||
self.assertIsInstance(
|
||||
self.loop._make_ssl_transport(m, m, m, m), _SelectorSslTransport)
|
||||
|
||||
@unittest.mock.patch('asyncio.selector_events.ssl', None)
|
||||
def test_make_ssl_transport_without_ssl_error(self):
|
||||
m = unittest.mock.Mock()
|
||||
self.loop.add_reader = unittest.mock.Mock()
|
||||
self.loop.add_writer = unittest.mock.Mock()
|
||||
self.loop.remove_reader = unittest.mock.Mock()
|
||||
self.loop.remove_writer = unittest.mock.Mock()
|
||||
with self.assertRaises(RuntimeError):
|
||||
self.loop._make_ssl_transport(m, m, m, m)
|
||||
|
||||
def test_close(self):
|
||||
ssock = self.loop._ssock
|
||||
ssock.fileno.return_value = 7
|
||||
|
@ -1277,6 +1288,15 @@ class SelectorSslTransportTests(unittest.TestCase):
|
|||
server_hostname='localhost')
|
||||
|
||||
|
||||
class SelectorSslWithoutSslTransportTests(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('asyncio.selector_events.ssl', None)
|
||||
def test_ssl_transport_requires_ssl_module(self):
|
||||
Mock = unittest.mock.Mock
|
||||
with self.assertRaises(RuntimeError):
|
||||
transport = _SelectorSslTransport(Mock(), Mock(), Mock(), Mock())
|
||||
|
||||
|
||||
class SelectorDatagramTransportTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue