-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_with_timer.py
More file actions
43 lines (32 loc) · 1.42 KB
/
test_with_timer.py
File metadata and controls
43 lines (32 loc) · 1.42 KB
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
43
from test.pytestutils import before
from codeguru_profiler_agent.metrics.with_timer import with_timer
from codeguru_profiler_agent.metrics.timer import Timer
class TargetClass:
def __init__(self):
self.timer = Timer()
@with_timer(metric_name="test-foo-wall", measurement="wall-clock-time")
def foo_wall(self):
return
@with_timer(metric_name="test-foo-cpu", measurement="cpu-time")
def foo_cpu(self):
# Run something to make sure the cpu clock does tick (https://bugs.python.org/issue37859)
sum_x = 0
for i in range(10000000):
sum_x += i
return
class TestWithTimer:
@before
def before(self):
self.test_class = TargetClass()
def test_it_times_wall_time(self):
self.test_class.foo_wall()
assert (self.test_class.timer.metrics["test-foo-wall"].counter == 1)
assert (self.test_class.timer.metrics["test-foo-wall"].max > 0)
assert (self.test_class.timer.metrics["test-foo-wall"].total ==
self.test_class.timer.metrics["test-foo-wall"].max)
def test_it_times_cpu_time(self):
self.test_class.foo_cpu()
assert (self.test_class.timer.metrics["test-foo-cpu"].counter == 1)
assert (self.test_class.timer.metrics["test-foo-cpu"].max > 0)
assert (self.test_class.timer.metrics["test-foo-cpu"].total ==
self.test_class.timer.metrics["test-foo-cpu"].max)