• Home
  • Raw
  • Download

Lines Matching refs:q

17 def qfull(q):  argument
18 return q.maxsize > 0 and q.qsize() == q.maxsize
92 def basic_queue_test(self, q): argument
93 if q.qsize():
95 self.assertTrue(q.empty())
96 self.assertFalse(q.full())
98 q.put(111)
99 q.put(333)
100 q.put(222)
104 actual_order = [q.get(), q.get(), q.get()]
105 self.assertEqual(actual_order, target_order[q.__class__.__name__],
108 q.put(i)
109 self.assertTrue(q.qsize(), "Queue should not be empty")
110 self.assertTrue(not qfull(q), "Queue should not be full")
113 q.put(last)
114 self.assertTrue(qfull(q), "Queue should be full")
115 self.assertFalse(q.empty())
116 self.assertTrue(q.full())
118 q.put(full, block=0)
123 q.put(full, timeout=0.01)
128 self.do_blocking_test(q.put, (full,), q.get, ())
129 self.do_blocking_test(q.put, (full, True, 10), q.get, ())
132 q.get()
133 self.assertTrue(not q.qsize(), "Queue should be empty")
135 q.get(block=0)
140 q.get(timeout=0.01)
145 self.do_blocking_test(q.get, (), q.put, ('empty',))
146 self.do_blocking_test(q.get, (True, 10), q.put, ('empty',))
149 def worker(self, q): argument
151 x = q.get()
153 q.task_done()
157 q.task_done()
159 def queue_join_test(self, q): argument
163 thread = threading.Thread(target=self.worker, args=(q,))
167 q.put(i)
168 q.join()
172 q.put(-1) # instruct the threads to close
173 q.join() # verify that you can join twice
179 q = self.type2test()
181 q.task_done()
190 q = self.type2test()
191 self.queue_join_test(q)
192 self.queue_join_test(q)
194 q.task_done()
203 q = self.type2test(QUEUE_SIZE)
204 self.basic_queue_test(q)
205 self.basic_queue_test(q)
208 q = self.type2test(QUEUE_SIZE)
210 q.put(1, timeout=-1)
212 q.get(1, timeout=-1)
215 q = self.type2test(QUEUE_SIZE)
217 q.put_nowait(1)
219 q.put_nowait(1)
222 q.get_nowait()
224 q.get_nowait()
228 q = self.type2test(3)
229 q.put(1)
230 q.put(2)
231 q.put(3)
233 q.put_nowait(4)
234 self.assertEqual(q.qsize(), 3)
235 q.maxsize = 2 # shrink the queue
237 q.put_nowait(4)
315 def failing_queue_test(self, q): argument
316 if q.qsize():
319 q.put(i)
321 q.fail_next_put = True
323 q.put("oops", block=0)
327 q.fail_next_put = True
329 q.put("oops", timeout=0.1)
333 q.put("last")
334 self.assertTrue(qfull(q), "Queue should be full")
336 q.fail_next_put = True
338 self.do_blocking_test(q.put, ("full",), q.get, ())
344 q.put("last")
346 q.fail_next_put = True
348 self.do_exceptional_blocking_test(q.put, ("full", True, 10), q.get, (),
355 q.put("last")
356 self.assertTrue(qfull(q), "Queue should be full")
357 q.get()
358 self.assertTrue(not qfull(q), "Queue should not be full")
359 q.put("last")
360 self.assertTrue(qfull(q), "Queue should be full")
362 self.do_blocking_test(q.put, ("full",), q.get, ())
365 q.get()
366 self.assertTrue(not q.qsize(), "Queue should be empty")
367 q.put("first")
368 q.fail_next_get = True
370 q.get()
374 self.assertTrue(q.qsize(), "Queue should not be empty")
375 q.fail_next_get = True
377 q.get(timeout=0.1)
381 self.assertTrue(q.qsize(), "Queue should not be empty")
382 q.get()
383 self.assertTrue(not q.qsize(), "Queue should be empty")
384 q.fail_next_get = True
386 self.do_exceptional_blocking_test(q.get, (), q.put, ('empty',),
392 self.assertTrue(q.qsize(), "Queue should not be empty")
393 q.get()
394 self.assertTrue(not q.qsize(), "Queue should be empty")
400 q = self.FailingQueue(QUEUE_SIZE)
401 self.failing_queue_test(q)
402 self.failing_queue_test(q)
418 self.q = self.type2test()
420 def feed(self, q, seq, rnd): argument
426 q.put(val)
430 def consume(self, q, results, sentinel): argument
432 val = q.get()
437 def consume_nonblock(self, q, results, sentinel): argument
441 val = q.get(block=False)
450 def consume_timeout(self, q, results, sentinel): argument
454 val = q.get(timeout=1e-5)
463 def run_threads(self, n_feeders, n_consumers, q, inputs, argument
481 args=(q, seq, rnd))
484 args=(q, results, sentinel))
491 self.assertTrue(q.empty())
492 self.assertEqual(q.qsize(), 0)
498 q = self.q
499 self.assertTrue(q.empty())
500 self.assertEqual(q.qsize(), 0)
501 q.put(1)
502 self.assertFalse(q.empty())
503 self.assertEqual(q.qsize(), 1)
504 q.put(2)
505 q.put_nowait(3)
506 q.put(4)
507 self.assertFalse(q.empty())
508 self.assertEqual(q.qsize(), 4)
510 self.assertEqual(q.get(), 1)
511 self.assertEqual(q.qsize(), 3)
513 self.assertEqual(q.get_nowait(), 2)
514 self.assertEqual(q.qsize(), 2)
516 self.assertEqual(q.get(block=False), 3)
517 self.assertFalse(q.empty())
518 self.assertEqual(q.qsize(), 1)
520 self.assertEqual(q.get(timeout=0.1), 4)
521 self.assertTrue(q.empty())
522 self.assertEqual(q.qsize(), 0)
525 q.get(block=False)
527 q.get(timeout=1e-3)
529 q.get_nowait()
530 self.assertTrue(q.empty())
531 self.assertEqual(q.qsize(), 0)
534 q = self.q
535 q.put(1)
537 q.get(timeout=-1)
541 q = self.q
543 results = self.run_threads(1, 1, q, inputs, self.feed, self.consume)
551 q = self.q
553 results = self.run_threads(N, N, q, inputs, self.feed, self.consume)
562 q = self.q
564 results = self.run_threads(N, N, q, inputs,
572 q = self.q
574 results = self.run_threads(N, N, q, inputs,
586 q = self.q
588 q.put(C())
590 wr = weakref.ref(q.get())
618 q = self.q
631 q.put(next(gen))
635 q.put(next(gen))
637 results.append(q.get())