From 51c3acc6542ed3b74d1623db3da2a2d4da6aa8b8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 22 Oct 2019 09:56:27 +0200 Subject: [PATCH] Document helper functions --- tests/Settings/TestDefinitionContainer.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/Settings/TestDefinitionContainer.py b/tests/Settings/TestDefinitionContainer.py index 09efc3fcb8..73d10d871c 100644 --- a/tests/Settings/TestDefinitionContainer.py +++ b/tests/Settings/TestDefinitionContainer.py @@ -72,6 +72,11 @@ def test_validateOverridingDefaultValue(file_name): if "value" in parent_settings[key]: assert "default_value" not in val, "Unnecessary default_value for {key} in {file_name}".format(key = key, file_name = file_name) # If there is a value in the parent settings, then the default_value is not effective. +## Get all settings and their properties from a definition we're inheriting +# from. +# \param definition_id The definition we're inheriting from. +# \return A dictionary of settings by key. Each setting is a dictionary of +# properties. def getInheritedSettings(definition_id: str) -> Dict[str, Any]: definition_path = os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions", definition_id + ".def.json") with open(definition_path, encoding = "utf-8") as f: @@ -87,7 +92,13 @@ def getInheritedSettings(definition_id: str) -> Dict[str, Any]: return result -def flattenSettings(settings) -> Dict[str, Any]: +## Put all settings in the main dictionary rather than in children dicts. +# \param settings Nested settings. The keys are the setting IDs. The values +# are dictionaries of properties per setting, including the "children" +# property. +# \return A dictionary of settings by key. Each setting is a dictionary of +# properties. +def flattenSettings(settings: Dict[str, Any]) -> Dict[str, Any]: result = {} for entry, contents in settings.items(): if "children" in contents: @@ -96,6 +107,11 @@ def flattenSettings(settings) -> Dict[str, Any]: result[entry] = contents return result +## Make one dictionary override the other. Nested dictionaries override each +# other in the same way. +# \param base A dictionary of settings that will get overridden by the other. +# \param overrides A dictionary of settings that will override the other. +# \return Combined setting data. def merge_dicts(base: Dict[str, Any], overrides: Dict[str, Any]) -> Dict[str, Any]: result = {} result.update(base)