Skip to content

Commit 742f8fb

Browse files
committed
fixed python tests comments
1 parent c4150d6 commit 742f8fb

File tree

3 files changed

+97
-344
lines changed

3 files changed

+97
-344
lines changed

tests/flow/includes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,11 @@ def check_error_message(env, con, error_msg, *command):
202202
exception = e
203203
env.assertEqual(type(exception), redis.exceptions.ResponseError)
204204
env.assertEqual(error_msg, str(exception))
205+
206+
def check_error(env, con, *command):
207+
try:
208+
con.execute_command(*command)
209+
env.assertFalse(True)
210+
except Exception as e:
211+
exception = e
212+
env.assertEqual(type(exception), redis.exceptions.ResponseError)

tests/flow/tests_deprecated_commands.py

Lines changed: 36 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,7 @@ def test_pytorch_scriptrun(env):
217217
return
218218

219219
con = env.getConnection()
220-
221-
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
222-
script_filename = os.path.join(test_data_path, 'script.txt')
223-
224-
with open(script_filename, 'rb') as f:
225-
script = f.read()
220+
script = load_file_content('script.txt')
226221

227222
ret = con.execute_command('AI.SCRIPTSET', 'myscript{1}', DEVICE, 'TAG', 'version1', 'SOURCE', script)
228223
env.assertEqual(ret, b'OK')
@@ -272,11 +267,7 @@ def test_pytorch_scriptrun_variadic(env):
272267

273268
con = env.getConnection()
274269

275-
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
276-
script_filename = os.path.join(test_data_path, 'script.txt')
277-
278-
with open(script_filename, 'rb') as f:
279-
script = f.read()
270+
script = load_file_content('script.txt')
280271

281272
ret = con.execute_command('AI.SCRIPTSET', 'myscript{$}', DEVICE, 'TAG', 'version1', 'SOURCE', script)
282273
env.assertEqual(ret, b'OK')
@@ -326,11 +317,7 @@ def test_pytorch_scriptrun_errors(env):
326317

327318
con = env.getConnection()
328319

329-
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
330-
script_filename = os.path.join(test_data_path, 'script.txt')
331-
332-
with open(script_filename, 'rb') as f:
333-
script = f.read()
320+
script = load_file_content('script.txt')
334321

335322
ret = con.execute_command('AI.SCRIPTSET', 'ket{1}', DEVICE, 'TAG', 'asdf', 'SOURCE', script)
336323
env.assertEqual(ret, b'OK')
@@ -342,84 +329,37 @@ def test_pytorch_scriptrun_errors(env):
342329

343330
ensureSlaveSynced(con, env)
344331

332+
con.execute_command('DEL', 'EMPTY{1}')
345333
# ERR no script at key from SCRIPTGET
346-
try:
347-
con.execute_command('DEL', 'EMPTY{1}')
348-
con.execute_command('AI.SCRIPTGET', 'EMPTY{1}')
349-
except Exception as e:
350-
exception = e
351-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
352-
env.assertEqual("script key is empty", exception.__str__())
334+
check_error_message(env, con, "script key is empty", 'AI.SCRIPTGET', 'EMPTY{1}')
353335

336+
con.execute_command('SET', 'NOT_SCRIPT{1}', 'BAR')
354337
# ERR wrong type from SCRIPTGET
355-
try:
356-
con.execute_command('SET', 'NOT_SCRIPT{1}', 'BAR')
357-
con.execute_command('AI.SCRIPTGET', 'NOT_SCRIPT{1}')
358-
except Exception as e:
359-
exception = e
360-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
361-
env.assertEqual("WRONGTYPE Operation against a key holding the wrong kind of value", exception.__str__())
338+
check_error_message(env, con, "WRONGTYPE Operation against a key holding the wrong kind of value", 'AI.SCRIPTGET', 'NOT_SCRIPT{1}')
362339

340+
con.execute_command('DEL', 'EMPTY{1}')
363341
# ERR no script at key from SCRIPTRUN
364-
try:
365-
con.execute_command('DEL', 'EMPTY{1}')
366-
con.execute_command('AI.SCRIPTRUN', 'EMPTY{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS', 'c{1}')
367-
except Exception as e:
368-
exception = e
369-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
370-
env.assertEqual("script key is empty", exception.__str__())
342+
check_error_message(env, con, "script key is empty", 'AI.SCRIPTRUN', 'EMPTY{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS', 'c{1}')
371343

344+
con.execute_command('SET', 'NOT_SCRIPT{1}', 'BAR')
372345
# ERR wrong type from SCRIPTRUN
373-
try:
374-
con.execute_command('SET', 'NOT_SCRIPT{1}', 'BAR')
375-
con.execute_command('AI.SCRIPTRUN', 'NOT_SCRIPT{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS', 'c{1}')
376-
except Exception as e:
377-
exception = e
378-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
379-
env.assertEqual("WRONGTYPE Operation against a key holding the wrong kind of value", exception.__str__())
346+
check_error_message(env, con, "WRONGTYPE Operation against a key holding the wrong kind of value", 'AI.SCRIPTRUN', 'NOT_SCRIPT{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS', 'c{1}')
380347

