def test_queue(self): operation1 = Operation() assert operation1.is_ready operation2 = Operation() operation2.add_dependency(operation1) assert operation2.is_ready == False self.queue.add_operation(operation1) self.queue.add_operation(operation2) self.run_loop.waitBeforeCalling(2, self.quit) self.run_loop.run() assert operation2.is_finished assert operation1.is_finished self.assertEqual(0, len(self.queue.operations)) self.assertEqual(0, len(self.queue.executing))
def test_dependency(self): operation1 = Operation() assert operation1.is_ready operation2 = Operation() operation2.add_dependency(operation1) assert operation2.is_ready == False self.operation2 = operation2 operation1.add_observer(self, "is_finished") operation1.start() assert self.observed
def test_sort(self): operation1 = Operation() # operation1.queue_priority = self.QueuePriorityLow operation2 = Operation() operation2.add_dependency(operation1) operation3 = Operation() operation3.queue_priority = Operation.QueuePriorityLow l = [operation2, operation1, operation3] l.sort() self.assertEqual(l, [operation1, operation3, operation2]) operation4 = Operation() operation4.queue_priority = Operation.QueuePriorityVeryHigh operation5 = Operation() operation5.add_dependency(operation4) operation5.queue_priority = Operation.QueuePriorityVeryLow l = [operation2, operation1, operation5, operation4, operation3] l.sort() self.assertEqual(l, [operation4, operation1, operation3, operation2, operation5])