Commit a87472c6 authored by Christine Spang's avatar Christine Spang Committed by Denis Bilenko

Fix peek() in LifoQueue.

peek() should return the same element that get() returns, which
is not currently the case.

Add regression test for queue peek().
parent 5f17846e
...@@ -339,6 +339,9 @@ class LifoQueue(Queue): ...@@ -339,6 +339,9 @@ class LifoQueue(Queue):
def _get(self): def _get(self):
return self.queue.pop() return self.queue.pop()
def _peek(self):
return self.queue[-1]
class JoinableQueue(Queue): class JoinableQueue(Queue):
'''A subclass of :class:`Queue` that additionally has :meth:`task_done` and :meth:`join` methods.''' '''A subclass of :class:`Queue` that additionally has :meth:`task_done` and :meth:`join` methods.'''
......
...@@ -98,9 +98,19 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin): ...@@ -98,9 +98,19 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin):
q.put(111) q.put(111)
q.put(333) q.put(333)
q.put(222) q.put(222)
target_order = dict(Queue = [111, 333, 222], q.put(444)
target_first_items = dict(
Queue = 111,
LifoQueue = 444,
PriorityQueue = 111)
actual_first_item = (q.peek(), q.get())
self.assertEquals(actual_first_item,
(target_first_items[q.__class__.__name__],
target_first_items[q.__class__.__name__]),
"q.peek() and q.get() are not equal!")
target_order = dict(Queue = [333, 222, 444],
LifoQueue = [222, 333, 111], LifoQueue = [222, 333, 111],
PriorityQueue = [111, 222, 333]) PriorityQueue = [222, 333, 444])
actual_order = [q.get(), q.get(), q.get()] actual_order = [q.get(), q.get(), q.get()]
self.assertEquals(actual_order, target_order[q.__class__.__name__], self.assertEquals(actual_order, target_order[q.__class__.__name__],
"Didn't seem to queue the correct data!") "Didn't seem to queue the correct data!")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment