Esempio n. 1
0
 def test_good_calls(self):
     for secs in [0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1]:
         finish_clock = time.perf_counter() + secs
         secs_out = wait_secs(finish_clock)
         self.assertGreater(secs_out, secs - 1e-4)
         # add a tiny offset as this test may fail if
         # otherwise if the two calls to perf_counter are close
         # enough to return the same result as a + b - a cannot
         # in general be assumed to be <= b in floating point
         # math (here a is perf_counter() and b is the wait time
         self.assertLessEqual(secs_out, secs + 1e-14)
Esempio n. 2
0
 def _update_set_ts(self, step_clock):
     # calculate the delay time to the *max* delay,
     # then take off up to the tolerance
     tolerance = self._delay_tolerance
     step_clock += self._delay
     remainder = wait_secs(step_clock + tolerance)
     if remainder <= tolerance:
         # don't allow extra delays to compound
         step_clock = time.perf_counter()
         remainder = 0
     else:
         remainder -= tolerance
     return step_clock, remainder
Esempio n. 3
0
    def _wait(self, delay):
        if delay:
            finish_clock = time.perf_counter() + delay

            if self._monitor:
                # TODO - perhpas pass self._check_signal in here
                # so that we can halt within monitor.call if it
                # lasts a very long time?
                self._monitor.call(finish_by=finish_clock)

            while True:
                self._check_signal()
                t = wait_secs(finish_clock)
                time.sleep(min(t, self.signal_period))
                if t <= self.signal_period:
                    break
        else:
            self._check_signal()
Esempio n. 4
0
    def test_warning(self):
        with LogCapture() as logs:
            secs_out = wait_secs(time.perf_counter() - 1)
        self.assertEqual(secs_out, 0)

        self.assertEqual(logs.value.count('negative delay'), 1, logs.value)
Esempio n. 5
0
 def test_bad_calls(self):
     bad_args = [None, datetime.now()]
     for arg in bad_args:
         with self.assertRaises(TypeError):
             wait_secs(arg)
Esempio n. 6
0
 def _wait(self, delay):
     if delay:
         finish_clock = time.perf_counter() + delay
         t = wait_secs(finish_clock)
         time.sleep(t)
Esempio n. 7
0
def test_bad_calls():
    bad_args = [None, datetime.now()]
    for arg in bad_args:
        with pytest.raises(TypeError):
            wait_secs(arg)
Esempio n. 8
0
def test_warning():
    with LogCapture() as logs:
        secs_out = wait_secs(time.perf_counter() - 1)
    assert secs_out == 0

    assert logs.value.count('negative delay') == 1, logs.value
Esempio n. 9
0
 def test_good_calls(self):
     for secs in [0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1]:
         finish_clock = time.perf_counter() + secs
         secs_out = wait_secs(finish_clock)
         self.assertGreater(secs_out, secs - 1e-4)
         self.assertLessEqual(secs_out, secs)
Esempio n. 10
0
 def test_warning(self):
     with LogCapture() as logs:
         secs_out = wait_secs(time.perf_counter() - 1)
     self.assertEqual(secs_out, 0)