Esempio n. 1
0
 def test_callback_is_not_called_when_interval_not_reached(self):
     callback = MagicMock()
     message = 'a'
     cuckoo = Cuckoo(10, callback)
     cuckoo.reset()
     cuckoo(message)
     self.assertFalse(callback.called)
Esempio n. 2
0
 def test_callback_is_only_called_when_interval_reached(self):
     callback = MagicMock()
     message = 'a'
     cuckoo = Cuckoo(0.01, callback)
     cuckoo.reset()
     cuckoo(message)
     self.assertFalse(callback.called)
     sleep(0.011)
     cuckoo(message)
     self.assertTrue(callback.called)
Esempio n. 3
0
 def test_call_resets_timestamp_after_interval_reached(self):
     callback = MagicMock()
     message = 'a'
     cuckoo = Cuckoo(0.01, callback)
     cuckoo.reset()
     timestamp1 = cuckoo.timestamp
     print(cuckoo.timestamp)
     self.assertFalse(callback.called)
     sleep(0.011)
     cuckoo(message)
     timestamp2 = cuckoo.timestamp
     print(cuckoo.timestamp)
     self.assertTrue(callback.called)
     assert timestamp1 is not timestamp2
Esempio n. 4
0
 def test_reset_timestamp(self):
     cuckoo = Cuckoo()
     cuckoo.reset()
     delta = datetime.now() - cuckoo.timestamp
     assert delta.total_seconds() > 0
Esempio n. 5
0
 def test_interval_reached(self):
     cuckoo = Cuckoo(0.01)
     cuckoo.reset()
     self.assertFalse(cuckoo._interval_reached())
     sleep(0.011)
     self.assertTrue(cuckoo._interval_reached())