2019-09-11 17:39:28 +08:00
|
|
|
from time import time
|
|
|
|
|
|
|
|
|
|
|
|
class TestTimer(object):
|
|
|
|
def __init__(self, timeout):
|
|
|
|
self.timeout_time = TestTimer.get_timeout_time(timeout)
|
|
|
|
self.start_time = time()
|
|
|
|
|
2019-10-01 15:42:51 +08:00
|
|
|
def is_timed_out(self):
|
2019-09-11 17:39:28 +08:00
|
|
|
return time() > self.timeout_time
|
|
|
|
|
|
|
|
def get_time_taken(self):
|
|
|
|
return time() - self.start_time
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_timeout_time(timeout):
|
|
|
|
return time() + timeout
|