diff --git a/tests/test_interpolation.py b/tests/test_interpolation.py index fbb67fec1..55cd7f1e3 100644 --- a/tests/test_interpolation.py +++ b/tests/test_interpolation.py @@ -2,7 +2,7 @@ import random import re from textwrap import dedent -from typing import Any, Optional, Tuple +from typing import Any, Dict, List, Optional, Tuple import pytest from _pytest.python_api import RaisesContext @@ -924,18 +924,42 @@ def test_type_validation_error_no_throw() -> None: assert bad_node._dereference_node(throw_on_resolution_failure=False) is None -def test_resolver_output_dictconfig(restore_resolvers: Any) -> None: - OmegaConf.register_new_resolver("dict", lambda: {"a": 0, "b": 1}) - cfg = OmegaConf.create({"x": "${dict:}"}) - assert isinstance(cfg.x, DictConfig) - assert cfg.x.a == 0 and cfg.x.b == 1 +@pytest.mark.parametrize( + ("cfg", "expected"), + [ + ({"a": 0, "b": 1}, {"a": 0, "b": 1}), + ({"a": "${y}"}, {"a": -1}), + ({"a": 0, "b": "${x.a}"}, {"a": 0, "b": 0}), + ({"a": 0, "b": "${.a}"}, {"a": 0, "b": 0}), + ({"a": "${..y}"}, {"a": -1}), + ], +) +def test_resolver_output_dictconfig( + restore_resolvers: Any, cfg: Dict[str, Any], expected: Dict[str, Any] +) -> None: + OmegaConf.register_new_resolver("dict", lambda: cfg) + c = OmegaConf.create({"x": "${dict:}", "y": -1}) + assert isinstance(c.x, DictConfig) + assert c.x == expected -def test_resolver_output_listconfig(restore_resolvers: Any) -> None: - OmegaConf.register_new_resolver("list", lambda: [0, 1]) - cfg = OmegaConf.create({"x": "${list:}"}) - assert isinstance(cfg.x, ListConfig) - assert cfg.x == [0, 1] +@pytest.mark.parametrize( + ("cfg", "expected"), + [ + ([0, 1], [0, 1]), + (["${y}"], [-1]), + ([0, "${x.0}"], [0, 0]), + ([0, "${.0}"], [0, 0]), + (["${..y}"], [-1]), + ], +) +def test_resolver_output_listconfig( + restore_resolvers: Any, cfg: List[Any], expected: List[Any] +) -> None: + OmegaConf.register_new_resolver("list", lambda: cfg) + c = OmegaConf.create({"x": "${list:}", "y": -1}) + assert isinstance(c.x, ListConfig) + assert c.x == expected def test_none_value_in_quoted_string(restore_resolvers: Any) -> None: