[Python-modules-commits] [python-async-timeout] 01/03: Import python-async-timeout_2.0.0.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Mon Nov 13 20:26:37 UTC 2017
This is an automated email from the git hooks/post-receive script.
piotr pushed a commit to branch master
in repository python-async-timeout.
commit a5f2970dc1270f0db3900ea03aeaeec65c5d250c
Author: Piotr Ożarowski <piotr at debian.org>
Date: Mon Nov 13 21:23:06 2017 +0100
Import python-async-timeout_2.0.0.orig.tar.gz
---
CHANGES.rst | 9 +++++++++
PKG-INFO | 11 ++++++++++-
async_timeout.egg-info/PKG-INFO | 11 ++++++++++-
async_timeout/__init__.py | 28 ++++++++++++++++++----------
tests/test_py35.py | 23 +++++++++++++++++++++++
tests/test_timeout.py | 40 +++++++++++++++++++++++++++++-----------
6 files changed, 99 insertions(+), 23 deletions(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index bfe8cfa..be6a243 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,15 @@
CHANGES
=======
+2.0.0 (2017-10-09)
+------------------
+
+* Changed `timeout <= 0` behaviour
+
+ * Backward incompatibility change, prior this version `0` was
+ shortcut for `None`
+ * when timeout <= 0 `TimeoutError` raised faster
+
1.4.0 (2017-09-09)
------------------
diff --git a/PKG-INFO b/PKG-INFO
index b8459fa..997aa91 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: async-timeout
-Version: 1.4.0
+Version: 2.0.0
Summary: Timeout context manager for asyncio programs
Home-page: https://github.com/aio-libs/async_timeout/
Author: Andrew Svetlov
@@ -80,6 +80,15 @@ Description: async-timeout
CHANGES
=======
+ 2.0.0 (2017-10-09)
+ ------------------
+
+ * Changed `timeout <= 0` behaviour
+
+ * Backward incompatibility change, prior this version `0` was
+ shortcut for `None`
+ * when timeout <= 0 `TimeoutError` raised faster
+
1.4.0 (2017-09-09)
------------------
diff --git a/async_timeout.egg-info/PKG-INFO b/async_timeout.egg-info/PKG-INFO
index b8459fa..997aa91 100644
--- a/async_timeout.egg-info/PKG-INFO
+++ b/async_timeout.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: async-timeout
-Version: 1.4.0
+Version: 2.0.0
Summary: Timeout context manager for asyncio programs
Home-page: https://github.com/aio-libs/async_timeout/
Author: Andrew Svetlov
@@ -80,6 +80,15 @@ Description: async-timeout
CHANGES
=======
+ 2.0.0 (2017-10-09)
+ ------------------
+
+ * Changed `timeout <= 0` behaviour
+
+ * Backward incompatibility change, prior this version `0` was
+ shortcut for `None`
+ * when timeout <= 0 `TimeoutError` raised faster
+
1.4.0 (2017-09-09)
------------------
diff --git a/async_timeout/__init__.py b/async_timeout/__init__.py
index 8829f8e..5a560f8 100644
--- a/async_timeout/__init__.py
+++ b/async_timeout/__init__.py
@@ -1,7 +1,7 @@
import asyncio
-__version__ = '1.4.0'
+__version__ = '2.0.0'
class timeout:
@@ -19,8 +19,6 @@ class timeout:
loop - asyncio compatible event loop
"""
def __init__(self, timeout, *, loop=None):
- if timeout is not None and timeout == 0:
- timeout = None
self._timeout = timeout
if loop is None:
loop = asyncio.get_event_loop()
@@ -56,13 +54,23 @@ class timeout:
return None
def _do_enter(self):
- if self._timeout is not None:
- self._task = current_task(self._loop)
- if self._task is None:
- raise RuntimeError('Timeout context manager should be used '
- 'inside a task')
- self._cancel_at = self._loop.time() + self._timeout
- self._cancel_handler = self._loop.call_at(self._cancel_at, self._cancel_task)
+ # Support Tornado 5- without timeout
+ # Details: https://github.com/python/asyncio/issues/392
+ if self._timeout is None:
+ return self
+
+ self._task = current_task(self._loop)
+ if self._task is None:
+ raise RuntimeError('Timeout context manager should be used '
+ 'inside a task')
+
+ if self._timeout <= 0:
+ self._loop.call_soon(self._cancel_task)
+ return self
+
+ self._cancel_at = self._loop.time() + self._timeout
+ self._cancel_handler = self._loop.call_at(
+ self._cancel_at, self._cancel_task)
return self
def _do_exit(self, exc_type):
diff --git a/tests/test_py35.py b/tests/test_py35.py
index 1022dc9..d3410db 100644
--- a/tests/test_py35.py
+++ b/tests/test_py35.py
@@ -16,3 +16,26 @@ async def test_async_no_timeout(loop):
async with timeout(1, loop=loop) as cm:
await asyncio.sleep(0, loop=loop)
assert not cm.expired
+
+
+async def test_async_zero(loop):
+ with pytest.raises(asyncio.TimeoutError):
+ async with timeout(0, loop=loop) as cm:
+ await asyncio.sleep(10, loop=loop)
+ assert cm.expired
+
+
+async def test_async_zero_coro_not_started(loop):
+ coro_started = False
+
+ async def coro():
+ nonlocal coro_started
+ coro_started = True
+
+ with pytest.raises(asyncio.TimeoutError):
+ async with timeout(0, loop=loop) as cm:
+ await asyncio.sleep(0, loop=loop)
+ await coro()
+
+ assert cm.expired
+ assert coro_started is False
diff --git a/tests/test_timeout.py b/tests/test_timeout.py
index 7160bfe..04e86f0 100644
--- a/tests/test_timeout.py
+++ b/tests/test_timeout.py
@@ -80,19 +80,36 @@ def test_timeout_disable(loop):
assert 0.09 < dt < 0.13, dt
+def test_timeout_is_none_no_task(loop):
+ with timeout(None, loop=loop) as cm:
+ assert cm._task is None
+
+
+ at asyncio.coroutine
+def test_timeout_enable_zero(loop):
+ with pytest.raises(asyncio.TimeoutError):
+ with timeout(0, loop=loop) as cm:
+ yield from asyncio.sleep(0.1, loop=loop)
+
+ assert cm.expired
+
+
@asyncio.coroutine
-def test_timeout_disable_zero(loop):
+def test_timeout_enable_zero_coro_not_started(loop):
+ coro_started = False
+
@asyncio.coroutine
- def long_running_task():
- yield from asyncio.sleep(0.1, loop=loop)
- return 'done'
+ def coro():
+ nonlocal coro_started
+ coro_started = True
- t0 = loop.time()
- with timeout(0, loop=loop):
- resp = yield from long_running_task()
- assert resp == 'done'
- dt = loop.time() - t0
- assert 0.09 < dt < 0.13, dt
+ with pytest.raises(asyncio.TimeoutError):
+ with timeout(0, loop=loop) as cm:
+ yield from asyncio.sleep(0, loop=loop)
+ yield from coro()
+
+ assert cm.expired
+ assert coro_started is False
@asyncio.coroutine
@@ -104,7 +121,7 @@ def test_timeout_not_relevant_exception(loop):
@asyncio.coroutine
-def test_timeout_canceled_error_is_converted_to_timeout(loop):
+def test_timeout_canceled_error_is_not_converted_to_timeout(loop):
yield from asyncio.sleep(0, loop=loop)
with pytest.raises(asyncio.CancelledError):
with timeout(0.001, loop=loop):
@@ -228,6 +245,7 @@ def test_timeout_inner_other_error(loop):
raise RuntimeError
assert not cm.expired
+
@asyncio.coroutine
def test_timeout_remaining(loop):
with timeout(None, loop=loop) as cm:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-async-timeout.git
More information about the Python-modules-commits
mailing list