Skip to content

Commit

Permalink
Merge pull request #36 from KyleJamesWalker/dashes
Browse files Browse the repository at this point in the history
Allow items with dashes to work with the env
  • Loading branch information
KyleJamesWalker authored Jun 22, 2020
2 parents 9a2c865 + 20d3322 commit d50c2fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name='yamlsettings',
version='2.0.3',
version='2.1.0',
description='Yaml Settings Configuration Module',
long_description=readme,
author='Kyle James Walker',
Expand Down
10 changes: 9 additions & 1 deletion tests/test_yamldict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from mock import mock_open
from yamlsettings import (load, load_all, save_all,
update_from_env, update_from_file)
update_from_env, update_from_file, yamldict)

from . import builtin_module, path_override, open_override, isfile_override

Expand Down Expand Up @@ -228,6 +228,14 @@ def test_list_replace_on_update(self):
test_defaults.update({'a': (4,)})
self.assertEqual(test_defaults.a, (4,))

@mock.patch.dict('os.environ', {'FOO_BAR': 'new-baz'})
def test_dash_vars_with_env(self):
"""Test items with dashes can be overritten with env"""
test_settings = yamldict.YAMLDict({'foo-bar': 'baz'})
assert test_settings['foo-bar'] == 'baz'
update_from_env(test_settings)
assert test_settings['foo-bar'] == 'new-baz'


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion yamlsettings/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _set_env_var(path, node):
env_path = "{0}{1}{2}".format(
prefix.upper(),
'_' if prefix else '',
'_'.join([str(key).upper() for key in path])
'_'.join([str(key).replace('-', '_').upper() for key in path])
)
env_val = os.environ.get(env_path, None)
if env_val is not None:
Expand Down

0 comments on commit d50c2fd

Please sign in to comment.