예제 #1
0
 def test_idle_repeat(self):
     qs = QueueScheduler()
     calls = []
     def idle_add(arg):
         calls.append(arg)
         return len(calls)<10
     qs.idle_add(idle_add, True)
     qs.timeout_add(500, qs.stop)
     qs.run()
     assert len(calls)==10
예제 #2
0
    def test_idle_raises_exception(self):
        qs = QueueScheduler()

        def raise_exception():
            raise Exception("test scheduler error handling")

        with silence_error(log):
            qs.idle_add(raise_exception)
            qs.timeout_add(500, qs.stop)
            qs.run()
예제 #3
0
 def test_idle_timeout(self):
     qs = QueueScheduler()
     calls = []
     def idle_add(arg):
         calls.append(arg)
     qs.idle_add(idle_add, True)
     def timeout_add(arg):
         calls.append(arg)
     qs.timeout_add(100, timeout_add, True)
     qs.timeout_add(500, qs.stop)
     qs.run()
     assert len(calls)==2
예제 #4
0
    def test_idle_cancel(self):
        qs = QueueScheduler()
        calls = []

        def idle_add():
            calls.append(True)
            return True

        tid = qs.idle_add(idle_add)
        copy = []

        def cancel():
            qs.source_remove(tid)
            copy[:] = list(calls)
            return False

        qs.timeout_add(500, cancel)
        qs.timeout_add(1000, qs.stop)
        qs.run()
        assert len(calls) == len(copy), "idle_add continued to run!"
예제 #5
0
 def test_stop_queue(self):
     qs = QueueScheduler()
     qs.idle_add(qs.stop_main_queue)
     qs.run()