Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"
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"
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
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"
op=lambda cfg: OmegaConf.update(cfg, "a", IllegalType()),
key="a",
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"
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
lambda c: OmegaConf.update(c, "a.b", 10),
raises(ReadonlyConfigError, match="a"),
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"
op=lambda cfg: OmegaConf.update(cfg, "num", None),
exception_type=ValidationError,