From abd39cbdf0ac4c120019faacb9a089a1fd9d4143 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Mon, 21 Oct 2024 09:52:23 -0700 Subject: [PATCH] Update unit tests Update docstring to more completely describe behavior --- ovos_plugin_manager/utils/config.py | 7 ++++++- test/unittests/test_utils.py | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ovos_plugin_manager/utils/config.py b/ovos_plugin_manager/utils/config.py index d5f83c56..46f2f38c 100644 --- a/ovos_plugin_manager/utils/config.py +++ b/ovos_plugin_manager/utils/config.py @@ -14,6 +14,11 @@ def get_plugin_config(config: Optional[dict] = None, section: str = None, - module-specific configurations take priority - section-specific configuration is appended (new keys only) - global `lang` configuration is appended (if not already set) + + If no module is specified, then the requested section configuration is + assumed to be a top-level key in the base configuration, defaulting to the + base configuration if that section is not found. If both `module` and + `section` are unspecified, then the base configuration is returned. @param config: Base configuration to parse, defaults to `Configuration()` @param section: Config section for the plugin (i.e. TTS, STT, language) @param module: Module/plugin to get config for, default reads from config @@ -41,7 +46,7 @@ def get_plugin_config(config: Optional[dict] = None, section: str = None, # Use section-scoped config as defaults (i.e. TTS.lang) module_config.setdefault(key, val) config = module_config - if section not in ["hotwords", "VAD", "listener", "gui"]: + if section not in ["hotwords", "VAD", "listener", "gui", None]: # With some exceptions, plugins will want a `lang` value. If it was not # set in the section or module config, use the default top-level config. config.setdefault('lang', lang) diff --git a/test/unittests/test_utils.py b/test/unittests/test_utils.py index 27c02455..85c3cb4a 100644 --- a/test/unittests/test_utils.py +++ b/test/unittests/test_utils.py @@ -649,11 +649,12 @@ def test_get_plugin_config(self, config): self.assertEqual(tts_config['voice'], 'german-mbrola-5') self.assertNotIn("ovos_tts_plugin_espeakng", tts_config) - # Test PHAL with no configuration only `lang` is populated + # Test PHAL with no configuration phal_config = get_plugin_config(config, "PHAL") - self.assertEqual(set(phal_config.keys()), {"lang"}) + self.assertEqual(set(phal_config.keys()), config.keys()) phal_config = get_plugin_config(config, "PHAL", "test_plugin") - self.assertEqual(set(phal_config.keys()), {"lang"}) + self.assertEqual(phal_config, {"module": "test_plugin", + "lang": config["lang"]}) self.assertEqual(_MOCK_CONFIG, start_config)