Skip to content

Commit

Permalink
Add test for merging into a resolver's output
Browse files Browse the repository at this point in the history
  • Loading branch information
odelalleau committed Mar 30, 2021
1 parent 9995057 commit e87784c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/interpolation/built_in_resolvers/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_dict_keys(cfg: Any, key: Any, expected: Any) -> None:
InterpolationResolutionError,
match=re.escape(
"MissingMandatoryValue raised while resolving interpolation: "
"Missing mandatory value : y"
"Missing mandatory value: y"
),
),
id="select_missing",
Expand Down
24 changes: 23 additions & 1 deletion tests/interpolation/test_custom_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from typing import Any, Dict, List

from pytest import mark, raises, warns
from pytest import mark, param, raises, warns

from omegaconf import DictConfig, ListConfig, OmegaConf, Resolver
from tests.interpolation import dereference_node
Expand Down Expand Up @@ -466,3 +466,25 @@ def parent_and_default(default: int = 10, *, _parent_: Any) -> Any:

assert cfg.no_param == 20
assert cfg.param == 30


@mark.parametrize(
("cfg2", "expected"),
[
param({"foo": {"b": 1}}, {"foo": {"a": 0, "b": 1}}, id="extend"),
param({"foo": {"b": "${.a}"}}, {"foo": {"a": 0, "b": 0}}, id="extend_inter"),
param({"foo": {"a": 1}}, {"foo": {"a": 1}}, id="override_int"),
param({"foo": {"a": {"b": 1}}}, {"foo": {"a": {"b": 1}}}, id="override_dict"),
param({"foo": 10}, {"foo": 10}, id="replace_interpolation"),
param({"bar": 10}, {"foo": {"a": 0}, "bar": 10}, id="other_node"),
],
)
def test_merge_into_resolver_output(
restore_resolvers: Any, cfg2: Any, expected: Any
) -> None:
OmegaConf.register_new_resolver(
"make", lambda _parent_: OmegaConf.create({"a": 0}, parent=_parent_)
)

cfg = OmegaConf.create({"foo": "${make:}"})
assert OmegaConf.merge(cfg, cfg2) == expected

0 comments on commit e87784c

Please sign in to comment.