MCPcopy Index your code
hub / github.com/RustPython/RustPython / basic_queue_test

Method basic_queue_test

Lib/test/test_queue.py:97–151  ·  view source on GitHub ↗
(self, q)

Source from the content-addressed store, hash-verified

95 self.cumlock = threading.Lock()
96
97 def basic_queue_test(self, q):
98 if q.qsize():
99 raise RuntimeError("Call this function with an empty queue")
100 self.assertTrue(q.empty())
101 self.assertFalse(q.full())
102 # I guess we better check things actually queue correctly a little :)
103 q.put(111)
104 q.put(333)
105 q.put(222)
106 target_order = dict(Queue = [111, 333, 222],
107 LifoQueue = [222, 333, 111],
108 PriorityQueue = [111, 222, 333])
109 actual_order = [q.get(), q.get(), q.get()]
110 self.assertEqual(actual_order, target_order[q.__class__.__name__],
111 "Didn't seem to queue the correct data!")
112 for i in range(QUEUE_SIZE-1):
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")
116 last = 2 * QUEUE_SIZE
117 full = 3 * 2 * QUEUE_SIZE
118 q.put(last)
119 self.assertTrue(qfull(q), "Queue should be full")
120 self.assertFalse(q.empty())
121 self.assertTrue(q.full())
122 try:
123 q.put(full, block=0)
124 self.fail("Didn't appear to block with a full queue")
125 except self.queue.Full:
126 pass
127 try:
128 q.put(full, timeout=0.01)
129 self.fail("Didn't appear to time-out with a full queue")
130 except self.queue.Full:
131 pass
132 # Test a blocking put
133 self.do_blocking_test(q.put, (full,), q.get, ())
134 self.do_blocking_test(q.put, (full, True, 10), q.get, ())
135 # Empty it
136 for i in range(QUEUE_SIZE):
137 q.get()
138 self.assertTrue(not q.qsize(), "Queue should be empty")
139 try:
140 q.get(block=0)
141 self.fail("Didn't appear to block with an empty queue")
142 except self.queue.Empty:
143 pass
144 try:
145 q.get(timeout=0.01)
146 self.fail("Didn't appear to time-out with an empty queue")
147 except self.queue.Empty:
148 pass
149 # Test a blocking get
150 self.do_blocking_test(q.get, (), q.put, ('empty',))
151 self.do_blocking_test(q.get, (True, 10), q.put, ('empty',))
152
153
154 def worker(self, q):

Callers 1

test_basicMethod · 0.95

Calls 11

qfullFunction · 0.85
assertTrueMethod · 0.80
assertFalseMethod · 0.80
do_blocking_testMethod · 0.80
qsizeMethod · 0.45
emptyMethod · 0.45
fullMethod · 0.45
putMethod · 0.45
getMethod · 0.45
assertEqualMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected