From 0b724f2491efb35fb3b45dd3bbb249ce909b5f77 Mon Sep 17 00:00:00 2001 From: Matt Shin Date: Mon, 8 Jul 2024 16:11:17 +0100 Subject: [PATCH] Fix include merge variable substitution Variable substitution did not work correctly at top level of include merge. --- src/yamlprocessor/dataprocess.py | 3 ++- src/yamlprocessor/tests/test_dataprocess.py | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/yamlprocessor/dataprocess.py b/src/yamlprocessor/dataprocess.py index cb8b31e..cf73cf0 100755 --- a/src/yamlprocessor/dataprocess.py +++ b/src/yamlprocessor/dataprocess.py @@ -364,7 +364,8 @@ def process_data(self, in_filename: str, out_filename: str) -> None: del data[key] item = None for include_key, include_item in include_data.items(): - data[include_key] = include_item + data[include_key] = self.process_variable( + include_item, variable_map) skip_keys.add(include_key) if ( isinstance(include_item, dict) diff --git a/src/yamlprocessor/tests/test_dataprocess.py b/src/yamlprocessor/tests/test_dataprocess.py index 52288bb..6944803 100644 --- a/src/yamlprocessor/tests/test_dataprocess.py +++ b/src/yamlprocessor/tests/test_dataprocess.py @@ -459,6 +459,7 @@ def test_main_13(tmp_path, yaml): cat_data = { 'chase': ['rodents', 'birds'], 'like': ['food', 'play', 'sleep'], + 'think': '$CAT_THINK', } infilename = tmp_path / 'root.yaml' with infilename.open('w') as infile: @@ -467,13 +468,18 @@ def test_main_13(tmp_path, yaml): with include_infilename.open('w') as infile: yaml.dump(cat_data, infile) outfilename = tmp_path / 'b.yaml' - main([str(infilename), str(outfilename)]) + main([ + str(infilename), + str(outfilename), + '-D', 'CAT_THINK=humans are cats', + ]) assert yaml.load(outfilename.open()) == { 'cat': { 'speak': ['meow', 'miaow'], 'young': 'kitten', 'chase': ['rodents', 'birds'], 'like': ['food', 'play', 'sleep'], + 'think': 'humans are cats', }, }