From 572e125fb07fbde19f89b5984a572d76cd7ac712 Mon Sep 17 00:00:00 2001 From: Olivier Delalleau <507137+odelalleau@users.noreply.github.com> Date: Thu, 11 Mar 2021 21:48:45 -0500 Subject: [PATCH] Check readonly flag for dict/list resolver outputs --- tests/test_interpolation.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_interpolation.py b/tests/test_interpolation.py index 450d5816c..a06bb2a86 100644 --- a/tests/test_interpolation.py +++ b/tests/test_interpolation.py @@ -41,6 +41,14 @@ INVALID_CHARS_IN_KEY_NAMES = "\\${}()[].: '\"" +def dereference(cfg: Container, key: Any) -> Node: + node = cfg._get_node(key) + assert isinstance(node, Node) + node = node._dereference_node() + assert isinstance(node, Node) + return node + + @pytest.mark.parametrize( "cfg,key,expected", [ @@ -941,7 +949,7 @@ def test_interpolation_readonly_resolver_output( def test_interpolation_readonly_node() -> None: cfg = OmegaConf.structured(User(name="7", age=II("name"))) - resolved = cfg._get_node("age")._dereference_node() + resolved = dereference(cfg, "age") assert resolved == 7 # The `resolved` node must be read-only because `age` is an integer, so the # interpolation cannot return directly the `name` node. @@ -971,6 +979,7 @@ def test_resolver_output_dict_to_dictconfig( c = OmegaConf.create({"x": "${dict:}", "y": -1}) assert isinstance(c.x, DictConfig) assert c.x == expected + assert dereference(c, "x")._get_flag("readonly") @pytest.mark.parametrize( @@ -990,3 +999,4 @@ def test_resolver_output_list_to_listconfig( c = OmegaConf.create({"x": "${list:}", "y": -1}) assert isinstance(c.x, ListConfig) assert c.x == expected + assert dereference(c, "x")._get_flag("readonly")