Skip to content

Commit

Permalink
fix: do not log warning messages with special system properties (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo authored Jan 8, 2024
1 parent f847786 commit 304c70c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
9 changes: 7 additions & 2 deletions toolium/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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):
"""
Expand Down
29 changes: 27 additions & 2 deletions toolium/test/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
limitations under the License.
"""

import mock
import os

import mock
import pytest

from toolium.config_parser import ExtendedConfigParser
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 304c70c

Please sign in to comment.