Commit 8c0f741f authored by Fantix King's avatar Fantix King Committed by Denis Bilenko

Fixes test_queue.py for PY3

parent dee1219a
......@@ -33,7 +33,7 @@ Full = __queue__.Full
Empty = __queue__.Empty
from gevent.timeout import Timeout
from gevent.hub import get_hub, Waiter, getcurrent
from gevent.hub import get_hub, Waiter, getcurrent, PY3
__all__ = ['Queue', 'PriorityQueue', 'LifoQueue', 'JoinableQueue', 'Channel']
......@@ -285,6 +285,10 @@ class Queue(object):
raise result
return result
if PY3:
__next__ = next
del next
class ItemWaiter(Waiter):
__slots__ = ['item', 'queue']
......
......@@ -108,22 +108,22 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin):
q.put(i)
self.assert_(not q.empty(), "Queue should not be empty")
self.assert_(not q.full(), "Queue should not be full")
q.put("last")
q.put(999)
self.assert_(q.full(), "Queue should be full")
try:
q.put("full", block=0)
q.put(888, block=0)
self.fail("Didn't appear to block with a full queue")
except Queue.Full:
pass
try:
q.put("full", timeout=0.01)
q.put(888, timeout=0.01)
self.fail("Didn't appear to time-out with a full queue")
except Queue.Full:
pass
self.assertEquals(q.qsize(), QUEUE_SIZE)
# Test a blocking put
self.do_blocking_test(q.put, ("full",), q.get, ())
self.do_blocking_test(q.put, ("full", True, 10), q.get, ())
self.do_blocking_test(q.put, (888,), q.get, ())
self.do_blocking_test(q.put, (888, True, 10), q.get, ())
# Empty it
for i in range(QUEUE_SIZE):
q.get()
......@@ -249,36 +249,36 @@ class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
self.fail("The queue didn't fail when it should have")
except FailingQueueException:
pass
q.put("last")
q.put(999)
self.assert_(q.full(), "Queue should be full")
# Test a failing blocking put
q.fail_next_put = True
try:
self.do_blocking_test(q.put, ("full",), q.get, ())
self.do_blocking_test(q.put, (888,), q.get, ())
self.fail("The queue didn't fail when it should have")
except FailingQueueException:
pass
# Check the Queue isn't damaged.
# put failed, but get succeeded - re-add
q.put("last")
q.put(999)
# Test a failing timeout put
q.fail_next_put = True
try:
self.do_exceptional_blocking_test(q.put, ("full", True, 10), q.get, (),
self.do_exceptional_blocking_test(q.put, (888, True, 10), q.get, (),
FailingQueueException)
self.fail("The queue didn't fail when it should have")
except FailingQueueException:
pass
# Check the Queue isn't damaged.
# put failed, but get succeeded - re-add
q.put("last")
q.put(999)
self.assert_(q.full(), "Queue should be full")
q.get()
self.assert_(not q.full(), "Queue should not be full")
q.put("last")
q.put(999)
self.assert_(q.full(), "Queue should be full")
# Test a blocking put
self.do_blocking_test(q.put, ("full",), q.get, ())
self.do_blocking_test(q.put, (888,), q.get, ())
# Empty it
for i in range(QUEUE_SIZE):
q.get()
......
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