-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
31 lines (25 loc) · 820 Bytes
/
tests.py
File metadata and controls
31 lines (25 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from contextlib import redirect_stdout
from io import StringIO
import unittest
import utils
class TestTimeIt(unittest.TestCase):
def test_timer(self):
"""
Test to make sure that timeit returns the time it takes for the
method to run close enough to the time that it actually takes.
"""
import time
@utils.timeit
def time_me():
time.sleep(0.5)
str_out = StringIO()
with redirect_stdout(str_out):
start = time.time()
time_me()
end = time.time()
out = str_out.getvalue().split(" ")
time = float(out[-2])
#print("took %f while test said %f" % (end-start, time,))
self.assertAlmostEqual(time, end - start, places=3)
if __name__ == "__main__":
unittest.main()