@@ -226,6 +226,73 @@ def test_update_list_of_dicts_with_values_from_config():
226
226
{"a" : 1 , "b" : 2 , "c" : 3 },
227
227
{"a" : 5 , "c" : 6 , "d" : 8 },
228
228
]
229
+ # Same happy case with different order of items in union_key_paths
230
+ input_list = [{"a" : 1 , "b" : 2 }, {"a" : 5 , "c" : 6 }]
231
+ input_config_list = [
232
+ {
233
+ "a" : 4 , # This should not be used. Use values from Input.
234
+ "c" : 3 ,
235
+ },
236
+ {
237
+ "a" : 7 , # This should not be used. Use values from Input.
238
+ "d" : 8 ,
239
+ },
240
+ ]
241
+ ss .sagemaker_config .config = {"DUMMY" : {"CONFIG" : {"PATH" : input_config_list }}}
242
+ update_list_of_dicts_with_values_from_config (
243
+ input_list , config_path , union_key_paths = [["d" , "e" ], ["c" , "e" ]], sagemaker_session = ss
244
+ )
245
+ assert input_list == [
246
+ {"a" : 1 , "b" : 2 , "c" : 3 },
247
+ {"a" : 5 , "c" : 6 , "d" : 8 },
248
+ ]
249
+ # Testing the combination of union parameter and required parameter. i.e. A parameter is both
250
+ # required and part of Union.
251
+ input_list = [{"a" : 1 , "b" : 2 }, {"a" : 5 , "c" : 6 }]
252
+ input_config_list = [
253
+ {
254
+ "a" : 4 , # This should not be used. Use values from Input.
255
+ "c" : 3 ,
256
+ },
257
+ {
258
+ "a" : 7 , # This should not be used. Use values from Input.
259
+ "d" : 8 ,
260
+ },
261
+ ]
262
+ ss .sagemaker_config .config = {"DUMMY" : {"CONFIG" : {"PATH" : input_config_list }}}
263
+ update_list_of_dicts_with_values_from_config (
264
+ input_list ,
265
+ config_path ,
266
+ required_key_paths = ["e" ],
267
+ union_key_paths = [["d" , "e" ], ["c" , "e" ]],
268
+ sagemaker_session = ss ,
269
+ )
270
+ # No merge should happen since 'e' is not present, even though union is obeyed.
271
+ assert input_list == [{"a" : 1 , "b" : 2 }, {"a" : 5 , "c" : 6 }]
272
+ # Same test but the required parameter is present.
273
+ input_list = [{"a" : 1 , "e" : 2 }, {"a" : 5 , "e" : 6 }]
274
+ input_config_list = [
275
+ {
276
+ "a" : 4 , # This should not be used. Use values from Input.
277
+ "f" : 3 ,
278
+ },
279
+ {
280
+ "a" : 7 , # This should not be used. Use values from Input.
281
+ "g" : 8 ,
282
+ },
283
+ ]
284
+ ss .sagemaker_config .config = {"DUMMY" : {"CONFIG" : {"PATH" : input_config_list }}}
285
+ update_list_of_dicts_with_values_from_config (
286
+ input_list ,
287
+ config_path ,
288
+ required_key_paths = ["e" ],
289
+ union_key_paths = [["d" , "e" ], ["c" , "e" ]],
290
+ sagemaker_session = ss ,
291
+ )
292
+ assert input_list == [
293
+ {"a" : 1 , "e" : 2 , "f" : 3 },
294
+ {"a" : 5 , "e" : 6 , "g" : 8 },
295
+ ]
229
296
230
297
231
298
def test_set_nested_value ():
0 commit comments