mirror of https://github.com/python/cpython
Revert accidental changes to test_queue in r60605.
This commit is contained in:
parent
bafa9425a6
commit
3c3d9ac46c
|
@ -9,10 +9,6 @@ from test import test_support
|
||||||
|
|
||||||
QUEUE_SIZE = 5
|
QUEUE_SIZE = 5
|
||||||
|
|
||||||
def qfull(q):
|
|
||||||
return q.maxsize > 0 and q.qsize() == q.maxsize
|
|
||||||
|
|
||||||
|
|
||||||
# A thread to run a function that unclogs a blocked Queue.
|
# A thread to run a function that unclogs a blocked Queue.
|
||||||
class _TriggerThread(threading.Thread):
|
class _TriggerThread(threading.Thread):
|
||||||
def __init__(self, fn, args):
|
def __init__(self, fn, args):
|
||||||
|
@ -90,7 +86,7 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
self.cumlock = threading.Lock()
|
self.cumlock = threading.Lock()
|
||||||
|
|
||||||
def simple_queue_test(self, q):
|
def simple_queue_test(self, q):
|
||||||
if q.qsize():
|
if not q.empty():
|
||||||
raise RuntimeError, "Call this function with an empty queue"
|
raise RuntimeError, "Call this function with an empty queue"
|
||||||
# I guess we better check things actually queue correctly a little :)
|
# I guess we better check things actually queue correctly a little :)
|
||||||
q.put(111)
|
q.put(111)
|
||||||
|
@ -104,10 +100,10 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
"Didn't seem to queue the correct data!")
|
"Didn't seem to queue the correct data!")
|
||||||
for i in range(QUEUE_SIZE-1):
|
for i in range(QUEUE_SIZE-1):
|
||||||
q.put(i)
|
q.put(i)
|
||||||
self.assert_(q.qsize(), "Queue should not be empty")
|
self.assert_(not q.empty(), "Queue should not be empty")
|
||||||
self.assert_(not qfull(q), "Queue should not be full")
|
self.assert_(not q.full(), "Queue should not be full")
|
||||||
q.put("last")
|
q.put("last")
|
||||||
self.assert_(qfull(q), "Queue should be full")
|
self.assert_(q.full(), "Queue should be full")
|
||||||
try:
|
try:
|
||||||
q.put("full", block=0)
|
q.put("full", block=0)
|
||||||
self.fail("Didn't appear to block with a full queue")
|
self.fail("Didn't appear to block with a full queue")
|
||||||
|
@ -124,7 +120,7 @@ class BaseQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
# Empty it
|
# Empty it
|
||||||
for i in range(QUEUE_SIZE):
|
for i in range(QUEUE_SIZE):
|
||||||
q.get()
|
q.get()
|
||||||
self.assert_(not q.qsize(), "Queue should be empty")
|
self.assert_(q.empty(), "Queue should be empty")
|
||||||
try:
|
try:
|
||||||
q.get(block=0)
|
q.get(block=0)
|
||||||
self.fail("Didn't appear to block with an empty queue")
|
self.fail("Didn't appear to block with an empty queue")
|
||||||
|
@ -228,7 +224,7 @@ class FailingQueue(Queue.Queue):
|
||||||
class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
|
class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
|
|
||||||
def failing_queue_test(self, q):
|
def failing_queue_test(self, q):
|
||||||
if q.qsize():
|
if not q.empty():
|
||||||
raise RuntimeError, "Call this function with an empty queue"
|
raise RuntimeError, "Call this function with an empty queue"
|
||||||
for i in range(QUEUE_SIZE-1):
|
for i in range(QUEUE_SIZE-1):
|
||||||
q.put(i)
|
q.put(i)
|
||||||
|
@ -246,7 +242,7 @@ class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
except FailingQueueException:
|
except FailingQueueException:
|
||||||
pass
|
pass
|
||||||
q.put("last")
|
q.put("last")
|
||||||
self.assert_(qfull(q), "Queue should be full")
|
self.assert_(q.full(), "Queue should be full")
|
||||||
# Test a failing blocking put
|
# Test a failing blocking put
|
||||||
q.fail_next_put = True
|
q.fail_next_put = True
|
||||||
try:
|
try:
|
||||||
|
@ -268,17 +264,17 @@ class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
# Check the Queue isn't damaged.
|
# Check the Queue isn't damaged.
|
||||||
# put failed, but get succeeded - re-add
|
# put failed, but get succeeded - re-add
|
||||||
q.put("last")
|
q.put("last")
|
||||||
self.assert_(qfull(q), "Queue should be full")
|
self.assert_(q.full(), "Queue should be full")
|
||||||
q.get()
|
q.get()
|
||||||
self.assert_(not qfull(q), "Queue should not be full")
|
self.assert_(not q.full(), "Queue should not be full")
|
||||||
q.put("last")
|
q.put("last")
|
||||||
self.assert_(qfull(q), "Queue should be full")
|
self.assert_(q.full(), "Queue should be full")
|
||||||
# Test a blocking put
|
# Test a blocking put
|
||||||
self.do_blocking_test(q.put, ("full",), q.get, ())
|
self.do_blocking_test(q.put, ("full",), q.get, ())
|
||||||
# Empty it
|
# Empty it
|
||||||
for i in range(QUEUE_SIZE):
|
for i in range(QUEUE_SIZE):
|
||||||
q.get()
|
q.get()
|
||||||
self.assert_(not q.qsize(), "Queue should be empty")
|
self.assert_(q.empty(), "Queue should be empty")
|
||||||
q.put("first")
|
q.put("first")
|
||||||
q.fail_next_get = True
|
q.fail_next_get = True
|
||||||
try:
|
try:
|
||||||
|
@ -286,16 +282,16 @@ class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
self.fail("The queue didn't fail when it should have")
|
self.fail("The queue didn't fail when it should have")
|
||||||
except FailingQueueException:
|
except FailingQueueException:
|
||||||
pass
|
pass
|
||||||
self.assert_(q.qsize(), "Queue should not be empty")
|
self.assert_(not q.empty(), "Queue should not be empty")
|
||||||
q.fail_next_get = True
|
q.fail_next_get = True
|
||||||
try:
|
try:
|
||||||
q.get(timeout=0.1)
|
q.get(timeout=0.1)
|
||||||
self.fail("The queue didn't fail when it should have")
|
self.fail("The queue didn't fail when it should have")
|
||||||
except FailingQueueException:
|
except FailingQueueException:
|
||||||
pass
|
pass
|
||||||
self.assert_(q.qsize(), "Queue should not be empty")
|
self.assert_(not q.empty(), "Queue should not be empty")
|
||||||
q.get()
|
q.get()
|
||||||
self.assert_(not q.qsize(), "Queue should be empty")
|
self.assert_(q.empty(), "Queue should be empty")
|
||||||
q.fail_next_get = True
|
q.fail_next_get = True
|
||||||
try:
|
try:
|
||||||
self.do_exceptional_blocking_test(q.get, (), q.put, ('empty',),
|
self.do_exceptional_blocking_test(q.get, (), q.put, ('empty',),
|
||||||
|
@ -304,9 +300,9 @@ class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
|
||||||
except FailingQueueException:
|
except FailingQueueException:
|
||||||
pass
|
pass
|
||||||
# put succeeded, but get failed.
|
# put succeeded, but get failed.
|
||||||
self.assert_(q.qsize(), "Queue should not be empty")
|
self.assert_(not q.empty(), "Queue should not be empty")
|
||||||
q.get()
|
q.get()
|
||||||
self.assert_(not q.qsize(), "Queue should be empty")
|
self.assert_(q.empty(), "Queue should be empty")
|
||||||
|
|
||||||
def test_failing_queue(self):
|
def test_failing_queue(self):
|
||||||
# Test to make sure a queue is functioning correctly.
|
# Test to make sure a queue is functioning correctly.
|
||||||
|
|
Loading…
Reference in New Issue