From 34d95c55afd58f2b5da30f422c34f3f83275e7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Gonz=C3=A1lez=20Alonso?= Date: Mon, 18 Dec 2023 19:46:49 +0100 Subject: [PATCH] fix: do not log warning messages with special system properties --- CHANGELOG.rst | 1 + toolium/config_parser.py | 9 +++++++-- toolium/test/test_config_parser.py | 29 +++++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e3f6ebda..3ff59bd2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,7 @@ v3.1.1 *Release date: In development* - Upgrade Sphinx version from 4.* to 7.* to fix readthedocs theme format +- Do not log warning messages when toolium system properties are used v3.1.0 ------ diff --git a/toolium/config_parser.py b/toolium/config_parser.py index 3a9c5598..fc64c35c 100644 --- a/toolium/config_parser.py +++ b/toolium/config_parser.py @@ -24,6 +24,11 @@ logger = logging.getLogger(__name__) +SPECIAL_SYSTEM_PROPERTIES = ['TOOLIUM_CONFIG_ENVIRONMENT', 'TOOLIUM_OUTPUT_DIRECTORY', 'TOOLIUM_OUTPUT_LOG_FILENAME', + 'TOOLIUM_CONFIG_DIRECTORY', 'TOOLIUM_CONFIG_LOG_FILENAME', + 'TOOLIUM_CONFIG_PROPERTIES_FILENAMES', 'TOOLIUM_VISUAL_BASELINE_DIRECTORY'] + + class ExtendedConfigParser(ConfigParser): def optionxform(self, optionstr): """Override default optionxform in ConfigParser to allow case sensitive options""" @@ -120,10 +125,10 @@ def update_toolium_system_properties(self, new_properties): if not self.has_section(section): self.add_section(section) self.set(section, option, value) - elif property_name.startswith('TOOLIUM'): + elif property_name.startswith('TOOLIUM') and property_name not in SPECIAL_SYSTEM_PROPERTIES: logger.warning('A toolium system property is configured but its name does not math with section' ' and option in value (use TOOLIUM_[SECTION]_[OPTION]=[Section]_[option]=value):' - ' %s=%s' % (property_name, property_value)) + ' %s=%s', property_name, property_value) def translate_config_variables(self, str_with_variables): """ diff --git a/toolium/test/test_config_parser.py b/toolium/test/test_config_parser.py index c751d21d..44ca2a32 100644 --- a/toolium/test/test_config_parser.py +++ b/toolium/test/test_config_parser.py @@ -16,8 +16,9 @@ limitations under the License. """ -import mock import os + +import mock import pytest from toolium.config_parser import ExtendedConfigParser @@ -285,11 +286,35 @@ def test_update_toolium_system_properties_wrong_format(config, logger, property_ if property_name.startswith('TOOLIUM'): logger.warning.assert_called_once_with('A toolium system property is configured but its name does not math with' ' section and option in value (use TOOLIUM_[SECTION]_[OPTION]=[Section]_' - '[option]=value): %s=%s' % (property_name, property_value)) + '[option]=value): %s=%s', property_name, property_value) else: logger.warning.assert_not_called() +toolium_system_properties_special = ( + ('TOOLIUM_CONFIG_ENVIRONMENT', 'value1'), + ('TOOLIUM_OUTPUT_DIRECTORY', 'value2'), + ('TOOLIUM_OUTPUT_LOG_FILENAME', 'value3'), + ('TOOLIUM_CONFIG_DIRECTORY', 'value4'), + ('TOOLIUM_CONFIG_LOG_FILENAME', 'value5'), + ('TOOLIUM_CONFIG_PROPERTIES_FILENAMES', 'value6'), + ('TOOLIUM_VISUAL_BASELINE_DIRECTORY', 'value7'), +) + + +@pytest.mark.parametrize("property_name, property_value", toolium_system_properties_special) +def test_update_toolium_system_properties_special(config, logger, property_name, property_value): + # Change system property and update config + environment_properties.append(property_name) + os.environ[property_name] = property_value + previous_config = config.deepcopy() + config.update_toolium_system_properties(os.environ) + + # Check that config has not been updated and error message is not logged + assert previous_config == config, 'Config has been updated' + logger.warning.assert_not_called() + + def test_update_properties_behave(config): section = 'Capabilities' option = 'platformName'