confini

Parse and merge multiple ini files in python3
git clone git://git.defalsify.org/python-confini.git
Log | Files | Refs | README | LICENSE

commit 0441a4d0fbb989de97c1527afdaddcd16e43f4ec
parent f298edbdeef401a96b861ef6e70ae1e62534adeb
Author: nolash <dev@holbrook.no>
Date:   Mon, 12 Oct 2020 21:27:37 +0200

Omit empty environment string overrides

Diffstat:
MCHANGELOG | 1+
Mconfini/config.py | 2+-
Msetup.py | 2+-
Mtest/test_env.py | 14+++++++++++---
4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,5 +1,6 @@ 0.2.1 - Set logger name + - Omit empty string environment variables 0.2.0 - Add optional prefix string for environment overrides 0.1.1 diff --git a/confini/config.py b/confini/config.py @@ -85,7 +85,7 @@ class Config: if self.env_prefix != None: cn_env = self.env_prefix + cn val = os.environ.get(cn_env) - if val == None: + if val == None or val == '': val = self.parser[s][k] else: logg.info('environment variable {} overrides {}'.format(cn_env, cn)) diff --git a/setup.py b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='confini', - version='0.2.0', + version='0.2.1', description='Parse, verify and merge all ini files in a single directory', author='Louis Holbrook', author_email='dev@holbrook.no', diff --git a/test/test_env.py b/test/test_env.py @@ -32,8 +32,6 @@ class TestEnv(unittest.TestCase): } self.assertDictEqual(expect, c.store) - - def test_env_b_override(self): os.environ['ZZZ_FOO_BAR'] = '44' inidir = os.path.join(self.wd, 'files') c = Config(inidir, 'ZZZ') @@ -46,6 +44,16 @@ class TestEnv(unittest.TestCase): } self.assertDictEqual(expect, c.store) - + os.environ['ZZZ_FOO_BAR'] = '' + inidir = os.path.join(self.wd, 'files') + c = Config(inidir, 'ZZZ') + c.process() + expect = { + 'FOO_BAR': '42', + 'FOO_BAZ': '029a', + 'BAR_FOO': 'oof', + 'XYZZY_BERT': 'ernie', + } + self.assertDictEqual(expect, c.store) if __name__ == '__main__': unittest.main()