Lines Matching refs:q

22 def qfull(q):  argument
23 return q.maxsize > 0 and q.qsize() == q.maxsize
97 def basic_queue_test(self, q): argument
98 if q.qsize():
100 self.assertTrue(q.empty())
101 self.assertFalse(q.full())
103 q.put(111)
104 q.put(333)
105 q.put(222)
109 actual_order = [q.get(), q.get(), q.get()]
110 self.assertEqual(actual_order, target_order[q.__class__.__name__],
113 q.put(i)
114 self.assertTrue(q.qsize(), "Queue should not be empty")
115 self.assertTrue(not qfull(q), "Queue should not be full")
118 q.put(last)
119 self.assertTrue(qfull(q), "Queue should be full")
120 self.assertFalse(q.empty())
121 self.assertTrue(q.full())
123 q.put(full, block=0)
128 q.put(full, timeout=0.01)
133 self.do_blocking_test(q.put, (full,), q.get, ())
134 self.do_blocking_test(q.put, (full, True, 10), q.get, ())
137 q.get()
138 self.assertTrue(not q.qsize(), "Queue should be empty")
140 q.get(block=0)
145 q.get(timeout=0.01)
150 self.do_blocking_test(q.get, (), q.put, ('empty',))
151 self.do_blocking_test(q.get, (True, 10), q.put, ('empty',))
154 def worker(self, q): argument
156 x = q.get()
158 q.task_done()
162 q.task_done()
164 def queue_join_test(self, q): argument
168 thread = threading.Thread(target=self.worker, args=(q,))
172 q.put(i)
173 q.join()
177 q.put(-1) # instruct the threads to close
178 q.join() # verify that you can join twice
184 q = self.type2test()
186 q.task_done()
195 q = self.type2test()
196 self.queue_join_test(q)
197 self.queue_join_test(q)
199 q.task_done()
208 q = self.type2test(QUEUE_SIZE)
209 self.basic_queue_test(q)
210 self.basic_queue_test(q)
213 q = self.type2test(QUEUE_SIZE)
215 q.put(1, timeout=-1)
217 q.get(1, timeout=-1)
220 q = self.type2test(QUEUE_SIZE)
222 q.put_nowait(1)
224 q.put_nowait(1)
227 q.get_nowait()
229 q.get_nowait()
233 q = self.type2test(3)
234 q.put(1)
235 q.put(2)
236 q.put(3)
238 q.put_nowait(4)
239 self.assertEqual(q.qsize(), 3)
240 q.maxsize = 2 # shrink the queue
242 q.put_nowait(4)
277 def failing_queue_test(self, q): argument
278 if q.qsize():
281 q.put(i)
283 q.fail_next_put = True
285 q.put("oops", block=0)
289 q.fail_next_put = True
291 q.put("oops", timeout=0.1)
295 q.put("last")
296 self.assertTrue(qfull(q), "Queue should be full")
298 q.fail_next_put = True
300 self.do_blocking_test(q.put, ("full",), q.get, ())
306 q.put("last")
308 q.fail_next_put = True
310 self.do_exceptional_blocking_test(q.put, ("full", True, 10), q.get, (),
317 q.put("last")
318 self.assertTrue(qfull(q), "Queue should be full")
319 q.get()
320 self.assertTrue(not qfull(q), "Queue should not be full")
321 q.put("last")
322 self.assertTrue(qfull(q), "Queue should be full")
324 self.do_blocking_test(q.put, ("full",), q.get, ())
327 q.get()
328 self.assertTrue(not q.qsize(), "Queue should be empty")
329 q.put("first")
330 q.fail_next_get = True
332 q.get()
336 self.assertTrue(q.qsize(), "Queue should not be empty")
337 q.fail_next_get = True
339 q.get(timeout=0.1)
343 self.assertTrue(q.qsize(), "Queue should not be empty")
344 q.get()
345 self.assertTrue(not q.qsize(), "Queue should be empty")
346 q.fail_next_get = True
348 self.do_exceptional_blocking_test(q.get, (), q.put, ('empty',),
354 self.assertTrue(q.qsize(), "Queue should not be empty")
355 q.get()
356 self.assertTrue(not q.qsize(), "Queue should be empty")
361 q = FailingQueue(QUEUE_SIZE)
362 self.failing_queue_test(q)
363 self.failing_queue_test(q)
369 self.q = self.type2test()
371 def feed(self, q, seq, rnd): argument
377 q.put(val)
381 def consume(self, q, results, sentinel): argument
383 val = q.get()
388 def consume_nonblock(self, q, results, sentinel): argument
392 val = q.get(block=False)
401 def consume_timeout(self, q, results, sentinel): argument
405 val = q.get(timeout=1e-5)
414 def run_threads(self, n_feeders, n_consumers, q, inputs, argument
432 args=(q, seq, rnd))
435 args=(q, results, sentinel))
442 self.assertTrue(q.empty())
443 self.assertEqual(q.qsize(), 0)
449 q = self.q
450 self.assertTrue(q.empty())
451 self.assertEqual(q.qsize(), 0)
452 q.put(1)
453 self.assertFalse(q.empty())
454 self.assertEqual(q.qsize(), 1)
455 q.put(2)
456 q.put_nowait(3)
457 q.put(4)
458 self.assertFalse(q.empty())
459 self.assertEqual(q.qsize(), 4)
461 self.assertEqual(q.get(), 1)
462 self.assertEqual(q.qsize(), 3)
464 self.assertEqual(q.get_nowait(), 2)
465 self.assertEqual(q.qsize(), 2)
467 self.assertEqual(q.get(block=False), 3)
468 self.assertFalse(q.empty())
469 self.assertEqual(q.qsize(), 1)
471 self.assertEqual(q.get(timeout=0.1), 4)
472 self.assertTrue(q.empty())
473 self.assertEqual(q.qsize(), 0)
476 q.get(block=False)
478 q.get(timeout=1e-3)
480 q.get_nowait()
481 self.assertTrue(q.empty())
482 self.assertEqual(q.qsize(), 0)
485 q = self.q
486 q.put(1)
488 q.get(timeout=-1)
492 q = self.q
494 results = self.run_threads(1, 1, q, inputs, self.feed, self.consume)
502 q = self.q
504 results = self.run_threads(N, N, q, inputs, self.feed, self.consume)
513 q = self.q
515 results = self.run_threads(N, N, q, inputs,
523 q = self.q
525 results = self.run_threads(N, N, q, inputs,
537 q = self.q
539 q.put(C())
541 wr = weakref.ref(q.get())
562 q = self.q
575 q.put(next(gen))
579 q.put(next(gen))
581 results.append(q.get())