Ejemplo n.º 1
0
def test_mmqrz_select():
    with kauli.test.redis.RedisServer() as tredis:
        connect_db('localhost', tredis.port, 0)

        def setup(mmqrz):
            fruits = mmqrz.qadd('fruits', 200)
            fruits.put('apple')

            people = mmqrz.qadd('people', 150)
            people.put('Mike')

            mountains = mmqrz.qadd('mountains', 100)
            mountains.put('fuji', 3776)
            mountains.put('takao', 599)

        mmqrz = Mmqrz()

        setup(mmqrz)
        queue = mmqrz.qselect()
        eq_(queue.name, 'fruits')
        eq_(queue.get().value, 'apple')

        queue = mmqrz.qselect()
        eq_(queue.name, 'people')
        eq_(queue.get().value, 'Mike')

        queue = mmqrz.qselect()
        eq_(queue.name, 'mountains')
        eq_(queue.get().value, 'takao')

        queue = mmqrz.qselect()
        eq_(queue.name, 'mountains')
        eq_(queue.get().value, 'fuji')
Ejemplo n.º 2
0
def test_mmqrz():
    def assert_queues(got, expect):
        eq_([(x.name, x.score) for x in got], expect)

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

        mmqrz = Mmqrz()
        assert_queues(mmqrz.qall(), [])

        # add queues
        fruits = mmqrz.qadd('fruits')
        assert_true(isinstance(fruits, Queue))

        mmqrz.qadd('mountains', score=20)
        mmqrz.qadd('people', score=5)
        assert_queues(mmqrz.qall(),
                      [('mountains', 20.0), ('fruits', 10.0), ('people', 5.0)])

        # get queue
        people = mmqrz.qget('people')
        assert_true(isinstance(people, Queue))
        eq_(people.name, 'people')
        assert_raises(IndexError, mmqrz.qget, 'books')

        # remove queue
        mmqrz.qrem('fruits')
        assert_queues(mmqrz.qall(), [('mountains', 20.0), ('people', 5.0)])

        # qrem also delete tasks
        people.put('Mike')
        eq_(people.qsize(), 1)
        mmqrz.qrem('people')
        eq_(mmqrz.qadd('people').qsize(), 0)