# Path: clients/python/lib/RpqQueue.py
# class RpqQueue:
# 
#     def __init__(self, redis, queueName):
#         """
#             Registers RpqLua queue from a Redis connection
#         """
# 
#         # RpqLua instance
#         self.queue = RpqLua(redis)
# 
#         # Set queue name
#         self.setqueueName(queueName)
# 
#     def eval(self, args):
#         return self.queue.eval(*args)
# 
#     def bytesDecode(self, item):
#         """
#             Decode Bytes to utf-8 for Python 3 compatibility
#         """
# 
#         return item.decode("utf-8")
# 
#     def setqueueName(self, queueName):
#         """
#             Define loaded queue name at class level
#         """
# 
#         self.queueName = queueName
# 
#     def push(self, item, priority=None):
#         """
#             Push an item
#         """
# 
#         # Build arg list
#         args = ['push', self.queueName, item]
#         if priority is not None:
#             args.append(priority)
# 
#         return self.eval(args)
# 
#     def pop(self, orderBy='desc'):
#         """
#             alias for popOne()
#         """
# 
#         return self.popOne(orderBy)
# 
#     def popOne(self, orderBy='desc'):
#         """
#             Pop an item
#         """
# 
#         item = self.popMany(orderBy, 1)
# 
#         if item:  # There is an item
#             return item[0]
#         else:
#             return None
# 
#     def popMany(self, orderBy='desc', numberOfItems=1):
#         """
#             Pop many items
#         """
# 
#         items = self.eval(['pop', self.queueName, orderBy, numberOfItems])
#         if items:
#             # Decode all items from bytes to utf-8
#             items = tuple(map(self.bytesDecode, items))
# 
#             return items
#         else:
#             return None
# 
#     def peek(self, orderBy='desc'):
#         """
#             alias for peekOne()
#         """
# 
#         return self.peekOne(orderBy)
# 
#     def peekOne(self, orderBy='desc'):
#         """
#             Peek an item
#         """
# 
#         item = self.peekMany(orderBy, 1)
# 
#         if item:  # There is an item
#             return item[0]
#         else:
#             return None
# 
#     def peekMany(self, orderBy='desc', numberOfItems=1):
#         """
#             Peek many items
#         """
# 
#         items = self.eval(['peek', self.queueName, orderBy, numberOfItems])
#         if items:
#             # Decode all items from bytes to utf-8
#             items = tuple(map(self.bytesDecode, items))
# 
#             return items
#         else:
#             return None
# 
#     def count(self, priorityMin=None, priorityMax=None):
#         """
#             Get queue size
#         """
# 
#         # Build arg list
#         args = ['size', self.queueName]
#         if priorityMin is not None:
#             args.append(priorityMin)
#             if priorityMax is not None:
#                 args.append(priorityMax)
# 
#         return self.eval(args)


