From 4220baa602c701114ee273c54c7675d908f0177d Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Tue, 10 Nov 2020 17:32:58 +0545 Subject: [PATCH] parametrization: Support keys of the dictionary to be interpolated (#4869) --- dvc/parsing/context.py | 2 +- tests/unit/test_context.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dvc/parsing/context.py b/dvc/parsing/context.py index 4cc2848b3..5231bfe50 100644 --- a/dvc/parsing/context.py +++ b/dvc/parsing/context.py @@ -297,7 +297,7 @@ class Context(CtxDict): resolve = rpartial(self.resolve, unwrap) if isinstance(src, Mapping): - return {key: resolve(value) for key, value in src.items()} + return dict(map(resolve, kv) for kv in src.items()) elif isinstance(src, Seq): return type(src)(map(resolve, src)) elif isinstance(src, str): diff --git a/tests/unit/test_context.py b/tests/unit/test_context.py index 2d4e20de4..b5d1a5e06 100644 --- a/tests/unit/test_context.py +++ b/tests/unit/test_context.py @@ -370,3 +370,12 @@ def test_node_value(): assert context["lst"][1].value == 2 assert context["foo"].value == "foo" + + +def test_resolve_resolves_dict_keys(): + d = {"dct": {"foo": "foobar", "persist": True}} + + context = Context(d) + assert context.resolve({"${dct.foo}": {"persist": "${dct.persist}"}}) == { + "foobar": {"persist": True} + }