def test_set_time_limit(self): def my_function(): return 100 x = set_time_limit(my_function, 500) self.assertEquals(x, 100)
def test_set_time_limit_of_long_function(self): def my_function(): time.sleep(1) return 100 with self.assertRaises(TimeLimitExceededError): set_time_limit(my_function, 500)
#!/usr/bin/env python from useless import set_time_limit, TimeLimitExceededError import time __author__ = 'Ronie Martinez' def my_function(): time.sleep(1) print "Hello world!" # if time limit is enough set_time_limit(my_function, 1500) # if time limit is not enough, raises TimeLimitExceededError try: set_time_limit(my_function, 500) except TimeLimitExceededError as e: print e.message