Example #1
0
    def test_delayed_call(self):
        test_time = self.god.create_mock_function('time')
        test_time.expect_call().and_return(33)
        test_time.expect_call().and_return(34.01)
        test_time.expect_call().and_return(34.99)
        test_time.expect_call().and_return(35.01)

        def test_callback():
            test_callback.calls += 1

        test_callback.calls = 0
        delay_task = scheduler_models.DelayedCallTask(
            delay_seconds=2, callback=test_callback,
            now_func=test_time)  # time 33
        self.assertEqual(35, delay_task.end_time)
        delay_task.poll()  # activates the task and polls it once, time 34.01
        self.assertEqual(0, test_callback.calls, "callback called early")
        delay_task.poll()  # time 34.99
        self.assertEqual(0, test_callback.calls, "callback called early")
        delay_task.poll()  # time 35.01
        self.assertEqual(1, test_callback.calls)
        self.assert_(delay_task.is_done())
        self.assert_(delay_task.success)
        self.assert_(not delay_task.aborted)
        self.god.check_playback()
Example #2
0
 def test_delayed_call_abort(self):
     delay_task = scheduler_models.DelayedCallTask(delay_seconds=987654,
                                                   callback=lambda: None)
     delay_task.abort()
     self.assert_(delay_task.aborted)
     self.assert_(delay_task.is_done())
     self.assert_(not delay_task.success)
     self.god.check_playback()