-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_timer.py
More file actions
42 lines (34 loc) · 990 Bytes
/
test_timer.py
File metadata and controls
42 lines (34 loc) · 990 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
32
33
34
35
36
37
38
39
40
41
42
"""Tests for utils/timer.py"""
import time
import pytest
from utils.timer import Timer, timer
class TestTimerContextManager:
def test_elapsed_is_positive(self):
with Timer("test", log=False) as t:
time.sleep(0.05)
assert t.elapsed >= 0.04
def test_elapsed_accessible_after_block(self):
t = Timer(log=False)
with t:
pass
assert isinstance(t.elapsed, float)
def test_no_log_does_not_raise(self):
with Timer("silent", log=False):
pass
class TestTimerDecorator:
def test_return_value_preserved(self):
@timer
def fn():
return 42
assert fn() == 42
def test_args_passed_through(self):
@timer
def add(a, b):
return a + b
assert add(2, 3) == 5
def test_exception_propagates(self):
@timer
def boom():
raise ValueError("err")
with pytest.raises(ValueError):
boom()