1515 LIST1 , LIST2 ,
1616 SET1 ,
1717 VAL1 , VAL2 , VAL3 , VAL4 ,
18+ bVAL1 , bVAL2 , bVAL3 , bVAL4 ,
1819 LPOP_SCRIPT
1920)
20- from mockredis .tests .fixtures import raises_response_error
2121
2222
2323if sys .version_info >= (3 , 0 ):
2424 long = int
25+ string_types = (str , )
26+ else :
27+ string_types = (basestring , )
2528
2629
2730class TestScript (object ):
@@ -108,7 +111,7 @@ def test_register_script_lpush(self):
108111 script (keys = [LIST1 ], args = [VAL1 , VAL2 ])
109112
110113 # validate insertion
111- eq_ ([VAL2 , VAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
114+ eq_ ([bVAL2 , bVAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
112115
113116 def test_register_script_lpop (self ):
114117 self .redis .lpush (LIST1 , VAL2 , VAL1 )
@@ -120,7 +123,7 @@ def test_register_script_lpop(self):
120123
121124 # validate lpop
122125 eq_ (VAL1 , list_item )
123- eq_ ([VAL2 ], self .redis .lrange (LIST1 , 0 , - 1 ))
126+ eq_ ([bVAL2 ], self .redis .lrange (LIST1 , 0 , - 1 ))
124127
125128 def test_register_script_rpoplpush (self ):
126129 self .redis .lpush (LIST1 , VAL2 , VAL1 )
@@ -132,8 +135,8 @@ def test_register_script_rpoplpush(self):
132135 script (keys = [LIST1 , LIST2 ])
133136
134137 # validate rpoplpush
135- eq_ ([VAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
136- eq_ ([VAL2 , VAL3 , VAL4 ], self .redis .lrange (LIST2 , 0 , - 1 ))
138+ eq_ ([bVAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
139+ eq_ ([bVAL2 , bVAL3 , bVAL4 ], self .redis .lrange (LIST2 , 0 , - 1 ))
137140
138141 def test_register_script_rpop_lpush (self ):
139142 self .redis .lpush (LIST1 , VAL2 , VAL1 )
@@ -148,8 +151,8 @@ def test_register_script_rpop_lpush(self):
148151 script (keys = [LIST1 , LIST2 ])
149152
150153 # validate rpop and then lpush
151- eq_ ([VAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
152- eq_ ([VAL2 , VAL3 , VAL4 ], self .redis .lrange (LIST2 , 0 , - 1 ))
154+ eq_ ([bVAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
155+ eq_ ([bVAL2 , bVAL3 , bVAL4 ], self .redis .lrange (LIST2 , 0 , - 1 ))
153156
154157 def test_register_script_client (self ):
155158 # lpush two values in LIST1 in first instance of redis
@@ -168,16 +171,16 @@ def test_register_script_client(self):
168171
169172 # validate lpop from LIST1 in redis2
170173 eq_ (VAL3 , list_item )
171- eq_ ([VAL4 ], redis2 .lrange (LIST1 , 0 , - 1 ))
172- eq_ ([VAL1 , VAL2 ], self .redis .lrange (LIST1 , 0 , - 1 ))
174+ eq_ ([bVAL4 ], redis2 .lrange (LIST1 , 0 , - 1 ))
175+ eq_ ([bVAL1 , bVAL2 ], self .redis .lrange (LIST1 , 0 , - 1 ))
173176
174177 def test_eval_lpush (self ):
175178 # lpush two values
176179 script_content = "redis.call('LPUSH', KEYS[1], ARGV[1], ARGV[2])"
177180 self .redis .eval (script_content , 1 , LIST1 , VAL1 , VAL2 )
178181
179182 # validate insertion
180- eq_ ([VAL2 , VAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
183+ eq_ ([bVAL2 , bVAL1 ], self .redis .lrange (LIST1 , 0 , - 1 ))
181184
182185 def test_eval_lpop (self ):
183186 self .redis .lpush (LIST1 , VAL2 , VAL1 )
@@ -188,7 +191,7 @@ def test_eval_lpop(self):
188191
189192 # validate lpop
190193 eq_ (VAL1 , list_item )
191- eq_ ([VAL2 ], self .redis .lrange (LIST1 , 0 , - 1 ))
194+ eq_ ([bVAL2 ], self .redis .lrange (LIST1 , 0 , - 1 ))
192195
193196 def test_eval_lrem (self ):
194197 self .redis .delete (LIST1 )
@@ -318,7 +321,7 @@ def test_lua_to_python_flota(self):
318321 def test_lua_to_python_string (self ):
319322 lval = self .lua .eval ('"somestring"' )
320323 pval = MockRedisScript ._lua_to_python (lval )
321- ok_ (isinstance (pval , str ))
324+ ok_ (isinstance (pval , string_types ))
322325 eq_ ("somestring" , pval )
323326
324327 def test_lua_to_python_bool (self ):
@@ -383,11 +386,24 @@ def test_lua_ok_return(self):
383386 script = self .redis .register_script (script_content )
384387 eq_ ('OK' , script ())
385388
386- @raises_response_error
387389 def test_lua_err_return (self ):
388390 script_content = "return {err='ERROR Some message'}"
389391 script = self .redis .register_script (script_content )
390- script ()
392+ with assert_raises (Exception ) as error_context :
393+ script ()
394+ eq_ ('ERROR Some message' , error_context .exception .args [0 ])
395+
396+ def test_lua_redis_status_reply (self ):
397+ script_content = "return redis.status_reply('OK')"
398+ script = self .redis .register_script (script_content )
399+ eq_ ('OK' , script ())
400+
401+ def test_lua_redis_error_reply (self ):
402+ script_content = "return redis.error_reply('my error')"
403+ script = self .redis .register_script (script_content )
404+ with assert_raises (Exception ) as error_context :
405+ script ()
406+ eq_ ('my error' , error_context .exception .args [0 ])
391407
392408 def test_concurrent_lua (self ):
393409 script_content = """
0 commit comments