def test_result(profiler): __, cpu_time, wall_time = profiler.result() assert cpu_time == wall_time == 0.0 with profiler: spin(0.1) __, cpu_time, wall_time = profiler.result() assert cpu_time > 0.0 assert wall_time >= 0.1
def test_tracing_sampler_does_not_sample_too_often(): # pytest-cov cannot detect a callback function registered by # :func:`sys.setprofile`. class fake_profiler(object): samples = [] @classmethod def sample(cls, frame): cls.samples.append(frame) @classmethod def count_and_clear_samples(cls): count = len(cls.samples) del cls.samples[:] return count sampler = TracingSampler(0.1) sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 1 sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 0 spin(0.5) sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 1
def spin_500ms(): spin(0.5)
def spin_100ms(): spin(0.1)