[Python-modules-commits] [python-async-timeout] 01/04: Import python-async-timeout_1.4.0.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Fri Sep 29 09:05:10 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 5c96aee6dd25e93a22a6e332664005862ad63b16
Author: Piotr Ożarowski <piotr at debian.org>
Date: Fri Sep 29 11:01:22 2017 +0200
Import python-async-timeout_1.4.0.orig.tar.gz
---
CHANGES.rst | 20 ++++++++++++++++
PKG-INFO | 49 +++++++++++++++++++++++++++++++++++---
README.rst | 27 +++++++++++++++++++--
async_timeout.egg-info/PKG-INFO | 49 +++++++++++++++++++++++++++++++++++---
async_timeout.egg-info/SOURCES.txt | 2 ++
async_timeout/__init__.py | 39 +++++++++++++++++++++++++-----
setup.cfg | 4 ++--
setup.py | 2 --
tests/conftest.py | 7 ++++++
tests/test_py35.py | 18 ++++++++++++++
tests/test_timeout.py | 48 +++++++++++++++++++++++++++++++++----
11 files changed, 243 insertions(+), 22 deletions(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index 2d495f5..bfe8cfa 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,26 @@
CHANGES
=======
+1.4.0 (2017-09-09)
+------------------
+
+* Implement `remaining` property (#20)
+
+ * If timeout is not started yet or started unconstrained:
+ `remaining` is `None`
+ * If timeout is expired: `remaining` is `0.0`
+ * All others: roughly amount of time before `TimeoutError` is triggered
+
+1.3.0 (2017-08-23)
+------------------
+
+* Don't suppress nested exception on timeout. Exception context points
+ on cancelled line with suspended `await` (#13)
+
+* Introduce `.timeout` property (#16)
+
+* Add methods for using as async context manager (#9)
+
1.2.1 (2017-05-02)
------------------
diff --git a/PKG-INFO b/PKG-INFO
index 031f127..b8459fa 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: async-timeout
-Version: 1.2.1
+Version: 1.4.0
Summary: Timeout context manager for asyncio programs
Home-page: https://github.com/aio-libs/async_timeout/
Author: Andrew Svetlov
@@ -8,6 +8,15 @@ Author-email: andrew.svetlov at gmail.com
License: Apache 2
Description: async-timeout
=============
+ .. image:: https://travis-ci.org/aio-libs/async-timeout.svg?branch=master
+ :target: https://travis-ci.org/aio-libs/async-timeout
+ .. image:: https://codecov.io/gh/aio-libs/async-timeout/branch/master/graph/badge.svg
+ :target: https://codecov.io/gh/aio-libs/async-timeout
+ .. image:: https://img.shields.io/pypi/v/async-timeout.svg
+ :target: https://pypi.python.org/pypi/async-timeout
+ .. image:: https://badges.gitter.im/Join%20Chat.svg
+ :target: https://gitter.im/aio-libs/Lobby
+ :alt: Chat on Gitter
asyncio-compatible timeout context manager.
@@ -24,8 +33,8 @@ Description: async-timeout
The ``timeout(timeout, *, loop=None)`` call returns a context manager
that cancels a block on *timeout* expiring::
- with timeout(1.5):
- yield from inner()
+ async with timeout(1.5):
+ await inner()
1. If ``inner()`` is executed faster than in ``1.5`` seconds nothing
happens.
@@ -35,6 +44,20 @@ Description: async-timeout
*timeout* parameter could be ``None`` for skipping timeout functionality.
+
+ Context manager has ``.expired`` property for check if timeout happens
+ exactly in context manager::
+
+ async with timeout(1.5) as cm:
+ await inner()
+ print(cm.expired)
+
+ The property is ``True`` is ``inner()`` execution is cancelled by
+ timeout context manager.
+
+ If ``inner()`` call explicitly raises ``TimeoutError`` ``cm.expired``
+ is ``False``.
+
Installation
------------
@@ -57,6 +80,26 @@ Description: async-timeout
CHANGES
=======
+ 1.4.0 (2017-09-09)
+ ------------------
+
+ * Implement `remaining` property (#20)
+
+ * If timeout is not started yet or started unconstrained:
+ `remaining` is `None`
+ * If timeout is expired: `remaining` is `0.0`
+ * All others: roughly amount of time before `TimeoutError` is triggered
+
+ 1.3.0 (2017-08-23)
+ ------------------
+
+ * Don't suppress nested exception on timeout. Exception context points
+ on cancelled line with suspended `await` (#13)
+
+ * Introduce `.timeout` property (#16)
+
+ * Add methods for using as async context manager (#9)
+
1.2.1 (2017-05-02)
------------------
diff --git a/README.rst b/README.rst
index 0bf302b..85b4b52 100644
--- a/README.rst
+++ b/README.rst
@@ -1,5 +1,14 @@
async-timeout
=============
+.. image:: https://travis-ci.org/aio-libs/async-timeout.svg?branch=master
+ :target: https://travis-ci.org/aio-libs/async-timeout
+.. image:: https://codecov.io/gh/aio-libs/async-timeout/branch/master/graph/badge.svg
+ :target: https://codecov.io/gh/aio-libs/async-timeout
+.. image:: https://img.shields.io/pypi/v/async-timeout.svg
+ :target: https://pypi.python.org/pypi/async-timeout
+.. image:: https://badges.gitter.im/Join%20Chat.svg
+ :target: https://gitter.im/aio-libs/Lobby
+ :alt: Chat on Gitter
asyncio-compatible timeout context manager.
@@ -16,8 +25,8 @@ because ``timeout`` doesn't create a new task.
The ``timeout(timeout, *, loop=None)`` call returns a context manager
that cancels a block on *timeout* expiring::
- with timeout(1.5):
- yield from inner()
+ async with timeout(1.5):
+ await inner()
1. If ``inner()`` is executed faster than in ``1.5`` seconds nothing
happens.
@@ -27,6 +36,20 @@ that cancels a block on *timeout* expiring::
*timeout* parameter could be ``None`` for skipping timeout functionality.
+
+Context manager has ``.expired`` property for check if timeout happens
+exactly in context manager::
+
+ async with timeout(1.5) as cm:
+ await inner()
+ print(cm.expired)
+
+The property is ``True`` is ``inner()`` execution is cancelled by
+timeout context manager.
+
+If ``inner()`` call explicitly raises ``TimeoutError`` ``cm.expired``
+is ``False``.
+
Installation
------------
diff --git a/async_timeout.egg-info/PKG-INFO b/async_timeout.egg-info/PKG-INFO
index 031f127..b8459fa 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.2.1
+Version: 1.4.0
Summary: Timeout context manager for asyncio programs
Home-page: https://github.com/aio-libs/async_timeout/
Author: Andrew Svetlov
@@ -8,6 +8,15 @@ Author-email: andrew.svetlov at gmail.com
License: Apache 2
Description: async-timeout
=============
+ .. image:: https://travis-ci.org/aio-libs/async-timeout.svg?branch=master
+ :target: https://travis-ci.org/aio-libs/async-timeout
+ .. image:: https://codecov.io/gh/aio-libs/async-timeout/branch/master/graph/badge.svg
+ :target: https://codecov.io/gh/aio-libs/async-timeout
+ .. image:: https://img.shields.io/pypi/v/async-timeout.svg
+ :target: https://pypi.python.org/pypi/async-timeout
+ .. image:: https://badges.gitter.im/Join%20Chat.svg
+ :target: https://gitter.im/aio-libs/Lobby
+ :alt: Chat on Gitter
asyncio-compatible timeout context manager.
@@ -24,8 +33,8 @@ Description: async-timeout
The ``timeout(timeout, *, loop=None)`` call returns a context manager
that cancels a block on *timeout* expiring::
- with timeout(1.5):
- yield from inner()
+ async with timeout(1.5):
+ await inner()
1. If ``inner()`` is executed faster than in ``1.5`` seconds nothing
happens.
@@ -35,6 +44,20 @@ Description: async-timeout
*timeout* parameter could be ``None`` for skipping timeout functionality.
+
+ Context manager has ``.expired`` property for check if timeout happens
+ exactly in context manager::
+
+ async with timeout(1.5) as cm:
+ await inner()
+ print(cm.expired)
+
+ The property is ``True`` is ``inner()`` execution is cancelled by
+ timeout context manager.
+
+ If ``inner()`` call explicitly raises ``TimeoutError`` ``cm.expired``
+ is ``False``.
+
Installation
------------
@@ -57,6 +80,26 @@ Description: async-timeout
CHANGES
=======
+ 1.4.0 (2017-09-09)
+ ------------------
+
+ * Implement `remaining` property (#20)
+
+ * If timeout is not started yet or started unconstrained:
+ `remaining` is `None`
+ * If timeout is expired: `remaining` is `0.0`
+ * All others: roughly amount of time before `TimeoutError` is triggered
+
+ 1.3.0 (2017-08-23)
+ ------------------
+
+ * Don't suppress nested exception on timeout. Exception context points
+ on cancelled line with suspended `await` (#13)
+
+ * Introduce `.timeout` property (#16)
+
+ * Add methods for using as async context manager (#9)
+
1.2.1 (2017-05-02)
------------------
diff --git a/async_timeout.egg-info/SOURCES.txt b/async_timeout.egg-info/SOURCES.txt
index 07236f5..94f7b8e 100644
--- a/async_timeout.egg-info/SOURCES.txt
+++ b/async_timeout.egg-info/SOURCES.txt
@@ -9,4 +9,6 @@ async_timeout.egg-info/PKG-INFO
async_timeout.egg-info/SOURCES.txt
async_timeout.egg-info/dependency_links.txt
async_timeout.egg-info/top_level.txt
+tests/conftest.py
+tests/test_py35.py
tests/test_timeout.py
\ No newline at end of file
diff --git a/async_timeout/__init__.py b/async_timeout/__init__.py
index ee0817a..8829f8e 100644
--- a/async_timeout/__init__.py
+++ b/async_timeout/__init__.py
@@ -1,7 +1,7 @@
import asyncio
-__version__ = '1.2.1'
+__version__ = '1.4.0'
class timeout:
@@ -28,29 +28,56 @@ class timeout:
self._task = None
self._cancelled = False
self._cancel_handler = None
+ self._cancel_at = None
def __enter__(self):
+ return self._do_enter()
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ self._do_exit(exc_type)
+
+ @asyncio.coroutine
+ def __aenter__(self):
+ return self._do_enter()
+
+ @asyncio.coroutine
+ def __aexit__(self, exc_type, exc_val, exc_tb):
+ self._do_exit(exc_type)
+
+ @property
+ def expired(self):
+ return self._cancelled
+
+ @property
+ def remaining(self):
+ if self._cancel_at is not None:
+ return max(self._cancel_at - self._loop.time(), 0.0)
+ else:
+ 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_handler = self._loop.call_later(
- self._timeout, self._cancel_task)
+ self._cancel_at = self._loop.time() + self._timeout
+ self._cancel_handler = self._loop.call_at(self._cancel_at, self._cancel_task)
return self
- def __exit__(self, exc_type, exc_val, exc_tb):
+ def _do_exit(self, exc_type):
if exc_type is asyncio.CancelledError and self._cancelled:
self._cancel_handler = None
self._task = None
- raise asyncio.TimeoutError from None
+ raise asyncio.TimeoutError
if self._timeout is not None and self._cancel_handler is not None:
self._cancel_handler.cancel()
self._cancel_handler = None
self._task = None
def _cancel_task(self):
- self._cancelled = self._task.cancel()
+ self._task.cancel()
+ self._cancelled = True
def current_task(loop):
diff --git a/setup.cfg b/setup.cfg
index e4eba0b..eb9a041 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
-[aliases]
-test = pytest
+[tool:pytest]
+addopts = --cov=async_timeout --cov-report=term --cov-report=html --cov-branch
[egg_info]
tag_build =
diff --git a/setup.py b/setup.py
index 1dbdffa..9740a44 100644
--- a/setup.py
+++ b/setup.py
@@ -40,6 +40,4 @@ setup(name='async-timeout',
url='https://github.com/aio-libs/async_timeout/',
license='Apache 2',
packages=['async_timeout'],
- setup_requires=[],
- tests_require=['pytest', 'pytest_aiohttp', 'pytest-runner'],
include_package_data=False)
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..0ec19b3
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,7 @@
+import sys
+
+
+def pytest_ignore_collect(path, config):
+ if 'py35' in str(path):
+ if sys.version_info < (3, 5, 0):
+ return True
diff --git a/tests/test_py35.py b/tests/test_py35.py
new file mode 100644
index 0000000..1022dc9
--- /dev/null
+++ b/tests/test_py35.py
@@ -0,0 +1,18 @@
+import asyncio
+
+import pytest
+
+from async_timeout import timeout
+
+
+async def test_async_timeout(loop):
+ with pytest.raises(asyncio.TimeoutError):
+ async with timeout(0.01, loop=loop) as cm:
+ await asyncio.sleep(10, loop=loop)
+ assert cm.expired
+
+
+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
diff --git a/tests/test_timeout.py b/tests/test_timeout.py
index 3f7937b..7160bfe 100644
--- a/tests/test_timeout.py
+++ b/tests/test_timeout.py
@@ -199,9 +199,49 @@ def test_cancel_outer_coro(loop):
@asyncio.coroutine
def test_timeout_suppress_exception_chain(loop):
-
with pytest.raises(asyncio.TimeoutError) as ctx:
- with timeout(0.01, loop=loop) as t:
+ with timeout(0.01, loop=loop):
yield from asyncio.sleep(10, loop=loop)
- assert t._loop is loop
- assert ctx.value.__suppress_context__
+ assert not ctx.value.__suppress_context__
+
+
+ at asyncio.coroutine
+def test_timeout_expired(loop):
+ with pytest.raises(asyncio.TimeoutError):
+ with timeout(0.01, loop=loop) as cm:
+ yield from asyncio.sleep(10, loop=loop)
+ assert cm.expired
+
+
+ at asyncio.coroutine
+def test_timeout_inner_timeout_error(loop):
+ with pytest.raises(asyncio.TimeoutError):
+ with timeout(0.01, loop=loop) as cm:
+ raise asyncio.TimeoutError
+ assert not cm.expired
+
+
+ at asyncio.coroutine
+def test_timeout_inner_other_error(loop):
+ with pytest.raises(RuntimeError):
+ with timeout(0.01, loop=loop) as cm:
+ raise RuntimeError
+ assert not cm.expired
+
+ at asyncio.coroutine
+def test_timeout_remaining(loop):
+ with timeout(None, loop=loop) as cm:
+ assert cm.remaining is None
+
+ t = timeout(1.0, loop=loop)
+ assert t.remaining is None
+
+ with timeout(1.0, loop=loop) as cm:
+ yield from asyncio.sleep(0.1, loop=loop)
+ assert cm.remaining < 1.0
+
+ with pytest.raises(asyncio.TimeoutError):
+ with timeout(0.1, loop=loop) as cm:
+ yield from asyncio.sleep(0.5, loop=loop)
+
+ assert cm.remaining == 0.0
--
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