Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing a bug where himl flattens nested lists #175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions himl/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ def loop_all_items(self, data, process_func):
if isinstance(data, list):
items = []
for item in data:
if isinstance(item, list):
items.extend(item)
else:
items.append(self.loop_all_items(item, process_func))
items.append(self.loop_all_items(item, process_func))
return items
if isinstance(data, dict):
for key in data:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'backports.functools_lru_cache==1.6.6',
'pyyaml~=6.0.2',
'boto3~=1.35.94',
'hvac~=2.3.0'
'hvac~=2.3.0',
'pathlib2'
]

setup(
Expand Down
37 changes: 37 additions & 0 deletions tests/test_interpolation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2019 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

from pytest import mark
from himl.interpolation import DictIterator


@mark.parametrize(
"start, end, func",
[
(
{"test": [1, 3, 2], "another": {"thing": "is", "some": "data"}},
{"test": [1, 3, 2], "another": {"thing": "is", "some": "data"}},
lambda x: x,
),
(
{"test": [1, 3, 2], "another": {"thing": "is", "some": "data"}},
{"test": [1, 3, 2], "another": {"thing": "isis", "some": "datadata"}},
lambda x: 2 * x,
),
(
[["a", "set"], ["of", "test"], ["data", "for", "testing"], [1, 2, 3]],
[["a_", "set_"], ["of_", "test_"], ["data_", "for_", "testing_"], [1, 2, 3]],
lambda x: x + "_",
),
],
)
def test_dict_iterator(start, end, func):
looper = DictIterator()
assert looper.loop_all_items(start, func) == end