asyncio, Tulip issue 126: call_soon(), call_soon_threadsafe(), call_later(),

call_at() and run_in_executor() now raise a TypeError if the callback is a
coroutine function.
This commit is contained in:
Victor Stinner 2014-02-11 11:34:30 +01:00
parent 1db2ba3a92
commit a125497ea3
6 changed files with 39 additions and 13 deletions

View file

@ -567,6 +567,7 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
m_socket.getaddrinfo.return_value = [
(2, 1, 6, '', ('127.0.0.1', 10100))]
m_socket.getaddrinfo._is_coroutine = False
m_sock = m_socket.socket.return_value = unittest.mock.Mock()
m_sock.bind.side_effect = Err
@ -577,6 +578,7 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
@unittest.mock.patch('asyncio.base_events.socket')
def test_create_datagram_endpoint_no_addrinfo(self, m_socket):
m_socket.getaddrinfo.return_value = []
m_socket.getaddrinfo._is_coroutine = False
coro = self.loop.create_datagram_endpoint(
MyDatagramProto, local_addr=('localhost', 0))
@ -681,6 +683,22 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
unittest.mock.ANY,
MyProto, sock, None, None)
def test_call_coroutine(self):
@asyncio.coroutine
def coroutine_function():
pass
with self.assertRaises(TypeError):
self.loop.call_soon(coroutine_function)
with self.assertRaises(TypeError):
self.loop.call_soon_threadsafe(coroutine_function)
with self.assertRaises(TypeError):
self.loop.call_later(60, coroutine_function)
with self.assertRaises(TypeError):
self.loop.call_at(self.loop.time() + 60, coroutine_function)
with self.assertRaises(TypeError):
self.loop.run_in_executor(None, coroutine_function)
if __name__ == '__main__':
unittest.main()