Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 671153d

Browse files
committed
Add queue tests for empty, full, put_nowait, and get_nowait.
Closes issue 9357. Thanks to Brian Brazil for the patch.
1 parent 6b0e0e4 commit 671153d

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lib/test/test_queue.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def setUp(self):
9090
def simple_queue_test(self, q):
9191
if q.qsize():
9292
raise RuntimeError("Call this function with an empty queue")
93+
self.assertTrue(q.empty())
94+
self.assertFalse(q.full())
9395
# I guess we better check things actually queue correctly a little :)
9496
q.put(111)
9597
q.put(333)
@@ -108,6 +110,8 @@ def simple_queue_test(self, q):
108110
full = 3 * 2 * QUEUE_SIZE
109111
q.put(last)
110112
self.assertTrue(qfull(q), "Queue should be full")
113+
self.assertFalse(q.empty())
114+
self.assertTrue(q.full())
111115
try:
112116
q.put(full, block=0)
113117
self.fail("Didn't appear to block with a full queue")
@@ -193,6 +197,25 @@ def test_simple_queue(self):
193197
self.simple_queue_test(q)
194198
self.simple_queue_test(q)
195199

200+
def test_negative_timeout_raises_exception(self):
201+
q = self.type2test(QUEUE_SIZE)
202+
with self.assertRaises(ValueError):
203+
q.put(1, timeout=-1)
204+
with self.assertRaises(ValueError):
205+
q.get(1, timeout=-1)
206+
207+
def test_nowait(self):
208+
q = self.type2test(QUEUE_SIZE)
209+
for i in range(QUEUE_SIZE):
210+
q.put_nowait(1)
211+
with self.assertRaises(queue.Full):
212+
q.put_nowait(1)
213+
214+
for i in range(QUEUE_SIZE):
215+
q.get_nowait()
216+
with self.assertRaises(queue.Empty):
217+
q.get_nowait()
218+
196219

197220
class QueueTest(BaseQueueTest):
198221
type2test = queue.Queue

0 commit comments

Comments
 (0)