Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 5ec1416

Browse files
author
Mangled Deutz
committed
Return config objects even from environment
+ enhanced typage tests Docker-DCO-1.1-Signed-off-by: Mangled Deutz <[email protected]> (github: dmp42)
1 parent 31ab559 commit 5ec1416

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

docker_registry/lib/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def __repr__(self):
3333
def __dir__(self):
3434
return self._config.keys()
3535

36+
def keys(self):
37+
return self._config.keys()
38+
3639
# Python 2.6 and below need this
3740
@property
3841
def __members__(self):
@@ -48,9 +51,6 @@ def __getattr__(self, key):
4851
return None
4952
# raise exceptions.ConfigError("No such attribute: %s" % key)
5053
result = self._config[key]
51-
# Dicts are rewrapped inside a Config object
52-
if isinstance(result, dict):
53-
return Config(result)
5454
# Strings starting with `_env:' get evaluated
5555
if isinstance(
5656
result, compat.basestring) and result.startswith('_env:'):
@@ -63,6 +63,9 @@ def __getattr__(self, key):
6363
raise exceptions.ConfigError(
6464
'Config `%s` (value: `%s`) is not valid: %s' % (
6565
varname, e, result))
66+
# Dicts are rewrapped inside a Config object
67+
if isinstance(result, dict):
68+
result = Config(result)
6669
return result
6770

6871
def __getitem__(self, key):

tests/fixtures/test_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ ENV:
3030
yetanothernonemptystring: _env:YETANOTHERNONEMPTYSTRING:'nonemptystring'
3131
bugger: _env:BUGGER:bug:me:endlessly
3232
array: _env:ARRAY:[one, two, three]
33+
dict: _env:DICT

tests/test_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_simple_types(self):
6464
assert conf.array[2] == 'three'
6565
assert len(conf.array) == 3
6666
assert conf.dict.two == 'valuetwo'
67+
assert isinstance(conf.dict, config.Config)
6768

6869
def test_env_defaults(self):
6970
global fakeenv
@@ -84,6 +85,7 @@ def test_env_defaults(self):
8485
assert conf.bugger == 'bug:me:endlessly'
8586
assert conf.array[2] == 'three'
8687
assert len(conf.array) == 3
88+
assert conf.dict is None
8789

8890
def test_env_overrides(self):
8991
global fakeenv
@@ -97,6 +99,7 @@ def test_env_overrides(self):
9799
fakeenv['NONEMPTYSTRING'] = '""'
98100
fakeenv['BUGGER'] = '"whatever:the:flush:"'
99101
fakeenv['ARRAY'] = '[one, again]'
102+
fakeenv['DICT'] = '{"one": "oneagain", "two": "twoagain"}'
100103

101104
conf = self.c.ENV
102105
assert conf.booltrue is False
@@ -117,6 +120,9 @@ def test_env_overrides(self):
117120
fakeenv['ISNONE'] = ''
118121
assert conf.isnone is None
119122

123+
assert isinstance(conf.dict, config.Config)
124+
assert conf.dict.one == 'oneagain'
125+
120126
def test_write(self):
121127
conf = self.c
122128
assert conf.something == 'else'

0 commit comments

Comments
 (0)