Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved optional substitutions work with config merging #153

Merged
merged 2 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyhocon/config_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def merge_configs(a, b, copy_trees=False):
if isinstance(value, ConfigValues):
value.parent = a
value.key = key
value.overriden_value = a.get(key, None)
if key in a:
value.overriden_value = a[key]
a[key] = value
if a.root:
a.history[key] = (a.history.get(key) or []) + b.history.get(key)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,21 @@ def test_substitution_nested_override(self):
assert config['database.name'] == 'peopledb'
assert config['database.pass'] == 'peoplepass'

def test_optional_with_merge(self):
unresolved = ConfigFactory.parse_string(
"""
foo: 42
foo: ${?a}
""", resolve=False)
source = ConfigFactory.parse_string(
"""
b: 14
""")
config = unresolved.with_fallback(source)
assert config['foo'] == 42
config = source.with_fallback(unresolved)
assert config['foo'] == 42

def test_optional_substitution(self):
config = ConfigFactory.parse_string(
"""
Expand Down