@@ -217,12 +217,7 @@ def test_pytorch_scriptrun(env):
217
217
return
218
218
219
219
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' )
226
221
227
222
ret = con .execute_command ('AI.SCRIPTSET' , 'myscript{1}' , DEVICE , 'TAG' , 'version1' , 'SOURCE' , script )
228
223
env .assertEqual (ret , b'OK' )
@@ -272,11 +267,7 @@ def test_pytorch_scriptrun_variadic(env):
272
267
273
268
con = env .getConnection ()
274
269
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' )
280
271
281
272
ret = con .execute_command ('AI.SCRIPTSET' , 'myscript{$}' , DEVICE , 'TAG' , 'version1' , 'SOURCE' , script )
282
273
env .assertEqual (ret , b'OK' )
@@ -326,11 +317,7 @@ def test_pytorch_scriptrun_errors(env):
326
317
327
318
con = env .getConnection ()
328
319
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' )
334
321
335
322
ret = con .execute_command ('AI.SCRIPTSET' , 'ket{1}' , DEVICE , 'TAG' , 'asdf' , 'SOURCE' , script )
336
323
env .assertEqual (ret , b'OK' )
@@ -342,84 +329,37 @@ def test_pytorch_scriptrun_errors(env):
342
329
343
330
ensureSlaveSynced (con , env )
344
331
332
+ con .execute_command ('DEL' , 'EMPTY{1}' )
345
333
# 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}' )
353
335
336
+ con .execute_command ('SET' , 'NOT_SCRIPT{1}' , 'BAR' )
354
337
# 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}' )
362
339
340
+ con .execute_command ('DEL' , 'EMPTY{1}' )
363
341
# 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}' )
371
343
344
+ con .execute_command ('SET' , 'NOT_SCRIPT{1}' , 'BAR' )
372
345
# 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}' )
380
347
348
+ con .execute_command ('DEL' , 'EMPTY{1}' )
381
349
# 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}' )
389
351
352
+ con .execute_command ('SET' , 'NOT_TENSOR{1}' , 'BAR' )
390
353
# 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' )
422
361
362
+ check_error (env , con , 'AI.SCRIPTRUN' , 'ket{1}' , 'bar' , 'INPUTS' , 'OUTPUTS' )
423
363
424
364
def test_pytorch_scriptrun_variadic_errors (env ):
425
365
if not TEST_PT :
@@ -428,11 +368,7 @@ def test_pytorch_scriptrun_variadic_errors(env):
428
368
429
369
con = env .getConnection ()
430
370
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' )
436
372
437
373
ret = con .execute_command ('AI.SCRIPTSET' , 'ket{$}' , DEVICE , 'TAG' , 'asdf' , 'SOURCE' , script )
438
374
env .assertEqual (ret , b'OK' )
@@ -444,45 +380,18 @@ def test_pytorch_scriptrun_variadic_errors(env):
444
380
445
381
ensureSlaveSynced (con , env )
446
382
383
+ con .execute_command ('DEL' , 'EMPTY{$}' )
447
384
# 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' )
456
388
# 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