@@ -12,38 +12,24 @@ def wrapper(env, *args, **kwargs):
1212 modules = con .execute_command ("MODULE" , "LIST" )
1313 if b'rg' in [module [1 ] for module in modules ]:
1414 return f (env , * args , ** kwargs )
15+ platform = paella .Platform ()
16+ redisgears_dir = "{ROOT}/bin/{PLATFORM}/RedisGears" .format (ROOT = ROOT , PLATFORM = platform .triplet ())
17+ if not os .path .isdir (redisgears_dir ):
18+ env .debugPrint ("RedisGears directory does not exist" , force = True )
19+ return
20+ redisgears_path = os .path .join (redisgears_dir , 'redisgears.so' )
21+ python_plugin_path = os .path .join (redisgears_dir , 'plugin/gears_python.so' )
1522 try :
16- platform = paella .Platform ()
17- redisgears_dir = "{ROOT}/bin/{PLATFORM}/RedisGears" .format (ROOT = ROOT , PLATFORM = platform .triplet ())
18- redisgears_path = os .path .join (redisgears_dir , 'redisgears.so' )
19- python_plugin_path = os .path .join (redisgears_dir , 'plugin/gears_python.so' )
2023 ret = con .execute_command ('MODULE' , 'LOAD' , redisgears_path , 'Plugin' , python_plugin_path , 'CreateVenv' ,
2124 0 , 'PythonInstallationDir' , redisgears_dir )
2225 env .assertEqual (ret , b'OK' )
23- except Exception as e :
24- env .debugPrint (str (e ), force = True )
26+ except Exception :
2527 env .debugPrint ("skipping since RedisGears not loaded" , force = True )
2628 return
2729 return f (env , * args , ** kwargs )
2830 return wrapper
2931
3032
31- @skip_if_gears_not_loaded
32- def test_ping_gears (env ):
33-
34- script = '''
35- def ping(record):
36- return "pong"
37-
38- GB("CommandReader").map(ping).register(trigger="ping_test")
39- '''
40- con = env .getConnection ()
41- ret = con .execute_command ('rg.pyexecute' , script )
42- env .assertEqual (ret , b'OK' )
43- ret = con .execute_command ('rg.trigger' , 'ping_test' )
44- env .assertEqual (ret [0 ], b'pong' )
45-
46-
4733@skip_if_gears_not_loaded
4834def test_model_run (env ):
4935 script = '''
@@ -56,7 +42,7 @@ def ModelRun_oldAPI(record):
5642 modelRunner = redisAI.createModelRunner('m{1}')
5743 redisAI.modelRunnerAddInput(modelRunner, 'a', tensors[0])
5844 redisAI.modelRunnerAddInput(modelRunner, 'b', tensors[1])
59- redisAI.modelRunnerAddOutput(modelRunner, 'mul ')
45+ redisAI.modelRunnerAddOutput(modelRunner, 'c ')
6046 res = redisAI.modelRunnerRun(modelRunner)
6147 redisAI.setTensorInKey('c{1}', res[0])
6248 return "ModelRun_oldAPI_OK"
@@ -67,7 +53,7 @@ async def ModelRun_Async(record):
6753 modelRunner = redisAI.createModelRunner('m{1}')
6854 redisAI.modelRunnerAddInput(modelRunner, 'a', tensors[0])
6955 redisAI.modelRunnerAddInput(modelRunner, 'b', tensors[1])
70- redisAI.modelRunnerAddOutput(modelRunner, 'mul ')
56+ redisAI.modelRunnerAddOutput(modelRunner, 'c ')
7157 res = await redisAI.modelRunnerRunAsync(modelRunner)
7258 redisAI.setTensorInKey('c{1}', res[0])
7359 return "ModelRun_Async_OK"
@@ -108,6 +94,8 @@ async def ModelRun_AsyncRunError(record):
10894 env .assertEqual (ret [0 ], b'ModelRun_oldAPI_OK' )
10995 values = con .execute_command ('AI.TENSORGET' , 'c{1}' , 'VALUES' )
11096 env .assertEqual (values , [b'4' , b'9' , b'4' , b'9' ])
97+ ret = con .execute_command ('DEL' , 'c{1}' )
98+ env .assertEqual (ret , 1 )
11199
112100 ret = con .execute_command ('rg.trigger' , 'ModelRun_Async_test2' )
113101 env .assertEqual (ret [0 ], b'ModelRun_Async_OK' )
@@ -186,6 +174,8 @@ async def ScriptRun_AsyncRunError(record):
186174 env .assertEqual (ret [0 ], b'ScriptRun_oldAPI_OK' )
187175 values = con .execute_command ('AI.TENSORGET' , 'c{1}' , 'VALUES' )
188176 env .assertEqual (values , [b'4' , b'6' , b'4' , b'6' ])
177+ ret = con .execute_command ('DEL' , 'c{1}' )
178+ env .assertEqual (ret , 1 )
189179
190180 ret = con .execute_command ('rg.trigger' , 'ScriptRun_Async_test2' )
191181 env .assertEqual (ret [0 ], b'ScriptRun_Async_OK' )
@@ -194,8 +184,7 @@ async def ScriptRun_AsyncRunError(record):
194184
195185 ret = con .execute_command ('rg.trigger' , 'ScriptRun_AsyncRunError_test3' )
196186 # This should raise an exception
197- error_string = b'attempted to get undefined function bad_func'
198- env .assertEqual (str (ret [0 ])[:len (error_string )+ 2 ]+ "'" , "{}" .format (error_string ))
187+ env .assertTrue (str (ret [0 ]).startswith ("b'attempted to get undefined function bad_func" ))
199188
200189
201190@skip_if_gears_not_loaded
@@ -314,9 +303,7 @@ async def DAGRun_addOpsFromString(record):
314303
315304 ret = con .execute_command ('rg.trigger' , 'DAGRun_test4' )
316305 # This should raise an exception
317-
318- error_string = b'attempted to get undefined function no_func'
319- env .assertEqual (str (ret [0 ])[:len (error_string )+ 2 ]+ "'" , "{}" .format (error_string ))
306+ env .assertTrue (str (ret [0 ]).startswith ("b'attempted to get undefined function no_func" ))
320307
321308 ret = con .execute_command ('rg.trigger' , 'DAGRun_test5' )
322309 env .assertEqual (ret [0 ], b'test5_OK' )
0 commit comments