diff --git a/src/tests/test.py b/src/tests/test.py index be9f851..59cd721 100644 --- a/src/tests/test.py +++ b/src/tests/test.py @@ -3,7 +3,6 @@ import unittest import decimal import inspect -from asyncio import get_event_loop from collections import defaultdict, ChainMap, abc as c from decorator import dispatch_on, contextmanager, decorator try: @@ -28,9 +27,22 @@ async def before_after(coro, *args, **kwargs): return "" + (await coro(*args, **kwargs)) + "" +def asyncio_run(awaitable): + """asyncio.run for Python 3.5""" + try: + from asyncio import run + aio_run = run + except ImportError: + # Python 3.5 + from asyncio import get_event_loop + return get_event_loop().run_until_complete(awaitable) + else: + return aio_run(awaitable) + + @decorator def coro_to_func(coro, *args, **kw): - return get_event_loop().run_until_complete(coro(*args, **kw)) + return asyncio_run(coro(*args, **kw)) class CoroutineTestCase(unittest.TestCase): @@ -39,7 +51,7 @@ def test_before_after(self): async def coro(x): return x self.assertTrue(inspect.iscoroutinefunction(coro)) - out = get_event_loop().run_until_complete(coro('x')) + out = asyncio_run(coro('x')) self.assertEqual(out, 'x') def test_coro_to_func(self):