@@ -297,29 +297,57 @@ def square(x):
297
297
@pytest .mark .parametrize (
298
298
"args, kwargs, error_message" ,
299
299
[
300
- ((1 , 2 ), {}, "decorated_function() missing 1 required keyword-only argument: 'c'" ),
301
300
(
302
- ( 1 , 2 ) ,
303
- {"c" : 3 , "d" : 4 , "e" : "extra_arg" },
304
- "decorated_function() got an unexpected keyword argument 'e'" ,
301
+ [ 1 , 2 , 3 ] ,
302
+ {},
303
+ "decorated_function() missing 2 required keyword-only arguments: 'd', and 'e'" ,
305
304
),
306
- ((), { "c" : 3 , "d" : 4 }, "decorated_function() missing 1 required positional argument: 'a '" ),
305
+ ([ 1 , 2 , 3 ], { "d" : 4 }, "decorated_function() missing 1 required keyword-only argument: 'e '" ),
307
306
(
308
- (1 , 2 , "extra_Arg" ),
307
+ [1 , 2 , 3 ],
308
+ {"d" : 3 , "e" : 4 , "g" : "extra_arg" },
309
+ "decorated_function() got an unexpected keyword argument 'g'" ,
310
+ ),
311
+ (
312
+ [],
309
313
{"c" : 3 , "d" : 4 },
310
- "decorated_function() takes 2 positional arguments but 3 were given." ,
314
+ "decorated_function() missing 2 required positional arguments: 'a', and 'b'" ,
315
+ ),
316
+ ([1 ], {"c" : 3 , "d" : 4 }, "decorated_function() missing 1 required positional argument: 'b'" ),
317
+ (
318
+ [1 , 2 , 3 , "extra_arg" ],
319
+ {"d" : 3 , "e" : 4 },
320
+ "decorated_function() takes 3 positional arguments but 4 were given." ,
321
+ ),
322
+ ([], {"a" : 1 , "b" : 2 , "d" : 3 , "e" : 2 }, None ),
323
+ (
324
+ (1 , 2 ),
325
+ {"a" : 1 , "c" : 3 , "d" : 2 },
326
+ "decorated_function() got multiple values for argument 'a'" ,
327
+ ),
328
+ (
329
+ (1 , 2 ),
330
+ {"b" : 1 , "c" : 3 , "d" : 2 },
331
+ "decorated_function() got multiple values for argument 'b'" ,
311
332
),
312
333
],
313
334
)
314
- def test_decorator_invalid_function_args (args , kwargs , error_message ):
335
+ @patch ("sagemaker.remote_function.client._JobSettings" )
336
+ @patch ("sagemaker.remote_function.client._Job.start" )
337
+ def test_decorator_invalid_function_args (job_start , job_settings , args , kwargs , error_message ):
315
338
@remote (image_uri = IMAGE , s3_root_uri = S3_URI )
316
- def decorated_function (a , b = 1 , * , c , d = 3 ):
317
- return a * b * c * d
318
-
319
- with pytest .raises (TypeError ) as e :
320
- decorated_function (* args , ** kwargs )
321
-
322
- assert error_message in str (e .value )
339
+ def decorated_function (a , b , c = 1 , * , d , e , f = 3 ):
340
+ return a * b * c * d * e * f
341
+
342
+ if error_message :
343
+ with pytest .raises (TypeError ) as e :
344
+ decorated_function (* args , ** kwargs )
345
+ assert error_message in str (e .value )
346
+ else :
347
+ try :
348
+ decorated_function (* args , ** kwargs )
349
+ except Exception as ex :
350
+ pytest .fail ("Unexpected Exception: " + str (ex ))
323
351
324
352
325
353
def test_executor_invalid_arguments ():
0 commit comments