Esempio n. 1
0
 def timer(self, *, clock, sleep) -> Timer:
     return Timer(
         self.interval,
         name='test',
         clock=clock,
         sleep=sleep,
     )
Esempio n. 2
0
async def test_Timer_real_run():
    i = 0
    async for sleep_time in Timer(0.1, sleep=asyncio.sleep):
        assert sleep_time == pytest.approx(0.1, 2e-1)
        if i > 10:
            break
        i += 1
Esempio n. 3
0
 def to_next_interval(self,
                      timer: Timer,
                      interval: Interval,
                      sleep_time: float = None,
                      yield_time: float = 0.1,
                      expected_new_interval: float = None) -> Interval:
     if sleep_time is None:
         sleep_time = interval.interval + 0.001
     if yield_time is None:
         yield_time = self.default_yield_s
     next_wakeup_time = interval.yield_time + self.default_yield_s
     next_yield_time = next_wakeup_time + sleep_time
     time_spent_sleeping = interval.yield_time - interval.wakeup_time
     drift = interval.interval - time_spent_sleeping
     if expected_new_interval is None:
         expected_new_interval = timer.adjust_interval(drift)
     return Interval(
         interval=interval.interval,
         wakeup_time=next_wakeup_time,
         yield_time=next_yield_time,
         expected_new_interval=expected_new_interval,
     )