def test_no_sleep(self, mock_time, mock_interruptable_sleep): mock_time.time.side_effect = [0, 1] sw = utils.Stopwatch() sw.start() sw.sleep(1) self.assertFalse(mock_interruptable_sleep.called)
def _timer_method(self): """Timer thread method. It generates events with type "time" to inform HookExecutor about how many time passed since beginning of the first iteration. """ stopwatch = rutils.Stopwatch(stop_event=self._timer_stop_event) stopwatch.start() seconds_since_start = 0 while not self._timer_stop_event.isSet(): self.on_event(event_type="time", value=seconds_since_start) seconds_since_start += 1 stopwatch.sleep(seconds_since_start)
def test_stopwatch(self, mock_time, mock_interruptable_sleep): mock_time.time.side_effect = [0, 0, 1, 2, 3] sw = utils.Stopwatch() sw.start() sw.sleep(1) sw.sleep(2) sw.sleep(3) mock_interruptable_sleep.assert_has_calls([ mock.call(1), mock.call(1), mock.call(1), ])
def test_stopwatch_with_event(self, mock_time): mock_time.time.side_effect = [0, 0, 1, 2, 3] event = mock.Mock(spec=threading.Event)() sw = utils.Stopwatch(stop_event=event) sw.start() sw.sleep(1) sw.sleep(2) sw.sleep(3) event.wait.assert_has_calls([ mock.call(1), mock.call(1), mock.call(1), ])