Skip to content

Commit

Permalink
Added tests for timeout decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJokr committed Jun 11, 2016
1 parent 9678dc5 commit f5937a0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/test_timeout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# coding: utf-8

import unittest

import time
import signal

from vmbot.helpers.exceptions import TimeoutError

from vmbot.helpers.decorators import timeout


@timeout(1)
def timeout_success():
return True


@timeout(1)
def timeout_fail():
time.sleep(3)
return True


@timeout(1, "TestException")
def timeout_msg():
time.sleep(3)
return True


@unittest.skipUnless(hasattr(signal, "alarm"), "OS doesn't support SIGALRM")
class TestFormat(unittest.TestCase):
def test_timeout(self):
self.assertRaises(TimeoutError, timeout_fail)

def test_timeout_notimeout(self):
self.assertTrue(timeout_success())

def test_timeout_msg(self):
self.assertRaisesRegexp(TimeoutError, "TestException", timeout_msg)


if __name__ == "__main__":
unittest.main()

0 comments on commit f5937a0

Please sign in to comment.