How to use the omegaconf.OmegaConf.is_missing 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 / structured_conf / test_structured_basic.py View on Github external
def test_missing2(self, class_type: str) -> None:
            module: Any = import_module(class_type)
            cfg = OmegaConf.create(module.MissingTest.Missing2)
            assert cfg == {"head": {"next": "???", "value": 1}}
            assert OmegaConf.is_missing(cfg.head, "next")

            cfg.head.next = module.LinkedList(value=2)
            assert cfg == {"head": {"next": {"next": None, "value": 2}, "value": 1}}
github omry / omegaconf / tests / structured_conf / test_structured_config.py View on Github external
def test_merge_missing_structured_config_is_missing(self, class_type: str) -> None:
        # Test that the merged type is that of the last merged config
        module: Any = import_module(class_type)
        c1 = OmegaConf.structured(module.MissingStructuredConfigField)
        assert OmegaConf.is_missing(c1, "plugin")
        c2 = OmegaConf.merge(c1, module.MissingStructuredConfigField)
        assert OmegaConf.is_missing(c2, "plugin")
github omry / omegaconf / tests / test_omegaconf.py View on Github external
def test_is_missing_resets() -> None:
    cfg = OmegaConf.structured(StructuredWithMissing)
    assert OmegaConf.is_missing(cfg, "dict")
    cfg.dict = {}
    assert not OmegaConf.is_missing(cfg, "dict")

    assert OmegaConf.is_missing(cfg, "list")
    cfg.list = [1, 2, 3]
    assert not OmegaConf.is_missing(cfg, "list")
    cfg.list = "???"
    assert OmegaConf.is_missing(cfg, "list")
github omry / omegaconf / tests / structured_conf / test_structured_config.py View on Github external
def test_merge_missing_structured_config_is_missing(self, class_type: str) -> None:
        # Test that the merged type is that of the last merged config
        module: Any = import_module(class_type)
        c1 = OmegaConf.structured(module.MissingStructuredConfigField)
        assert OmegaConf.is_missing(c1, "plugin")
        c2 = OmegaConf.merge(c1, module.MissingStructuredConfigField)
        assert OmegaConf.is_missing(c2, "plugin")
github omry / omegaconf / tests / test_matrix.py View on Github external
opt: bool,
    missing: bool,
    inter: bool,
    exp: Any = SKIP,
) -> None:
    target_node = cfg._get_node(key)
    assert target_node._key() == key
    assert target_node._is_none() == none
    assert target_node._is_optional() == opt
    assert target_node._is_missing() == missing
    assert target_node._is_interpolation() == inter

    if exp is not SKIP:
        assert cfg.get(key) == exp

    assert OmegaConf.is_missing(cfg, key) == missing
    assert OmegaConf.is_none(cfg, key) == none
    assert OmegaConf.is_optional(cfg, key) == opt
    assert OmegaConf.is_interpolation(cfg, key) == inter
github omry / omegaconf / tests / test_interpolation.py View on Github external
def test_interpolation_with_missing() -> None:
    cfg = OmegaConf.create({"out_file": "${x.name}.txt", "x": {"name": "???"}})
    assert OmegaConf.is_missing(cfg, "out_file")
github omry / omegaconf / tests / structured_conf / test_structured_config.py View on Github external
def validate(cfg: DictConfig) -> None:
            assert cfg == {"dict1": {"foo": "bar"}, "missing": MISSING}
            assert OmegaConf.is_missing(cfg, "missing")
github omry / omegaconf / tests / test_omegaconf.py View on Github external
def test_is_missing(
    cfg: Any, key: str, expected_is_missing: bool, expectation: Any
) -> None:
    cfg = OmegaConf.create(cfg)
    with expectation:
        cfg.get(key)

    assert OmegaConf.is_missing(cfg, key) == expected_is_missing
    OmegaConf.set_struct(cfg, True)
    assert OmegaConf.is_missing(cfg, key) == expected_is_missing
    OmegaConf.set_readonly(cfg, True)
    assert OmegaConf.is_missing(cfg, key) == expected_is_missing
github omry / omegaconf / tests / structured_conf / test_structured_config.py View on Github external
def test_promote_to_class(self, class_type: str) -> None:
        module: Any = import_module(class_type)

        conf = OmegaConf.create(module.AnyTypeConfig)
        assert OmegaConf.get_type(conf) == module.AnyTypeConfig

        conf._promote(module.BoolConfig)

        assert OmegaConf.get_type(conf) == module.BoolConfig
        assert conf.with_default is True
        assert conf.null_default is None
        assert OmegaConf.is_missing(conf, "mandatory_missing")
github omry / omegaconf / tests / examples / test_dataclass_example.py View on Github external
schema: Config = OmegaConf.structured(Config)
    cfg = OmegaConf.create(yaml)
    merged: Any = OmegaConf.merge(schema, cfg)
    assert merged == {
        "num": 10,
        "user": {"name": "Omry", "height": "???"},
        "domains": {
            "blog_website": {
                "name": "blog",
                "path": "???",
                "protocols": [Protocol.HTTPS],
            }
        },
    }
    assert OmegaConf.is_missing(merged.domains.blog_website, "path")