Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using wrapt instead of wraps, refractoring only use one wrapped function, change Exception, adding powerful eval option #41

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
c4691c7
Update timeout_decorator.py - now using wrapt
bitranox Nov 3, 2017
7ce5516
Update timeout_decorator.py
bitranox Nov 3, 2017
2714ec4
Update timeout_decorator.py
bitranox Nov 3, 2017
9c54676
Update test_timeout_decorator.py
bitranox Nov 3, 2017
689afe0
Update test_timeout_decorator.py
bitranox Nov 3, 2017
d4d0c5c
Create requirements.txt
bitranox Nov 3, 2017
e36ee7b
Create requirements.txt
bitranox Nov 3, 2017
92a61e3
Update .travis.yml
bitranox Nov 3, 2017
e8c539f
Delete requirements.txt
bitranox Nov 3, 2017
79096c3
Update .travis.yml
bitranox Nov 3, 2017
569251f
Update timeout_decorator.py
bitranox Nov 3, 2017
0c2db0a
Update test_timeout_decorator.py
bitranox Nov 3, 2017
16ca9f8
Update test_timeout_decorator.py
bitranox Nov 3, 2017
0194d24
Update timeout_decorator.py
bitranox Nov 3, 2017
fdbf01b
Update test_timeout_decorator.py
bitranox Nov 3, 2017
18be4a0
Update timeout_decorator.py
bitranox Nov 3, 2017
423fbb5
Update test_timeout_decorator.py
bitranox Nov 3, 2017
493f6f8
Update test_timeout_decorator.py
bitranox Nov 3, 2017
5b93d6b
Update timeout_decorator.py
bitranox Nov 3, 2017
84c07e1
Create requirements-testing.txt
bitranox Nov 3, 2017
7f53db3
Create requirements.txt
bitranox Nov 3, 2017
b339b9b
Create requirements-testing.txt
bitranox Nov 3, 2017
644be60
Update tox.ini
bitranox Nov 3, 2017
fb21932
Update setup.py
bitranox Nov 3, 2017
b41d28f
Delete requirements-testing.txt
bitranox Nov 3, 2017
3f61a34
Delete requirements.txt
bitranox Nov 3, 2017
b9f1764
Delete requirements-testing.txt
bitranox Nov 3, 2017
6378405
Delete requirements.txt
bitranox Nov 3, 2017
077f0a9
Update __init__.py
bitranox Nov 3, 2017
7ab0afd
Update timeout_decorator.py
bitranox Nov 3, 2017
e767633
Update tox.ini
bitranox Nov 3, 2017
d16e533
Update tox.ini
bitranox Nov 3, 2017
1f5bee6
Update timeout_decorator.py
bitranox Nov 3, 2017
133d6d1
Update timeout_decorator.py
bitranox Nov 3, 2017
7d582ff
Update test_timeout_decorator.py
bitranox Nov 3, 2017
65e0067
Update tox.ini
bitranox Nov 3, 2017
97a7391
Update timeout_decorator.py
bitranox Nov 3, 2017
588a38a
Update timeout_decorator.py
bitranox Nov 3, 2017
38634d9
Update test_timeout_decorator.py
bitranox Nov 3, 2017
0a10327
Update timeout_decorator.py
bitranox Nov 3, 2017
a3d723b
Update test_timeout_decorator.py
bitranox Nov 3, 2017
9bcc713
Update timeout_decorator.py
bitranox Nov 3, 2017
2c7e1ba
Update test_timeout_decorator.py
bitranox Nov 3, 2017
4de8277
Update timeout_decorator.py
bitranox Nov 3, 2017
3e9157f
Update timeout_decorator.py
bitranox Nov 3, 2017
2cf1bb6
Update timeout_decorator.py
bitranox Nov 4, 2017
3135b36
Update .travis.yml
bitranox Nov 4, 2017
100c1a7
Update timeout_decorator.py
bitranox Nov 4, 2017
b688543
Update test_timeout_decorator.py
bitranox Nov 4, 2017
94d4b47
Update timeout_decorator.py
bitranox Nov 4, 2017
151992f
Update test_timeout_decorator.py
bitranox Nov 4, 2017
ed0d34d
Update test_timeout_decorator.py
bitranox Nov 4, 2017
d5514c4
Update test_timeout_decorator.py
bitranox Nov 4, 2017
7790105
Update test_timeout_decorator.py
bitranox Nov 4, 2017
cb67fba
Update test_timeout_decorator.py
bitranox Nov 4, 2017
1186c37
Update timeout_decorator.py
bitranox Nov 4, 2017
4aa0590
Update test_timeout_decorator.py
bitranox Nov 4, 2017
719dcb2
Update setup.py
bitranox Nov 4, 2017
6ace58a
Update Makefile
bitranox Nov 4, 2017
728fc9c
Create requirements.txt
bitranox Nov 4, 2017
2f3dec5
Update timeout_decorator.py
bitranox Nov 5, 2017
4bc09f3
Update timeout_decorator.py
bitranox Nov 5, 2017
7461061
Update timeout_decorator.py
bitranox Nov 5, 2017
7e25e1a
Update timeout_decorator.py
bitranox Nov 5, 2017
04dec99
Update timeout_decorator.py
bitranox Nov 5, 2017
99c8e3a
Update timeout_decorator.py
bitranox Nov 5, 2017
5d84e62
Update timeout_decorator.py
bitranox Nov 5, 2017
606acde
Update README.rst
bitranox Nov 9, 2017
6a39ee3
Update timeout_decorator.py
bitranox Nov 10, 2017
8fc2834
Update test_timeout_decorator.py
bitranox Nov 10, 2017
773844d
Update timeout_decorator.py
bitranox Nov 10, 2017
6b6a330
Update .travis.yml
bitranox Sep 11, 2018
83e6f09
Update .travis.yml
bitranox Sep 11, 2018
da1a85e
Update timeout_decorator.py
bitranox Sep 13, 2018
a311866
Update timeout_decorator.py
bitranox Sep 13, 2018
9908a00
Update timeout_decorator.py
bitranox Sep 13, 2018
8101c74
Update timeout_decorator.py
bitranox Sep 13, 2018
e5a8966
Update test_timeout_decorator.py
bitranox Sep 13, 2018
fab625a
Update test_timeout_decorator.py
bitranox Sep 13, 2018
1620b8c
Update .travis.yml
bitranox Sep 13, 2018
45289e5
Update requirements.txt
bitranox Sep 13, 2018
1ffc2be
Update tox.ini
bitranox Sep 13, 2018
018ff70
Update setup.py
bitranox Sep 13, 2018
0eaf765
Update README.rst
bitranox Sep 13, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ sudo: false
python:
- '2.6'
- '2.7'
- '3.2'
- '3.3'
- '3.4'
- '3.5'
- '3.6'
- '3.7-dev'
- 'pypy'
- 'pypy3'
install:
- if [[ $TRAVIS_PYTHON_VERSION == 3.2 ]]; then pip install -U "virtualenv<14.0.0"; fi
- pip install python-coveralls tox tox-travis
- pip install tox tox-travis dill multiprocess wrapt pytest-cov coverage codecov
script: tox --recreate

after_success:
- pip install -e .
- py.test --cov=timeout_decorator --cov-report=term-missing tests
- coveralls
deploy:
provider: pypi
user: png
password:
secure: ZXoq3kgfu+IICjhhmQZr0s0xE6bvWzH04GjdE/VL4BxdDdGI4fHEwudGEjzLXJbt2d09vNOO67Nqam+MwPWtq+WZEP69g/Fhyy4kbkuUl/CMeqashQzU/N+3lwv97Y2qvzTUwDnSoz4zyBFu67SSrovKruFsYaiH00bwvWcvLa0=
on:
python: 2.7
- py.test --cov=./
- codecov

# deploy:
# provider: pypi
# user: png
# password:
# secure: ZXoq3kgfu+IICjhhmQZr0s0xE6bvWzH04GjdE/VL4BxdDdGI4fHEwudGEjzLXJbt2d09vNOO67Nqam+MwPWtq+WZEP69g/Fhyy4kbkuUl/CMeqashQzU/N+3lwv97Y2qvzTUwDnSoz4zyBFu67SSrovKruFsYaiH00bwvWcvLa0=
# on:
# python: 2.7
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ venv:

# install all needed for development
develop: venv
venv/bin/pip install -e . -r requirements-testing.txt tox
venv/bin/pip install -e . -r requirements.txt tox

# clean the development envrironment
clean:
Expand Down
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Timeout decorator
=================

|Build Status| |Pypi Status| |Coveralls Status|
|Build Status| |Pypi Status| |Codecov Status|

Installation
------------
Expand All @@ -28,10 +28,10 @@ Usage

@timeout_decorator.timeout(5)
def mytest():
print "Start"
print("Start")
for i in range(1,10):
time.sleep(1)
print "%d seconds have passed" % i
print("{} seconds have passed".format(i))

if __name__ == '__main__':
mytest()
Expand All @@ -45,10 +45,10 @@ Specify an alternate exception to raise on timeout:

@timeout_decorator.timeout(5, timeout_exception=StopIteration)
def mytest():
print "Start"
print("Start")
for i in range(1,10):
time.sleep(1)
print "%d seconds have passed" % i
print("{} seconds have passed".format(i))

if __name__ == '__main__':
mytest()
Expand All @@ -73,7 +73,7 @@ case - by using multiprocessing. To use it, just pass
print "Start"
for i in range(1,10):
time.sleep(1)
print "%d seconds have passed" % i
print("{} seconds have passed".format(i))

