How to use the omegaconf.ValidationError function in omegaconf

To help you get started, we’ve selected a few omegaconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github omry / omegaconf / tests / test_base_config.py View on Github external
def test_omegaconf_create() -> None:
    assert OmegaConf.create([]) == []
    assert OmegaConf.create({}) == {}
    with raises(ValidationError):
        assert OmegaConf.create(10)  # type: ignore
github omry / omegaconf / tests / test_merge.py View on Github external
        ([{"user": User}, {"user": Group}], pytest.raises(ValidationError)),
        (
            [{"user": DictConfig(ref_type=User, content=User)}, {"user": Group}],
            pytest.raises(ValidationError),
        ),
        ([Plugin, ConcretePlugin], ConcretePlugin),
        pytest.param(
            [{"user": "???"}, {"user": Group}],
            {"user": Group},
            id="merge_into_missing_node",
        ),
        # missing DictConfig
        pytest.param(
            [{"dict": DictConfig(content="???")}, {"dict": {"foo": "bar"}}],
            {"dict": {"foo": "bar"}},
            id="merge_into_missing_DictConfig",
        ),
github omry / omegaconf / tests / test_matrix.py View on Github external
def test_none_assignment_and_merging_in_dict(
        self, node_type: Any, values: Any
    ) -> None:
        values = copy.deepcopy(values)
        for value in values:
            node = node_type(value=value, is_optional=False)
            data = {"node": node}
            cfg = OmegaConf.create(obj=data)
            verify(cfg, "node", none=False, opt=False, missing=False, inter=False)
            msg = "child 'node' is not Optional"
            with pytest.raises(ValidationError, match=re.escape(msg)):
                cfg.node = None

            with pytest.raises(ValidationError):
                OmegaConf.merge(cfg, {"node": None})
github omry / omegaconf / tests / structured_conf / test_structured_config.py View on Github external
def test_merged_with_nons_subclass(self, class_type: str) -> None:
        module: Any = import_module(class_type)
        c1 = OmegaConf.structured(module.Plugin)
        c2 = OmegaConf.structured(module.FaultyPlugin)
        with pytest.raises(ValidationError):
            OmegaConf.merge(c1, c2)
github omry / omegaconf / tests / test_base_config.py View on Github external
def test_set_value_validation_fail(input_: Any, key: Any, value: Any) -> None:
    c = OmegaConf.create(input_)
    with raises(ValidationError):
        c[key] = value
github omry / omegaconf / tests / structured_conf / test_structured_basic.py View on Github external
def test_assignment_of_non_subclass_2(self, class_type: str, rhs: Any) -> None:
            module: Any = import_module(class_type)
            cfg = OmegaConf.create({"plugin": module.Plugin})
            with pytest.raises(ValidationError):
                cfg.plugin = rhs
github omry / omegaconf / tests / examples / test_dataclass_example.py View on Github external
def test_modifiers() -> None:
    conf: Modifiers = OmegaConf.structured(Modifiers)
    # regular fields cannot take None
    with pytest.raises(ValidationError):
        conf.num = None  # type: ignore

    # but Optional fields can
    conf.optional_num = None
    assert conf.optional_num is None

    # Accessing a missing field will trigger MissingMandatoryValue exception
    with pytest.raises(MissingMandatoryValue):
        # noinspection PyStatementEffect
        conf.another_num

    # but you can access it once it's been assigned
    conf.another_num = 42
    assert conf.another_num == 42
github omry / omegaconf / tests / test_interpolation.py View on Github external
def test_merge_with_interpolation() -> None:
    cfg = OmegaConf.create(
        {"foo": 10, "bar": "${foo}", "typed_bar": IntegerNode("${foo}")}
    )

    assert OmegaConf.merge(cfg, {"bar": 20}) == {"foo": 10, "bar": 20, "typed_bar": 10}
    assert OmegaConf.merge(cfg, {"typed_bar": 30}) == {
        "foo": 10,
        "bar": 10,
        "typed_bar": 30,
    }

    with pytest.raises(ValidationError):
        OmegaConf.merge(cfg, {"typed_bar": "nope"})
github omry / omegaconf / tests / test_types.py View on Github external
def test_integer_1():
    c = OmegaConf.create()
    c.foo = types.Integer(10)
    assert c.foo == 10

    with pytest.raises(ValidationError):
        c.foo = "string"