def test_insert_max_priority_capped(self): q = StablePriorityQueue(maxsize=10, max_priority=20) a = mock.Mock() a.PRIORITY = 100 q.put(a) self.assertIs(q.get(), a)
def test_queue_length(self): a = mock.Mock() a.PRIORITY = 5 q = StablePriorityQueue(maxsize=10, max_priority=20) self.assertEqual(q.qsize(), 0) q.put(a) self.assertEqual(q.qsize(), 1) q.get() self.assertEqual(q.qsize(), 0)
def test_priority_attr_is_missing(self): # If priority attr is missing, we should add it # to the lowest priority. q = StablePriorityQueue(maxsize=10, max_priority=20) a = object() b = mock.Mock() b.PRIORITY = 5 q.put(a) q.put(b) self.assertIs(q.get(), b) self.assertIs(q.get(), a)
def __init__(self, num_threads, result_queue, quiet, max_queue_size, write_queue): self._max_queue_size = max_queue_size self.queue = StablePriorityQueue(maxsize=self._max_queue_size, max_priority=20) self.num_threads = num_threads self.result_queue = result_queue self.quiet = quiet self.threads_list = [] self.write_queue = write_queue self.print_thread = PrintThread(self.result_queue, self.quiet) self.print_thread.daemon = True self.io_thread = IOWriterThread(self.write_queue)
def __init__(self, num_threads, result_queue, quiet, only_show_errors, max_queue_size, write_queue): self._max_queue_size = max_queue_size LOGGER.debug("Using max queue size for s3 tasks of: %s", self._max_queue_size) self.queue = StablePriorityQueue(maxsize=self._max_queue_size, max_priority=20) self.num_threads = num_threads self.result_queue = result_queue self.quiet = quiet self.only_show_errors = only_show_errors self.threads_list = [] self.write_queue = write_queue self.print_thread = PrintThread(self.result_queue, self.quiet, self.only_show_errors) self.print_thread.daemon = True self.io_thread = IOWriterThread(self.write_queue)
def test_fifo_order_of_same_priorities(self): a = mock.Mock() a.PRIORITY = 5 b = mock.Mock() b.PRIORITY = 5 c = mock.Mock() c.PRIORITY = 1 q = StablePriorityQueue(maxsize=10, max_priority=20) q.put(a) q.put(b) q.put(c) # First we should get c because it's the lowest priority. # We're using assertIs because we want the *exact* object. self.assertIs(q.get(), c) # Then a and b are the same priority, but we should get # a first because it was inserted first. self.assertIs(q.get(), a) self.assertIs(q.get(), b)
def setUp(self): self.q = StablePriorityQueue(maxsize=10, max_priority=20)