Skip to content

Commit 10cefd7

Browse files
committed
tests: Refactor test for coroutines compiled with Cython
1 parent eac660a commit 10cefd7

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

tests/test_base.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -416,30 +416,6 @@ def coro():
416416

417417
class TestBaseUV(_TestBase, UVTestCase):
418418

419-
def test_cython_coro_is_coroutine(self):
420-
from asyncio.coroutines import _format_coroutine
421-
422-
coro = self.loop.create_server(object)
423-
424-
self.assertEqual(_format_coroutine(coro),
425-
'Loop.create_server()')
426-
427-
self.assertEqual(self.loop.create_server.__qualname__,
428-
'Loop.create_server')
429-
self.assertEqual(self.loop.create_server.__name__,
430-
'create_server')
431-
self.assertTrue(asyncio.iscoroutine(coro))
432-
fut = asyncio.ensure_future(coro, loop=self.loop)
433-
self.assertTrue(isinstance(fut, asyncio.Future))
434-
fut.cancel()
435-
try:
436-
self.loop.run_until_complete(fut)
437-
except asyncio.CancelledError:
438-
pass
439-
440-
_format_coroutine(coro) # This line checks against Cython segfault
441-
coro.close()
442-
443419
def test_loop_create_future(self):
444420
fut = self.loop.create_future()
445421
self.assertTrue(isinstance(fut, asyncio.Future))

tests/test_cython.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import asyncio
2+
3+
from uvloop._testbase import UVTestCase
4+
5+
6+
class TestCythonIntegration(UVTestCase):
7+
8+
def test_cython_coro_is_coroutine(self):
9+
from uvloop.loop import _test_coroutine_1
10+
from asyncio.coroutines import _format_coroutine
11+
12+
coro = _test_coroutine_1()
13+
14+
self.assertEqual(_format_coroutine(coro), '_test_coroutine_1()')
15+
self.assertEqual(_test_coroutine_1.__qualname__, '_test_coroutine_1')
16+
self.assertEqual(_test_coroutine_1.__name__, '_test_coroutine_1')
17+
self.assertTrue(asyncio.iscoroutine(coro))
18+
fut = asyncio.ensure_future(coro, loop=self.loop)
19+
self.assertTrue(isinstance(fut, asyncio.Future))
20+
self.assertTrue(isinstance(fut, asyncio.Task))
21+
fut.cancel()
22+
23+
with self.assertRaises(asyncio.CancelledError):
24+
self.loop.run_until_complete(fut)
25+
26+
_format_coroutine(coro) # This line checks against Cython segfault
27+
coro.close()

uvloop/loop.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,3 +2271,8 @@ cdef __install_pymem():
22712271
if err < 0:
22722272
__mem_installed = 0
22732273
raise convert_error(err)
2274+
2275+
########### Stuff for tests:
2276+
2277+
async def _test_coroutine_1():
2278+
return 42

0 commit comments

Comments
 (0)