import unittest
import redis
from ..lib.RpqQueue import RpqQueue
    def test_setqueueName(self):
        self.rq.setqueueName('some_queue')

        self.assertEqual(self.rq.queueName, 'some_queue')

    def test_push(self):
        self.assertTrue(self.rq.push('item') in [0, 1])

    def test_pop(self):
        self.rq.setqueueName('test_pop')
        self.rq.push('my_item')
        self.assertEqual(self.rq.pop(), 'my_item')

        self.rq.setqueueName('test_pop_empty')
        self.assertIsNone(self.rq.pop())

    def test_popOne(self):
        self.rq.setqueueName('test_popOne')
        self.rq.push('my_item')
        self.assertEqual(self.rq.popOne(), 'my_item')

        self.rq.setqueueName('test_popOne_empty')
        self.assertIsNone(self.rq.popOne())

    def test_popMany(self):
        self.rq.setqueueName('test_popMany')
        self.rq.push('my_item')
        self.rq.push('my_item_2')
        self.rq.push('my_item_3')
        self.assertEqual(self.rq.popMany('desc', 3),

# Path: clients/python/lib/RpqQueue.py
# class RpqQueue:
# 
#     def __init__(self, redis, queueName):
#         """
#             Registers RpqLua queue from a Redis connection
#         """
# 
#         # RpqLua instance
#         self.queue = RpqLua(redis)
# 
#         # Set queue name
#         self.setqueueName(queueName)
# 
#     def eval(self, args):
#         return self.queue.eval(*args)
# 
#     def bytesDecode(self, item):
#         """
#             Decode Bytes to utf-8 for Python 3 compatibility
#         """
# 
#         return item.decode("utf-8")
# 
#     def setqueueName(self, queueName):
#         """
#             Define loaded queue name at class level
#         """
# 
#         self.queueName = queueName
# 
#     def push(self, item, priority=None):
#         """
#             Push an item
#         """
# 
#         # Build arg list
#         args = ['push', self.queueName, item]
#         if priority is not None:
#             args.append(priority)
# 
#         return self.eval(args)
# 
#     def pop(self, orderBy='desc'):
#         """
#             alias for popOne()
#         """
# 
#         return self.popOne(orderBy)
# 
#     def popOne(self, orderBy='desc'):
#         """
#             Pop an item
#         """
# 
#         item = self.popMany(orderBy, 1)
# 
#         if item:  # There is an item
#             return item[0]
#         else:
#             return None
# 
#     def popMany(self, orderBy='desc', numberOfItems=1):
#         """
#             Pop many items
#         """
# 
#         items = self.eval(['pop', self.queueName, orderBy, numberOfItems])
#         if items:
#             # Decode all items from bytes to utf-8
#             items = tuple(map(self.bytesDecode, items))
# 
#             return items
#         else:
#             return None
# 
#     def peek(self, orderBy='desc'):
#         """
#             alias for peekOne()
#         """
# 
#         return self.peekOne(orderBy)
# 
#     def peekOne(self, orderBy='desc'):
#         """
#             Peek an item
#         """
# 
#         item = self.peekMany(orderBy, 1)
# 
#         if item:  # There is an item
#             return item[0]
#         else:
#             return None
# 
#     def peekMany(self, orderBy='desc', numberOfItems=1):
#         """
#             Peek many items
#         """
# 
#         items = self.eval(['peek', self.queueName, orderBy, numberOfItems])
#         if items:
#             # Decode all items from bytes to utf-8
#             items = tuple(map(self.bytesDecode, items))
# 
#             return items
#         else:
#             return None
# 
#     def count(self, priorityMin=None, priorityMax=None):
#         """
#             Get queue size
#         """
# 
#         # Build arg list
#         args = ['size', self.queueName]
#         if priorityMin is not None:
#             args.append(priorityMin)
#             if priorityMax is not None:
#                 args.append(priorityMax)
# 
#         return self.eval(args)


# Path: clients/python/unittest/test_RpqQueue.py
import unittest
import redis
from ..lib.RpqQueue import RpqQueue

    def test_setqueueName(self):
        self.rq.setqueueName('some_queue')

        self.assertEqual(self.rq.queueName, 'some_queue')

    def test_push(self):
        self.assertTrue(self.rq.push('item') in [0, 1])

    def test_pop(self):
        self.rq.setqueueName('test_pop')
        self.rq.push('my_item')
        self.assertEqual(self.rq.pop(), 'my_item')

        self.rq.setqueueName('test_pop_empty')
        self.assertIsNone(self.rq.pop())

    def test_popOne(self):
        self.rq.setqueueName('test_popOne')
        self.rq.push('my_item')
        self.assertEqual(self.rq.popOne(), 'my_item')

        self.rq.setqueueName('test_popOne_empty')
        self.assertIsNone(self.rq.popOne())

    def test_popMany(self):
        self.rq.setqueueName('test_popMany')
        self.rq.push('my_item')
        self.rq.push('my_item_2')
        self.rq.push('my_item_3')
        self.assertEqual(self.rq.popMany('desc', 3),

                         ('my_item_3', 'my_item_2', 'my_item'))