示例#1
0
    [
        ([], [], []),
        ([1, 2], [3], [1, 2, 3]),
        ([1, 2], ("a", "b", "c"), [1, 2, "a", "b", "c"]),
    ],
)
def test_extend(src: List[Any], append: List[Any], result: List[Any]) -> None:
    lst = OmegaConf.create(src)
    lst.extend(append)
    assert lst == result


@mark.parametrize(
    "src, remove, result, expectation",
    [
        ([10], 10, [], nullcontext()),
        ([], "oops", None, raises(ValueError)),
        ([0, dict(a="blah"), 10], dict(a="blah"), [0, 10], nullcontext()),
        ([1, 2, 1, 2], 2, [1, 1, 2], nullcontext()),
    ],
)
def test_remove(src: List[Any], remove: Any, result: Any,
                expectation: Any) -> None:
    with expectation:
        lst = OmegaConf.create(src)
        assert isinstance(lst, ListConfig)
        lst.remove(remove)
        assert lst == result


@mark.parametrize("src", [[], [1, 2, 3], [None, dict(foo="bar")]])
示例#2
0
from omegaconf.errors import (
    ConfigKeyError,
    InterpolationKeyError,
    InterpolationToMissingValueError,
    UnsupportedInterpolationType,
)
from tests import Color, ConcretePlugin, IllegalType, StructuredWithMissing


@mark.parametrize(
    "cfg, key, expected_is_missing, expectation",
    [
        ({}, "foo", False, raises(ConfigKeyError)),
        ({
            "foo": True
        }, "foo", False, nullcontext()),
        ({
            "foo": "${no_such_key}"
        }, "foo", False, raises(InterpolationKeyError)),
        ({
            "foo": MISSING
        }, "foo", True, raises(MissingMandatoryValue)),
        param(
            {
                "foo": "${bar}",
                "bar": DictConfig(content=MISSING)
            },
            "foo",
            False,
            raises(InterpolationToMissingValueError),
            id="missing_interpolated_dict",