|
15 | 15 | from unittest.mock import patch, Mock
|
16 | 16 | from sagemaker.jumpstart.types import HubArnExtractedInfo
|
17 | 17 | from sagemaker.jumpstart.constants import JUMPSTART_DEFAULT_REGION_NAME
|
18 |
| -from sagemaker.jumpstart.hub import utils |
| 18 | +from sagemaker.jumpstart.hub import parser_utils, utils |
19 | 19 |
|
20 | 20 |
|
21 | 21 | def test_get_info_from_hub_resource_arn():
|
@@ -254,3 +254,50 @@ def test_get_hub_model_version_wildcard_char(mock_session):
|
254 | 254 | )
|
255 | 255 |
|
256 | 256 | assert result == "2.0.0"
|
| 257 | + |
| 258 | +def test_walk_and_apply_json(): |
| 259 | + test_json = { |
| 260 | + "CamelCaseKey": "value", |
| 261 | + "CamelCaseObjectKey": { |
| 262 | + "CamelCaseObjectChildOne": "value1", |
| 263 | + "CamelCaseObjectChildTwo": "value2", |
| 264 | + }, |
| 265 | + "IgnoreMyChildren": {"ShouldNotBeTouchedOne": "const1", "ShouldNotBeTouchedTwo": "const2"}, |
| 266 | + "ShouldNotIgnoreMyChildren": {"NopeNope": "no"}, |
| 267 | + } |
| 268 | + |
| 269 | + result = parser_utils.walk_and_apply_json( |
| 270 | + test_json, parser_utils.camel_to_snake, ["ignore_my_children"] |
| 271 | + ) |
| 272 | + assert result == { |
| 273 | + "camel_case_key": "value", |
| 274 | + "camel_case_object_key": { |
| 275 | + "camel_case_object_child_one": "value1", |
| 276 | + "camel_case_object_child_two": "value2", |
| 277 | + }, |
| 278 | + "ignore_my_children": { |
| 279 | + "ShouldNotBeTouchedOne": "const1", |
| 280 | + "ShouldNotBeTouchedTwo": "const2", |
| 281 | + }, |
| 282 | + "should_not_ignore_my_children": {"nope_nope": "no"}, |
| 283 | + } |
| 284 | + |
| 285 | +def test_walk_and_apply_json_no_stop(): |
| 286 | + test_json = { |
| 287 | + "CamelCaseKey": "value", |
| 288 | + "CamelCaseObjectKey": { |
| 289 | + "CamelCaseObjectChildOne": "value1", |
| 290 | + "CamelCaseObjectChildTwo": "value2", |
| 291 | + }, |
| 292 | + "CamelCaseObjectListKey": {"instance.ml.type.xlarge": [{"ShouldChangeMe": "string"}]}, |
| 293 | + } |
| 294 | + |
| 295 | + result = parser_utils.walk_and_apply_json(test_json, parser_utils.camel_to_snake) |
| 296 | + assert result == { |
| 297 | + "camel_case_key": "value", |
| 298 | + "camel_case_object_key": { |
| 299 | + "camel_case_object_child_one": "value1", |
| 300 | + "camel_case_object_child_two": "value2", |
| 301 | + }, |
| 302 | + "camel_case_object_list_key": {"instance.ml.type.xlarge": [{"should_change_me": "string"}]}, |
| 303 | + } |
0 commit comments