From efd293c1669a64920529dc8d42f6397289594da2 Mon Sep 17 00:00:00 2001 From: Cameron Devine Date: Mon, 27 Jan 2025 22:02:18 -0500 Subject: [PATCH 1/2] fixing a bug where the dict iterator was flattening nested lists --- himl/interpolation.py | 5 +---- tests/test_interpolation.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 tests/test_interpolation.py diff --git a/himl/interpolation.py b/himl/interpolation.py index b517753d..22416e68 100644 --- a/himl/interpolation.py +++ b/himl/interpolation.py @@ -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: diff --git a/tests/test_interpolation.py b/tests/test_interpolation.py new file mode 100644 index 00000000..2a48e68e --- /dev/null +++ b/tests/test_interpolation.py @@ -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 From 0bae969deb2ca2fa89e89e430edf84bdd1c4f056 Mon Sep 17 00:00:00 2001 From: Cameron Devine Date: Wed, 12 Feb 2025 15:44:24 -0800 Subject: [PATCH 2/2] himl requires pathlib2 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2c17bd90..4ec96e9a 100644 --- a/setup.py +++ b/setup.py @@ -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(