diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2019-10-17 19:07:18 +0300 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2019-10-17 20:03:36 +0300 |
commit | f436fe8e72e3e58b7957821b8be24af040fb8bbc (patch) | |
tree | b8afb465796cc02aba26020b52d8306532233144 | |
parent | fe987a283d2bc96ea126861a220eb424182436b0 (diff) | |
download | apscheduler-f436fe8e72e3e58b7957821b8be24af040fb8bbc.tar.gz |
Adapted the code for the 3.x branch
-rw-r--r-- | apscheduler/executors/asyncio.py | 2 | ||||
-rw-r--r-- | apscheduler/util.py | 8 | ||||
-rw-r--r-- | tests/test_util.py | 23 | ||||
-rw-r--r-- | tests/test_util_py35.py | 22 |
4 files changed, 29 insertions, 26 deletions
diff --git a/apscheduler/executors/asyncio.py b/apscheduler/executors/asyncio.py index 2b8c619..06fc7f9 100644 --- a/apscheduler/executors/asyncio.py +++ b/apscheduler/executors/asyncio.py @@ -6,10 +6,8 @@ from apscheduler.executors.base import BaseExecutor, run_job from apscheduler.util import iscoroutinefunction_partial try: - from asyncio import iscoroutinefunction from apscheduler.executors.base_py3 import run_coroutine_job except ImportError: - from trollius import iscoroutinefunction run_coroutine_job = None diff --git a/apscheduler/util.py b/apscheduler/util.py index 4b54309..a596ddf 100644 --- a/apscheduler/util.py +++ b/apscheduler/util.py @@ -6,7 +6,6 @@ from datetime import date, datetime, time, timedelta, tzinfo from calendar import timegm from functools import partial from inspect import isclass, ismethod -import asyncio import re from pytz import timezone, utc, FixedOffset @@ -22,6 +21,11 @@ try: except ImportError: TIMEOUT_MAX = 4294967 # Maximum value accepted by Event.wait() on Windows +try: + from asyncio import iscoroutinefunction +except ImportError: + from trollius import iscoroutinefunction + __all__ = ('asint', 'asbool', 'astimezone', 'convert_to_datetime', 'datetime_to_utc_timestamp', 'utc_timestamp_to_datetime', 'timedelta_seconds', 'datetime_ceil', 'get_callable_name', 'obj_to_ref', 'ref_to_obj', 'maybe_ref', 'repr_escape', 'check_callable_args', @@ -418,4 +422,4 @@ def iscoroutinefunction_partial(f): # The asyncio version of iscoroutinefunction includes testing for @coroutine # decorations vs. the inspect version which does not. - return asyncio.iscoroutinefunction(f) + return iscoroutinefunction(f) diff --git a/tests/test_util.py b/tests/test_util.py index 30ce06d..f1f07e6 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -13,9 +13,7 @@ from apscheduler.job import Job from apscheduler.util import ( asint, asbool, astimezone, convert_to_datetime, datetime_to_utc_timestamp, utc_timestamp_to_datetime, timedelta_seconds, datetime_ceil, get_callable_name, obj_to_ref, - ref_to_obj, maybe_ref, check_callable_args, datetime_repr, repr_escape, - iscoroutinefunction_partial -) + ref_to_obj, maybe_ref, check_callable_args, datetime_repr, repr_escape) from tests.conftest import minpython, maxpython try: @@ -357,22 +355,3 @@ class TestCheckCallableArgs(object): exc = pytest.raises(ValueError, check_callable_args, func, [1], {}) assert str(exc.value) == ('The following keyword-only arguments have not been supplied in ' 'kwargs: y') - - -class TestIsCoroutineFunctionPartial(object): - @staticmethod - def not_a_coro(x): - pass - - @staticmethod - async def a_coro(x): - pass - - def test_non_coro(self): - assert not iscoroutinefunction_partial(self.not_a_coro) - - def test_coro(self): - assert iscoroutinefunction_partial(self.a_coro) - - def test_coro_partial(self): - assert iscoroutinefunction_partial(partial(self.a_coro, 1)) diff --git a/tests/test_util_py35.py b/tests/test_util_py35.py new file mode 100644 index 0000000..e3d35cd --- /dev/null +++ b/tests/test_util_py35.py @@ -0,0 +1,22 @@ +from functools import partial + +from apscheduler.util import iscoroutinefunction_partial + + +class TestIsCoroutineFunctionPartial: + @staticmethod + def not_a_coro(x): + pass + + @staticmethod + async def a_coro(x): + pass + + def test_non_coro(self): + assert not iscoroutinefunction_partial(self.not_a_coro) + + def test_coro(self): + assert iscoroutinefunction_partial(self.a_coro) + + def test_coro_partial(self): + assert iscoroutinefunction_partial(partial(self.a_coro, 1)) |