本文整理汇总了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)