def test_msg_is_not_called_when_interval_not_reached(self): callback = MagicMock() message = 'a' cuckoo = Cuckoo(10, callback) cuckoo.reset() cuckoo.msg(message) self.assertFalse(callback.called)
def test_msg_is_not_called_when_interval_not_reached(self): callback = MagicMock() message = "a" cuckoo = Cuckoo(10, callback) cuckoo.reset() cuckoo.msg(message) self.assertFalse(callback.called)
def test_msg_is_only_called_when_interval_reached(self): callback = MagicMock() message = "a" cuckoo = Cuckoo(0.1, callback) cuckoo.reset() cuckoo.msg(message) self.assertFalse(callback.called) sleep(0.11) cuckoo.msg(message) self.assertTrue(callback.called)
def test_msg_is_only_called_when_interval_reached(self): callback = MagicMock() message = 'a' cuckoo = Cuckoo(0.1, callback) cuckoo.reset() cuckoo.msg(message) self.assertFalse(callback.called) sleep(0.11) cuckoo.msg(message) self.assertTrue(callback.called)
def test_msg_resets_timestamp_after_interval_reached(self): callback = MagicMock() message = "a" cuckoo = Cuckoo(0.1, callback) cuckoo.reset() timestamp1 = cuckoo.timestamp print(cuckoo.timestamp) self.assertFalse(callback.called) sleep(0.11) cuckoo.msg(message) timestamp2 = cuckoo.timestamp print(cuckoo.timestamp) self.assertTrue(callback.called) assert timestamp1 is not timestamp2
def test_msg_resets_timestamp_after_interval_reached(self): callback = MagicMock() message = 'a' cuckoo = Cuckoo(0.1, callback) cuckoo.reset() timestamp1 = cuckoo.timestamp print(cuckoo.timestamp) self.assertFalse(callback.called) sleep(0.11) cuckoo.msg(message) timestamp2 = cuckoo.timestamp print(cuckoo.timestamp) self.assertTrue(callback.called) assert timestamp1 is not timestamp2
def test_reset_timestamp(self): cuckoo = Cuckoo() cuckoo.reset() delta = datetime.now() - cuckoo.timestamp self.assertGreater(total_seconds(delta), 0)
def test_interval_reached(self): cuckoo = Cuckoo(0.1) cuckoo.reset() self.assertFalse(cuckoo._interval_reached()) sleep(0.11) self.assertTrue(cuckoo._interval_reached())