Skip to content

Commit

Permalink
Fixed list parsing from ConfigIniEnv and adjusted code to match docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Nov 5, 2018
1 parent 07ffdfd commit 41f89f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions everett/manager.py
Expand Up @@ -600,11 +600,11 @@ def __init__(self, possible_paths):

path = os.path.abspath(os.path.expanduser(path.strip()))
if path and os.path.isfile(path):
self.cfg.update(ConfigIniEnv.parse_ini_file(path))
self.cfg.update(self.parse_ini_file(path))
break

@classmethod
def parse_ini_file(cls, path):
cfgobj = ConfigObj(path)
cfgobj = ConfigObj(path, list_values=False)

def extract_section(namespace, d):
cfg = {}
Expand Down
3 changes: 2 additions & 1 deletion tests/data/config_test.ini
@@ -1,8 +1,9 @@
[main]
foo = bar
bar = test1,test2

[nsbaz]
foo = bat

[[nsbaz2]]
foo = bat2
foo = bat2
2 changes: 2 additions & 0 deletions tests/data/config_test_original.ini
@@ -0,0 +1,2 @@
[main]
foo_original = original
17 changes: 17 additions & 0 deletions tests/test_manager.py
Expand Up @@ -318,6 +318,23 @@ def test_ConfigIniEnv(datadir):
assert cie.get('foo') == NO_VALUE


def test_ConfigIniEnv_multiple_files(datadir):
ini_filename = os.path.join(datadir, 'config_test.ini')
ini_filename_original = os.path.join(datadir, 'config_test_original.ini')
cie = ConfigIniEnv([ini_filename, ini_filename_original])
# Only the first found file is loaded, so foo_original does not exist
assert cie.get('foo_original') == NO_VALUE
cie = ConfigIniEnv([ini_filename_original])
# ... but it is there if only the original is loaded (safety check)
assert cie.get('foo_original') == 'original'


def test_ConfigIniEnv_does_not_parse_lists(datadir):
ini_filename = os.path.join(datadir, 'config_test.ini')
cie = ConfigIniEnv([ini_filename])
assert cie.get('bar') == 'test1,test2'


def test_ConfigEnvFileEnv(datadir):
env_filename = os.path.join(datadir, '.env')
cefe = ConfigEnvFileEnv(['/does/not/exist/.env', env_filename])
Expand Down

0 comments on commit 41f89f0

Please sign in to comment.