diff --git a/src/rougail/convert/convert.py b/src/rougail/convert/convert.py index ef9439401..210f984f3 100644 --- a/src/rougail/convert/convert.py +++ b/src/rougail/convert/convert.py @@ -408,7 +408,7 @@ class ParserVariable: exists = obj.pop("exists", None) else: exists = None - redefine = obj.pop("redefine", False) or force_redefine is True + redefine = obj.pop("redefine", False) or (force_redefine is True and path in self.paths) obj_type = self.get_family_or_variable_type(obj) force_to_attrs = list(self.list_attributes(obj, sources, obj_type)) for key, value in obj.items(): @@ -699,7 +699,7 @@ class ParserVariable: self.parse_params(path, obj, sources) self.parse_secret_manager(path, obj, sources, family_is_dynamic, copy_before_set) exists = obj.pop("exists", None) - redefine = obj.pop("redefine", False) or force_redefine is True + redefine = obj.pop("redefine", False) or (force_redefine is True and path in self.paths) if not redefine and not exists: obj_type = obj.get("type") if obj_type in self.custom_variable_types: diff --git a/tests/test_types.py b/tests/test_types.py index 538933a84..fa4b4d457 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -81,3 +81,7 @@ def test_type_variable_hidden(): def test_type_dynfamily(): type_variable("family_dynfamily") + + +def test_type_family_subfamily_add(): + type_variable("family_subfamily_add") diff --git a/tests/types/result/family_subfamily_add/tiramisu.py b/tests/types/result/family_subfamily_add/tiramisu.py new file mode 100644 index 000000000..cc1e1ce86 --- /dev/null +++ b/tests/types/result/family_subfamily_add/tiramisu.py @@ -0,0 +1,28 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_3 = StrOption(name="a_first_variable", doc="a first variable", default="a modified value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +option_5 = StrOption(name="a_second_variable", doc="a second variable", default="a modified value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +optiondescription_4 = OptionDescription(name="a_sub_family", doc="My subfamily", children=[option_5], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml']}) +option_7 = StrOption(name="a_second_variable", doc="a_second_variable", default="a modified value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/structures/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +optiondescription_6 = OptionDescription(name="a_new_subfamily", doc="a_new_subfamily", children=[option_7], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/structures/family_subfamily_add/00_structure.yml']}) +optiondescription_2 = OptionDescription(name="my_family_1", doc="My family type", children=[option_3, optiondescription_4, optiondescription_6], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml']}) +option_9 = StrOption(name="a_first_variable", doc="a first variable", default="a value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +option_11 = StrOption(name="a_second_variable", doc="a second variable", properties=frozenset({"basic", "mandatory"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +optiondescription_10 = OptionDescription(name="a_sub_family", doc="My subfamily", children=[option_11], properties=frozenset({"basic"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml']}) +optiondescription_8 = OptionDescription(name="my_family_2", doc="My family type", children=[option_9, optiondescription_10], properties=frozenset({"basic"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml']}) +option_13 = StrOption(name="a_first_variable", doc="a first variable", default="a value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +option_15 = StrOption(name="a_second_variable", doc="a second variable", default="a modified value 2", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +optiondescription_14 = OptionDescription(name="a_sub_family", doc="My subfamily", children=[option_15], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml']}) +option_16 = StrOption(name="a_new_variable", doc="a_new_variable", default="a modified value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/structures/family_subfamily_add/00_structure.yml'], 'type': 'string'}) +optiondescription_12 = OptionDescription(name="my_family_3", doc="My family type", children=[option_13, optiondescription_14, option_16], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/family_subfamily_add/00_structure.yml', 'tests/types/structures/family_subfamily_add/00_structure.yml']}) +optiondescription_1 = OptionDescription(name="rougail", doc="rougail", group_type=groups.namespace, children=[optiondescription_2, optiondescription_8, optiondescription_12], properties=frozenset({"basic"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/types/result/family_subfamily_add/variables.json b/tests/types/result/family_subfamily_add/variables.json new file mode 100644 index 000000000..8236df3cf --- /dev/null +++ b/tests/types/result/family_subfamily_add/variables.json @@ -0,0 +1,10 @@ +{ + "rougail.my_family_1.a_first_variable": "a modified value", + "rougail.my_family_1.a_sub_family.a_second_variable": "a modified value", + "rougail.my_family_1.a_new_subfamily.a_second_variable": "a modified value", + "rougail.my_family_2.a_first_variable": "a value", + "rougail.my_family_2.a_sub_family.a_second_variable": null, + "rougail.my_family_3.a_first_variable": "a value", + "rougail.my_family_3.a_sub_family.a_second_variable": "a modified value 2", + "rougail.my_family_3.a_new_variable": "a modified value" +} \ No newline at end of file diff --git a/tests/types/result/family_subfamily_add/variables_rw.json b/tests/types/result/family_subfamily_add/variables_rw.json new file mode 100644 index 000000000..8236df3cf --- /dev/null +++ b/tests/types/result/family_subfamily_add/variables_rw.json @@ -0,0 +1,10 @@ +{ + "rougail.my_family_1.a_first_variable": "a modified value", + "rougail.my_family_1.a_sub_family.a_second_variable": "a modified value", + "rougail.my_family_1.a_new_subfamily.a_second_variable": "a modified value", + "rougail.my_family_2.a_first_variable": "a value", + "rougail.my_family_2.a_sub_family.a_second_variable": null, + "rougail.my_family_3.a_first_variable": "a value", + "rougail.my_family_3.a_sub_family.a_second_variable": "a modified value 2", + "rougail.my_family_3.a_new_variable": "a modified value" +} \ No newline at end of file diff --git a/tests/types/structures/family_subfamily_add/00_structure.yml b/tests/types/structures/family_subfamily_add/00_structure.yml new file mode 100644 index 000000000..7a1b1566e --- /dev/null +++ b/tests/types/structures/family_subfamily_add/00_structure.yml @@ -0,0 +1,29 @@ +%YAML 1.2 +--- +version: 1.1 + +my_family_1: + type: my_family_type + + a_first_variable: a modified value + + a_sub_family: + + a_second_variable: a modified value + + a_new_subfamily: + + a_second_variable: a modified value + +my_family_2: + type: my_family_type + +my_family_3: + type: my_family_type + + a_new_variable: a modified value + + a_sub_family: + + a_second_variable: a modified value 2 +... diff --git a/tests/types/types/family_subfamily_add/00_structure.yml b/tests/types/types/family_subfamily_add/00_structure.yml new file mode 100644 index 000000000..aa378b739 --- /dev/null +++ b/tests/types/types/family_subfamily_add/00_structure.yml @@ -0,0 +1,12 @@ +%YAML 1.2 +--- +version: 1.1 + +my_family_type: # My family type + + a_first_variable: a value # a first variable + + a_sub_family: # My subfamily + + a_second_variable: # a second variable +...