[Python-checkins] r83108 - python/branches/py3k/Lib/test/test_queue.py

brett.cannon python-checkins at python.org
Fri Jul 23 18:56:21 CEST 2010


Author: brett.cannon
Date: Fri Jul 23 18:56:21 2010
New Revision: 83108
Log:
Add queue tests for empty, full, put_nowait, and get_nowait.
Closes issue 9357. Thanks to Brian Brazil for the patch.
Modified:
 python/branches/py3k/Lib/test/test_queue.py
Modified: python/branches/py3k/Lib/test/test_queue.py
==============================================================================
--- python/branches/py3k/Lib/test/test_queue.py	(original)
+++ python/branches/py3k/Lib/test/test_queue.py	Fri Jul 23 18:56:21 2010
@@ -90,6 +90,8 @@
 def simple_queue_test(self, q):
 if q.qsize():
 raise RuntimeError("Call this function with an empty queue")
+ self.assertTrue(q.empty())
+ self.assertFalse(q.full())
 # I guess we better check things actually queue correctly a little :)
 q.put(111)
 q.put(333)
@@ -108,6 +110,8 @@
 full = 3 * 2 * QUEUE_SIZE
 q.put(last)
 self.assertTrue(qfull(q), "Queue should be full")
+ self.assertFalse(q.empty())
+ self.assertTrue(q.full())
 try:
 q.put(full, block=0)
 self.fail("Didn't appear to block with a full queue")
@@ -193,6 +197,25 @@
 self.simple_queue_test(q)
 self.simple_queue_test(q)
 
+ def test_negative_timeout_raises_exception(self):
+ q = self.type2test(QUEUE_SIZE)
+ with self.assertRaises(ValueError):
+ q.put(1, timeout=-1)
+ with self.assertRaises(ValueError):
+ q.get(1, timeout=-1)
+
+ def test_nowait(self):
+ q = self.type2test(QUEUE_SIZE)
+ for i in range(QUEUE_SIZE):
+ q.put_nowait(1)
+ with self.assertRaises(queue.Full):
+ q.put_nowait(1)
+
+ for i in range(QUEUE_SIZE):
+ q.get_nowait()
+ with self.assertRaises(queue.Empty):
+ q.get_nowait()
+
 
 class QueueTest(BaseQueueTest):
 type2test = queue.Queue


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /