# Path: clients/python/lib/RpqLua.py
# class RpqLua:
#     def __init__(self, redisConnection):
#         '''Sets Redis connection, load LUA from path'''
# 
#         # Set Redis connection
#         self.setRedisConnection(redisConnection)
# 
#         # Load LUA source
#         self.loadSource(self.getLuaPath())
# 
#         # Register LUA script
#         self.register()
# 
#     def getLuaPath(self):
#         """
#             Returns the LUA path in the filesystem
#         """
# 
#         import rpq_src
#         import pkg_resources
# 
#         return pkg_resources.resource_filename('rpq_src', 'redis-priority-queue.lua')
# 
#     def file_get_contents(self, filename):
#         """
#             Get a file content
#         """
# 
#         with open(filename) as f:
#             return f.read()
# 
#     def setRedisConnection(self, connection):
#         """
#             Set a Redis connection
#         """
# 
#         self.connection = connection
# 
#         return True
# 
#     def loadSource(self, path):
#         """
#             Load LUA script source code from a file
#         """
# 
#         self.source = self.file_get_contents(path)
# 
#         return True
# 
#     def getSha1(self):
#         """
#             Calculate sha1 of the LUA source
#         """
# 
#         d = hashlib.sha1(self.source.encode('utf-8'))
#         d.digest()
#         return d.hexdigest()
# 
#     def exists(self):
#         """
#             Returns `True` if the LUA script is already loaded into Redis
#         """
# 
#         # Check if the script exists
#         t = self.connection.script_exists(self.sha1)
# 
#         if t and t[0]:
#             return True
# 
#         return False
# 
#     def load(self):
#         """
#             Load the script into Redis
#         """
# 
#         self.connection.script_load(self.source)
# 
#         return True
# 
#     def register(self):
#         """
#             Registers the script
#         """
# 
#         # Set LUA sha1
#         self.sha1 = self.getSha1()
# 
#         # Load if needed
#         if not self.exists():
#             self.load()
# 
#         return True
# 
#     def eval(self, *args):
#         """
#             Call the LUA script with the desired arguments and returns the output
#         """
# 
#         return self.connection.evalsha(self.sha1, 0, *args)


import unittest
import redis
from ..lib.RpqLua import RpqLua




class Test(unittest.TestCase):

    redis_host = '127.0.0.1'
    # redis_port = 8379
    redis_port = 6379
    redis_db = 0
    redis_password = ''
    lua_path = 'src/redis-priority-queue.lua'

    def setUp(self):
        # Redis instance
        self.r = redis.StrictRedis(
            host=self.redis_host, port=self.redis_port, db=self.redis_db, password=self.redis_password)

        # RpqQueue instance

# Path: clients/python/lib/RpqLua.py
# class RpqLua:
#     def __init__(self, redisConnection):
#         '''Sets Redis connection, load LUA from path'''
# 
#         # Set Redis connection
#         self.setRedisConnection(redisConnection)
# 
#         # Load LUA source
#         self.loadSource(self.getLuaPath())
# 
#         # Register LUA script
#         self.register()
# 
#     def getLuaPath(self):
#         """
#             Returns the LUA path in the filesystem
#         """
# 
#         import rpq_src
#         import pkg_resources
# 
#         return pkg_resources.resource_filename('rpq_src', 'redis-priority-queue.lua')
# 
#     def file_get_contents(self, filename):
#         """
#             Get a file content
#         """
# 
#         with open(filename) as f:
#             return f.read()
# 
#     def setRedisConnection(self, connection):
#         """
#             Set a Redis connection
#         """
# 
#         self.connection = connection
# 
#         return True
# 
#     def loadSource(self, path):
#         """
#             Load LUA script source code from a file
#         """
# 
#         self.source = self.file_get_contents(path)
# 
#         return True
# 
#     def getSha1(self):
#         """
#             Calculate sha1 of the LUA source
#         """
# 
#         d = hashlib.sha1(self.source.encode('utf-8'))
#         d.digest()
#         return d.hexdigest()
# 
#     def exists(self):
#         """
#             Returns `True` if the LUA script is already loaded into Redis
#         """
# 
#         # Check if the script exists
#         t = self.connection.script_exists(self.sha1)
# 
#         if t and t[0]:
#             return True
# 
#         return False
# 
#     def load(self):
#         """
#             Load the script into Redis
#         """
# 
#         self.connection.script_load(self.source)
# 
#         return True
# 
#     def register(self):
#         """
#             Registers the script
#         """
# 
#         # Set LUA sha1
#         self.sha1 = self.getSha1()
# 
#         # Load if needed
#         if not self.exists():
#             self.load()
# 
#         return True
# 
#     def eval(self, *args):
#         """
#             Call the LUA script with the desired arguments and returns the output
#         """
# 
#         return self.connection.evalsha(self.sha1, 0, *args)


# Path: clients/python/unittest/test_RpqLua.py
import unittest
import redis
from ..lib.RpqLua import RpqLua





class Test(unittest.TestCase):

    redis_host = '127.0.0.1'
    # redis_port = 8379
    redis_port = 6379
    redis_db = 0
    redis_password = ''
    lua_path = 'src/redis-priority-queue.lua'

    def setUp(self):
        # Redis instance
        self.r = redis.StrictRedis(
            host=self.redis_host, port=self.redis_port, db=self.redis_db, password=self.redis_password)

        # RpqQueue instance

        self.rl = RpqLua(self.r)