def test_get_next_timestamp(self): pings = [(12, 8), (14, 51)] ts = datetime.datetime(2020, 3, 26, 4, 0).timestamp() next_one = time_utils.get_next_timestamp(pings, ts) expected_next = datetime.datetime(2020, 3, 26, 12, 8).timestamp() self.assertEqual(next_one, expected_next) ts = datetime.datetime(2020, 3, 26, 12, 10).timestamp() next_one = time_utils.get_next_timestamp(pings, ts) expected_next = datetime.datetime(2020, 3, 26, 14, 51).timestamp() self.assertEqual(next_one, expected_next) ts = datetime.datetime(2020, 3, 26, 18, 10).timestamp() next_one = time_utils.get_next_timestamp(pings, ts) expected_next = datetime.datetime(2020, 3, 27, 12, 8).timestamp() self.assertEqual(next_one, expected_next)
def computes_delay(self, delay=None) -> int: """Computes the delay if None.""" if delay is not None: return int(delay) if not self.when: logging.warning('No ping time. Check config.') return -1 return int(time_utils.get_next_timestamp(self.when) - time.time())