348+
con.execute_command('DEL', 'EMPTY{1}')
381349
# ERR Input key is empty
382-
try:
383-
con.execute_command('DEL', 'EMPTY{1}')
384-
con.execute_command('AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'EMPTY{1}', 'b{1}', 'OUTPUTS', 'c{1}')
385-
except Exception as e:
386-
exception = e
387-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
388-
env.assertEqual("tensor key is empty or in a different shard", exception.__str__())
350+
check_error_message(env, con, "tensor key is empty or in a different shard", 'AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'EMPTY{1}', 'b{1}', 'OUTPUTS', 'c{1}')
389351

352+
con.execute_command('SET', 'NOT_TENSOR{1}', 'BAR')
390353
# ERR Input key not tensor
391-
try:
392-
con.execute_command('SET', 'NOT_TENSOR{1}', 'BAR')
393-
con.execute_command('AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'NOT_TENSOR{1}', 'b{1}', 'OUTPUTS', 'c{1}')
394-
except Exception as e:
395-
exception = e
396-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
397-
env.assertEqual("WRONGTYPE Operation against a key holding the wrong kind of value", exception.__str__())
398-
399-
try:
400-
con.execute_command('AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS', 'c{1}')
401-
except Exception as e:
402-
exception = e
403-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
404-
405-
try:
406-
con.execute_command('AI.SCRIPTRUN', 'ket{1}', 'INPUTS', 'a{1}', 'b{1}', 'OUTPUTS', 'c{1}')
407-
except Exception as e:
408-
exception = e
409-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
410-
411-
try:
412-
con.execute_command('AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS')
413-
except Exception as e:
414-
exception = e
415-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
416-
417-
try:
418-
con.execute_command('AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'OUTPUTS')
419-
except Exception as e:
420-
exception = e
421-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
354+
check_error_message(env, con, "WRONGTYPE Operation against a key holding the wrong kind of value", 'AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'NOT_TENSOR{1}', 'b{1}', 'OUTPUTS', 'c{1}')
355+
356+
check_error(env, con, 'AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS', 'c{1}')
357+
358+
check_error(env, con, 'AI.SCRIPTRUN', 'ket{1}', 'INPUTS', 'a{1}', 'b{1}', 'OUTPUTS', 'c{1}')
359+
360+
check_error(env, con, 'AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'b{1}', 'OUTPUTS')
422361

362+
check_error(env, con, 'AI.SCRIPTRUN', 'ket{1}', 'bar', 'INPUTS', 'OUTPUTS')
423363

424364
def test_pytorch_scriptrun_variadic_errors(env):
425365
if not TEST_PT:
@@ -428,11 +368,7 @@ def test_pytorch_scriptrun_variadic_errors(env):
428368

429369
con = env.getConnection()
430370

431-
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
432-
script_filename = os.path.join(test_data_path, 'script.txt')
433-
434-
with open(script_filename, 'rb') as f:
435-
script = f.read()
371+
script = load_file_content('script.txt')
436372

437373
ret = con.execute_command('AI.SCRIPTSET', 'ket{$}', DEVICE, 'TAG', 'asdf', 'SOURCE', script)
438374
env.assertEqual(ret, b'OK')
@@ -444,45 +380,18 @@ def test_pytorch_scriptrun_variadic_errors(env):
444380

445381
ensureSlaveSynced(con, env)
446382

383+
con.execute_command('DEL', 'EMPTY{$}')
447384
# ERR Variadic input key is empty
448-
try:
449-
con.execute_command('DEL', 'EMPTY{$}')
450-
con.execute_command('AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'a{$}', '$', 'EMPTY{$}', 'b{$}', 'OUTPUTS', 'c{$}')
451-
except Exception as e:
452-
exception = e
453-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
454-
env.assertEqual("tensor key is empty or in a different shard", exception.__str__())
455-
385+
check_error_message(env, con, "tensor key is empty or in a different shard", 'AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'a{$}', '$', 'EMPTY{$}', 'b{$}', 'OUTPUTS', 'c{$}')
386+
387+
con.execute_command('SET', 'NOT_TENSOR{$}', 'BAR')
456388
# ERR Variadic input key not tensor
457-
try:
458-
con.execute_command('SET', 'NOT_TENSOR{$}', 'BAR')
459-
con.execute_command('AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'a{$}', '$' , 'NOT_TENSOR{$}', 'b{$}', 'OUTPUTS', 'c{$}')
460-
except Exception as e:
461-
exception = e
462-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
463-
env.assertEqual("WRONGTYPE Operation against a key holding the wrong kind of value", exception.__str__())
464-
465-
try:
466-
con.execute_command('AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'b{$}', '${$}', 'OUTPUTS', 'c{$}')
467-
except Exception as e:
468-
exception = e
469-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
470-
471-
try:
472-
con.execute_command('AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'b{$}', '$', 'OUTPUTS')
473-
except Exception as e:
474-
exception = e
475-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
476-
477-
try:
478-
con.execute_command('AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', '$', 'OUTPUTS')
479-
except Exception as e:
480-
exception = e
481-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
482-
483-
# "ERR Already encountered a variable size list of tensors"
484-
try:
485-
con.execute_command('AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', '$', 'a{$}', '$', 'b{$}' 'OUTPUTS')
486-
except Exception as e:
487-
exception = e
488-
env.assertEqual(type(exception), redis.exceptions.ResponseError)
389+
check_error_message(env, con, "WRONGTYPE Operation against a key holding the wrong kind of value", 'AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'a{$}', '$' , 'NOT_TENSOR{$}', 'b{$}', 'OUTPUTS', 'c{$}')
390+
391+
check_error(env, con, 'AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'b{$}', '${$}', 'OUTPUTS', 'c{$}')
392+
393+
check_error(env, con, 'AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', 'b{$}', '$', 'OUTPUTS')
394+
395+
check_error(env, con, 'AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', '$', 'OUTPUTS')
396+
397+
check_error_message(env, con, "Already encountered a variable size list of tensors", 'AI.SCRIPTRUN', 'ket{$}', 'bar_variadic', 'INPUTS', '$', 'a{$}', '$', 'b{$}' 'OUTPUTS')

0 commit comments

Comments
 (0)