def test_bidirectional_put(): queue = MultiQueue() queue.put(1) queue.append(2) queue.appendleft(3) assert_equal(queue.get(), (2, 'default')) assert_equal(queue.get(), (1, 'default')) assert_equal(queue.get(), (3, 'default'))
def test_noarg_multiqueue_works_like_standard_queue(): queue = MultiQueue() queue.put(1) queue.put(2) value, _ = queue.get() assert_equal(value, 1) value, _ = queue.get() assert_equal(value, 2)
def test_get_from_many_queues(): queue = MultiQueue(['q1', 'q2']) queue.put(1, 'q1') queue.put(2, 'q2') value, from_queue = queue.get(['q1', 'q2']) assert_equal(value, 1) assert_equal(from_queue, 'q1') value, from_queue = queue.get(['q1', 'q2']) assert_equal(value, 2) assert_equal(from_queue, 'q2')
def test_select_queue_to_get_from(): queue = MultiQueue(['q1', 'q2']) queue.put(1, 'q1') queue.put(2, 'q2') value, from_queue = queue.get(['q2']) assert_equal(value, 2) assert_equal(from_queue, 'q2')
def test_access_specific_queue(): queue = MultiQueue(['myqueue']) queue.put(1, 'myqueue') value, from_queue = queue.get(['myqueue']) assert_equal(value, 1) assert_equal(from_queue, 'myqueue')
def test_unsuccessful_nonblocking_get(): queue = MultiQueue() with assert_raises(Empty): queue.get(blocking=False)
def test_successful_nonblocking_get(): queue = MultiQueue() queue.put(1) assert_equal(queue.get(blocking=False), (1, 'default'))
def test_get_from_nonexistent_queue(): queue = MultiQueue(['q1']) queue.get(['q1', 'q2'])