if __name__ == '__main__':
mytest()
Expand Down Expand Up @@ -107,5 +107,5 @@ See `License file <https://github.com/pnpnpn/timeout-decorator/blob/master/LICEN
:target: https://travis-ci.org/pnpnpn/timeout-decorator
.. |Pypi Status| image:: https://badge.fury.io/py/timeout-decorator.svg
:target: https://badge.fury.io/py/timeout-decorator
.. |Coveralls Status| image:: https://coveralls.io/repos/pnpnpn/timeout-decorator/badge.png?branch=master
:target: https://coveralls.io/r/pnpnpn/timeout-decorator
.. |Codecov Status| image:: https://codecov.io/gh/bitranox/wrapt-timeout-decorator/branch/master/graph/badge.svg
:target: https://codecov.io/gh/bitranox/wrapt-timeout-decorator
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dill
multiprocess
wrapt
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
long_description=long_description,
author='Patrick Ng',
author_email='pn.appdev@gmail.com',
url='https://github.com/pnpnpn/timeout-decorator',
url='https://github.com/bitranox/timeout-decorator',
packages=['timeout_decorator'],
install_requires=[],
install_requires=['dill', 'multiprocess', 'wrapt'],
classifiers=CLASSIFIERS)
64 changes: 50 additions & 14 deletions tests/test_timeout_decorator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Timeout decorator tests."""
from timeout_decorator import timeout
import pytest
import sys
import time
from dill import PicklingError

import pytest

from timeout_decorator import timeout, TimeoutError
if sys.version_info < (3, 3): # there is no TimeoutError < Python 3.3
TimeoutError = AssertionError


@pytest.fixture(params=[False, True])
Expand All @@ -20,29 +24,38 @@ def f():
f()


def test_timeout_class_method(use_signals):
def test_timeout_class_method_use_signals():
class c():
@timeout(1, use_signals=use_signals)
@timeout(1, use_signals=True)
def f(self):
time.sleep(2)
with pytest.raises(TimeoutError):
c().f()


def test_timeout_class_method_dont_use_signals():
class c():
@timeout(1, use_signals=False)
def f(self):
time.sleep(2)
with pytest.raises(PicklingError):
c().f()


def test_timeout_kwargs(use_signals):
@timeout(3, use_signals=use_signals)
def f():
time.sleep(2)
with pytest.raises(TimeoutError):
f(timeout=1)
f(dec_timeout=1)


def test_timeout_alternate_exception(use_signals):
@timeout(3, use_signals=use_signals, timeout_exception=StopIteration)
def f():
time.sleep(2)
with pytest.raises(StopIteration):
f(timeout=1)
f(dec_timeout=1)


def test_timeout_no_seconds(use_signals):
Expand All @@ -61,44 +74,67 @@ def f():


def test_timeout_ok(use_signals):
@timeout(seconds=2, use_signals=use_signals)
@timeout(dec_timeout=2, use_signals=use_signals)
def f():
time.sleep(1)
f()


def test_function_name(use_signals):
@timeout(seconds=2, use_signals=use_signals)
@timeout(dec_timeout=2, use_signals=use_signals)
def func_name():
pass

func_name()
assert func_name.__name__ == 'func_name'


def test_timeout_pickle_error():
"""Test that when a pickle error occurs a timeout error is raised."""
@timeout(seconds=1, use_signals=False)
"""Test that when a pickle error occurs a timeout error is raised"""
# codecov start ignore
@timeout(dec_timeout=1, use_signals=False)
def f():
time.sleep(0.1)

class Test(object):
pass
return Test()
with pytest.raises(TimeoutError):
# codecov end ignore
with pytest.raises(PicklingError):
f()


def test_timeout_custom_exception_message():
@timeout(seconds=1, exception_message="Custom fail message")
@timeout(dec_timeout=1, exception_message="Custom fail message")
def f():
time.sleep(2)
with pytest.raises(TimeoutError, match="Custom fail message"):
f()


def test_timeout_default_exception_message():
@timeout(seconds=1)
@timeout(dec_timeout=1)
def f():
time.sleep(2)
with pytest.raises(TimeoutError, match="Timed Out"):
with pytest.raises(TimeoutError, match="Function f timed out after 1 seconds"):
f()


def test_timeout_eval(use_signals):
""" Test Eval """
@timeout(dec_timeout='args[0] * 2', use_signals=use_signals, dec_allow_eval=True)
def f(x):
time.sleep(0.4)
f(0.3)
with pytest.raises(TimeoutError):
f(0.1)


def test_exception(use_signals):
""" Test Exception """
@timeout(0.4, use_signals=use_signals)
def f():
raise AssertionError

with pytest.raises(AssertionError):
f()
1 change: 0 additions & 1 deletion timeout_decorator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from .timeout_decorator import timeout
from .timeout_decorator import TimeoutError

__title__ = 'timeout_decorator'
__version__ = '0.4.0'
Loading