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
|
from typing import Any
from .util import parametrize_setstatprofile
class CallCounter:
def __init__(self) -> None:
self.count = 0
def __call__(self, *args: Any, **kwds: Any) -> Any:
self.count += 1
@parametrize_setstatprofile
def test_increment(setstatprofile):
time = 0.0
def fake_time():
return time
def fake_sleep(duration):
nonlocal time
time += duration
counter = CallCounter()
setstatprofile(counter, timer_func=fake_time, timer_type="timer_func")
for _ in range(100):
fake_sleep(1.0)
setstatprofile(None)
assert counter.count == 100
|