How to use the omegaconf.OmegaConf.update 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_update.py View on Github external
def test_update_list() -> None:
    c = OmegaConf.create([1, 2, 3])
    assert isinstance(c, ListConfig)
    OmegaConf.update(c, "1", "abc")
    OmegaConf.update(c, "-1", "last")
    with raises(IndexError):
        OmegaConf.update(c, "4", "abc")

    assert len(c) == 3
    assert c[0] == 1
    assert c[1] == "abc"
    assert c[2] == "last"
github omry / omegaconf / tests / test_update.py View on Github external
def test_update_nested_list() -> None:
    c = OmegaConf.create(dict(deep=dict(list=[1, 2, 3])))
    OmegaConf.update(c, "deep.list.1", "abc")
    OmegaConf.update(c, "deep.list.-1", "last")
    with raises(IndexError):
        OmegaConf.update(c, "deep.list.4", "abc")

    assert c.deep.list[0] == 1
    assert c.deep.list[1] == "abc"
    assert c.deep.list[2] == "last"
github omry / omegaconf / tests / test_update.py View on Github external
def test_update_deep_with_map_update() -> None:
    c = OmegaConf.create("a: {b : {c: 1}}")
    OmegaConf.update(c, "a.b.d", 2)
    assert {"a": {"b": {"c": 1, "d": 2}}} == c
github omry / omegaconf / tests / test_update.py View on Github external
def test_update_list_make_dict() -> None:
    c = OmegaConf.create([None, None])
    assert isinstance(c, ListConfig)
    OmegaConf.update(c, "0.a.a", "aa")
    OmegaConf.update(c, "0.a.b", "ab")
    OmegaConf.update(c, "1.b.a", "ba")
    OmegaConf.update(c, "1.b.b", "bb")
    assert c[0].a.a == "aa"
    assert c[0].a.b == "ab"
    assert c[1].b.a == "ba"
    assert c[1].b.b == "bb"
github omry / omegaconf / tests / test_errors.py View on Github external
            op=lambda cfg: OmegaConf.update(cfg, "a", IllegalType()),
            key="a",
github omry / omegaconf / tests / test_update.py View on Github external
def test_update_list_make_dict() -> None:
    c = OmegaConf.create([None, None])
    assert isinstance(c, ListConfig)
    OmegaConf.update(c, "0.a.a", "aa")
    OmegaConf.update(c, "0.a.b", "ab")
    OmegaConf.update(c, "1.b.a", "ba")
    OmegaConf.update(c, "1.b.b", "bb")
    assert c[0].a.a == "aa"
    assert c[0].a.b == "ab"
    assert c[1].b.a == "ba"
    assert c[1].b.b == "bb"
github omry / omegaconf / tests / test_update.py View on Github external
def test_update_map_value() -> None:
    # Replacing an existing key in a map
    s = "hello: world"
    c = OmegaConf.create(s)
    OmegaConf.update(c, "hello", "there")
    assert {"hello": "there"} == c
github omry / omegaconf / tests / test_readonly.py View on Github external
            lambda c: OmegaConf.update(c, "a.b", 10),
            raises(ReadonlyConfigError, match="a"),
github omry / omegaconf / tests / test_update.py View on Github external
def test_update_list() -> None:
    c = OmegaConf.create([1, 2, 3])
    assert isinstance(c, ListConfig)
    OmegaConf.update(c, "1", "abc")
    OmegaConf.update(c, "-1", "last")
    with raises(IndexError):
        OmegaConf.update(c, "4", "abc")

    assert len(c) == 3
    assert c[0] == 1
    assert c[1] == "abc"
    assert c[2] == "last"
github omry / omegaconf / tests / test_errors.py View on Github external
            op=lambda cfg: OmegaConf.update(cfg, "num", None),
            exception_type=ValidationError,