Beispiel #1
0
    def test_timer_runs_continiously(self):
        execute_mock = MagicMock()

        cancel = timer(0.1, execute_mock)

        sleep(0.5)
        cancel()
        self.assertTrue(execute_mock.call_count > 2)
Beispiel #2
0
    def _create_timer(self):
        def timer_fn():
            msg = EngineRunner._run_message()
            self.message_box.put_nowait(msg)

        if self.timer_cancel is not None:
            self.timer_cancel()

        self.timer_cancel = timer(self.interval, timer_fn)
Beispiel #3
0
    def _create_timer(self):
        def timer_fn():
            msg = EngineRunner._run_message()
            self.message_box.put_nowait(msg)

        if self.timer_cancel is not None:
            self.timer_cancel()

        self.timer_cancel = timer(self.interval, timer_fn)
Beispiel #4
0
    def test_timer_passes_arguments_to_timer_func(self):
        execute_mock = MagicMock()
        cancel = timer(0.1, execute_mock, 'foo', bar='baz')

        sleep(0.15)
        cancel()

        self.assertEqual(execute_mock.call_count, 1)
        execute_mock.assert_called_once_with('foo', bar='baz')
Beispiel #5
0
    def test_timer_dont_run_after_cancellation(self):
        execute_mock = MagicMock()
        cancel = timer(0.1, execute_mock)

        sleep(0.5)
        cancel()

        self.assertTrue(execute_mock.call_count > 2)
        expected_call_count = execute_mock.call_count

        sleep(0.5)
        self.assertEqual(execute_mock.call_count, expected_call_count)
Beispiel #6
0
    def test_timer_starts_daemon_thread(self):
        execute_mock = MagicMock()
        timer_thread = MagicMock()

        with patch('threading.Thread') as thread_mock:
            thread_mock.return_value = timer_thread

            cancel = timer(0.1, execute_mock)

            assert hasattr(timer_thread, "daemon")
            assert timer_thread.daemon is True

            cancel()