Example #1
0
def test_queue():
    with kauli.test.redis.RedisServer() as tredis:
        connect_db('localhost', tredis.port, 0)

        queue = Queue('fruits')
        assert_true(isinstance(queue, Queue))
        eq_(queue.name, 'fruits')
        eq_(queue.score, 10)

        queue.put('apple')
        queue.put('banana')
        queue.put('orange')
        eq_(queue.qsize(), 3)

        eq_(queue.get().value, 'apple')
        eq_(queue.get().value, 'banana')
        eq_(queue.get().value, 'orange')
        assert_raises(IndexError, queue.get)
        eq_(queue.qsize(), 0)

        # discard all tasks
        queue.put('apple')
        queue.put('banana')
        eq_(queue.qsize(), 2)
        queue.clear()
        eq_(queue.qsize(), 0)
Example #2
0
def test_queue_withscore():
    def assert_task(task, value, score):
        eq_(task.value, value)
        eq_(task.score, score)

    with kauli.test.redis.RedisServer() as tredis:
        connect_db('localhost', tredis.port, 0)

        queue = Queue('mountains', 20)
        eq_(queue.score, 20)

        queue.put('fuji', 3776)
        queue.put('takao', 599)
        queue.put('everest', 8848)

        assert_task(queue.get(), 'takao', 599)
        assert_task(queue.get(), 'fuji', 3776)
        assert_task(queue.get(), 'everest', 8848)
        assert_raises(IndexError, queue.get)