本文整理匯總了Python中mockredis.script.Script._import_lua方法的典型用法代碼示例。如果您正苦於以下問題:Python Script._import_lua方法的具體用法?Python Script._import_lua怎麽用?Python Script._import_lua使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mockredis.script.Script
的用法示例。
在下文中一共展示了Script._import_lua方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup
# 需要導入模塊: from mockredis.script import Script [as 別名]
# 或者: from mockredis.script.Script import _import_lua [as 別名]
def setup(self):
self.redis = MockRedis(load_lua_dependencies=False)
self.LPOP_SCRIPT_SHA = sha1(LPOP_SCRIPT.encode("utf-8")).hexdigest()
try:
lua, lua_globals = MockRedisScript._import_lua(load_dependencies=False)
except RuntimeError:
raise SkipTest("mockredispy was not installed with lua support")
self.lua = lua
self.lua_globals = lua_globals
assert_equal_list = """
function compare_list(list1, list2)
if #list1 ~= #list2 then
return false
end
for i, item1 in ipairs(list1) do
if item1 ~= list2[i] then
return false
end
end
return true
end
function assert_equal_list(list1, list2)
assert(compare_list(list1, list2))
end
return assert_equal_list
"""
self.lua_assert_equal_list = self.lua.execute(assert_equal_list)
assert_equal_list_with_pairs = """
function pair_exists(list1, key, value)
i = 1
for i, item1 in ipairs(list1) do
if i%2 == 1 then
if (list1[i] == key) and (list1[i + 1] == value) then
return true
end
end
end
return false
end
function compare_list_with_pairs(list1, list2)
if #list1 ~= #list2 or #list1 % 2 == 1 then
return false
end
for i = 1, #list1, 2 do
if not pair_exists(list2, list1[i], list1[i + 1]) then
return false
end
end
return true
end
function assert_equal_list_with_pairs(list1, list2)
assert(compare_list_with_pairs(list1, list2))
end
return assert_equal_list_with_pairs
"""
self.lua_assert_equal_list_with_pairs = self.lua.execute(assert_equal_list_with_pairs)
compare_val = """
function compare_val(var1, var2)
return var1 == var2
end
return compare_val
"""
self.lua_compare_val = self.lua.execute(compare_val)