diff options
author | Jon Black <Jon.Black@radboudumc.nl> | 2014-10-09 09:06:01 +0200 |
---|---|---|
committer | Jon Black <Jon.Black@radboudumc.nl> | 2014-10-09 09:06:01 +0200 |
commit | 187ee34d9e0a571bcc7f9233208462634940f4c0 (patch) | |
tree | e389e11f5604d63855990564d01ca3f10e503421 /tests/test_timeout_decorator.py | |
parent | 3e1b4526f46c4147924e8a5800467ac717ab5f42 (diff) | |
download | timeout-decorator-187ee34d9e0a571bcc7f9233208462634940f4c0.tar.gz |
Add support for timeout in function kwargs
I've added support for passing the timeout in kwargs, which means the client
code can decide the timeout. This is useful for functions that take a timeout
argument.
I've also made the tests proper and added nosetests as a requirement.
Diffstat (limited to 'tests/test_timeout_decorator.py')
-rw-r--r-- | tests/test_timeout_decorator.py | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/tests/test_timeout_decorator.py b/tests/test_timeout_decorator.py index 35d0e3e..143dfc8 100644 --- a/tests/test_timeout_decorator.py +++ b/tests/test_timeout_decorator.py @@ -2,14 +2,38 @@ # -*- coding: utf-8 -*- import time -import timeout_decorator -@timeout_decorator.timeout(5) -def mytest(): - print "Start" - for i in range(1,10): - time.sleep(1) - print "%d seconds have passed" % i +from nose.tools import raises + +from timeout_decorator import timeout, TimeoutError + + +@raises(TimeoutError) +def test_timeout_decorator_arg(): + @timeout(1) + def f(): + time.sleep(2) + f() + -if __name__ == '__main__': - mytest() +@raises(TimeoutError) +def test_timeout_kwargs(): + @timeout() + def f(timeout): + time.sleep(2) + f(timeout=1) + + +@raises(ValueError) +def test_timeout_no_seconds(): + @timeout() + def f(timeout): + time.sleep(2) + f() + + +def test_timeout_ok(): + @timeout(seconds=2) + def f(): + time.sleep(1) + f() |