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_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 #3
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 #4
0
 def test_msg_gets_called_on_the_very_first_time(self):
     callback = MagicMock()
     message = 'a'
     cuckoo = Cuckoo(1, callback)
     cuckoo.msg(message)
     self.assertTrue(callback.called)
Example #5
0
 def test_msg_sets_timestamp_on_first_call(self):
     cuckoo = Cuckoo()
     cuckoo.msg()
     assert cuckoo.timestamp
Example #6
0
 def test_msg_calls_callback(self):
     callback = MagicMock()
     message = 'a'
     cuckoo = Cuckoo(callback=callback)
     cuckoo.msg(message)
     callback.assert_called_with(message)