Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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
Example #6
0
 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
Example #7
0
 def test_reset_timestamp(self):
     cuckoo = Cuckoo()
     cuckoo.reset()
     delta = datetime.now() - cuckoo.timestamp
     self.assertGreater(total_seconds(delta), 0)
Example #8
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())
Example #9
0
 def test_reset_timestamp(self):
     cuckoo = Cuckoo()
     cuckoo.reset()
     delta = datetime.now() - cuckoo.timestamp
     self.assertGreater(total_seconds(delta), 0)
Example #10
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())