Skip to content

Commit

Permalink
Merge pull request #3 from cfhamlet/develop
Browse files Browse the repository at this point in the history
add: support dict in tuple
  • Loading branch information
cfhamlet committed Dec 24, 2018
2 parents 35dfee8 + f8fa671 commit 178e5b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/os_config/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.1.3
8 changes: 6 additions & 2 deletions src/os_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ def __true_tuple(self, sub_configs, tp):
for obj in tp:
if isinstance(obj, (list, tuple)):
lst.append(self.__true_tuple(sub_configs, obj))
elif isinstance(obj, _Config):
continue
elif isinstance(obj, dict):
obj = Config.from_dict(obj)

if isinstance(obj, _Config):
self.__ensure_not_sub_config_of(obj)
sub_configs.add(obj)
else:
self.__ensure_attribute_type(obj)
lst.append(obj)
lst.append(obj)

return tuple(lst)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ def test_tuple_with_list():
assert c.a == (1, 2, (1, 2, 3))


def test_tuple_with_dict():
d = {'a': (1, {'b': 2}, [3, 4, 5])}

c = Config.from_dict(d)
assert c.a[1].b == 2


def test_create_from_object():
class A(object):
a = 1
Expand Down

0 comments on commit 178e5b2

Please sign in to comment.