Skip to content

Commit

Permalink
Merge pull request #122 from pesser/fixexpansion
Browse files Browse the repository at this point in the history
fix expansion
  • Loading branch information
jhaux authored Aug 7, 2019
2 parents 249cda8 + 15a1ed4 commit 1ee4cea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions edflow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def retrieve(
raise KeyNotFoundError(e)

visited += [key]
# final expansion of retrieved value
if expand and callable(list_or_dict):
list_or_dict = list_or_dict()
parent[last_key] = list_or_dict
except KeyNotFoundError as e:
if default is None:
print("Key not found: {}, seen: {}".format(keys, visited))
Expand Down
22 changes: 22 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,28 @@ def test_retrieve_propagates_exception():
val = retrieve(dol, "b/c/d", default=0)


def test_retrieve_callable_leaves():
dol = {"a": [1, 2], "b": callable_leave, "e": 2}
val = retrieve(dol, "b")

# make sure expansion is returned
assert val == callable_leave()

# make sure expansion was done in-place
assert dol["b"] == callable_leave()

dol = {"a": [1, 2], "b": callable_leave, "e": 2}
val = retrieve(dol, "b/c")
# make sure expansion is returned
assert val == nested_leave()
# make sure expansion was done in-place
assert dol["b"]["c"] == nested_leave()

dol = {"a": [1, 2], "b": callable_leave, "e": 2}
val = retrieve(dol, "b/c/d")
assert val == 1


# ====================== walk ====================


Expand Down

0 comments on commit 1ee4cea

Please sign in to comment.