How to use the sacred.config.custom_containers.DogmaticDict function in sacred

To help you get started, we’ve selected a few sacred 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 IDSIA / sacred / tests / test_config / test_config_scope.py View on Github external
def is_dogmatic(a):
    if isinstance(a, (DogmaticDict, DogmaticList)):
        return True
    elif isinstance(a, dict):
        return any(is_dogmatic(v) for v in a.values())
    elif isinstance(a, (list, tuple)):
        return any(is_dogmatic(v) for v in a)
github IDSIA / sacred / tests / test_config / test_dogmatic_dict.py View on Github external
def test_isinstance_of_dict():
    assert isinstance(DogmaticDict(), dict)
github IDSIA / sacred / tests / test_config / test_dogmatic_dict.py View on Github external
def test_fixed_value_not_initialized():
    d = DogmaticDict({"a": 7})
    assert "a" not in d
github IDSIA / sacred / tests / test_config / test_dogmatic_dict.py View on Github external
def test_fallback():
    d = DogmaticDict(fallback={"a": 23})
    assert "a" in d
    assert d["a"] == 23
    assert d.get("a") == 23

    d = DogmaticDict()
    d.fallback = {"a": 23}
    assert "a" in d
    assert d["a"] == 23
    assert d.get("a") == 23
github IDSIA / sacred / tests / test_config / test_dogmatic_dict.py View on Github external
def test_fixed_value_fixed():
    d = DogmaticDict({"a": 7})
    d["a"] = 8
    assert d["a"] == 7

    del d["a"]
    assert "a" in d
    assert d["a"] == 7

    d.update([("a", 9), ("b", 12)])
    assert d["a"] == 7

    d.update({"a": 9, "b": 12})
    assert d["a"] == 7

    d.update(a=10, b=13)
    assert d["a"] == 7
github IDSIA / sacred / tests / test_config / test_dogmatic_dict.py View on Github external
def test_dict_interface_update_with_list_of_items():
    d = DogmaticDict()
    d["a"] = 12
    d["b"] = "foo"
    d.update([("b", 9), ("c", 7)])
    assert d["a"] == 12
    assert d["b"] == 9
    assert d["c"] == 7
github IDSIA / sacred / tests / test_config / test_dogmatic_dict.py View on Github external
def test_dict_interface_set_item():
    d = DogmaticDict()
    d["a"] = 12
    d["b"] = "foo"
    assert "a" in d
    assert "b" in d

    assert d["a"] == 12
    assert d["b"] == "foo"

    assert set(d.keys()) == {"a", "b"}
    assert set(d.values()) == {12, "foo"}
    assert set(d.items()) == {("a", 12), ("b", "foo")}
github IDSIA / sacred / sacred / config / utils.py View on Github external
def undogmatize(obj):
    if isinstance(obj, DogmaticDict):
        return dict({key: undogmatize(value) for key, value in obj.items()})
    elif isinstance(obj, DogmaticList):
        return list([undogmatize(value) for value in obj])
    elif isinstance(obj, tuple):
        return tuple(undogmatize(value) for value in obj)
    else:
        return obj
github IDSIA / sacred / sacred / config / utils.py View on Github external
def dogmatize(obj):
    if isinstance(obj, dict):
        return DogmaticDict({key: dogmatize(val) for key, val in obj.items()})
    elif isinstance(obj, list):
        return DogmaticList([dogmatize(value) for value in obj])
    elif isinstance(obj, tuple):
        return tuple(dogmatize(value) for value in obj)
    else:
        return obj