Skip to content

Commit

Permalink
test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Mar 9, 2021
1 parent bf97a64 commit 88586d8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/test_struct.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import Any, Dict

import pytest
from pytest import mark, raises

from omegaconf import OmegaConf
from omegaconf.errors import ConfigKeyError
Expand All @@ -16,40 +16,40 @@ def test_struct_set_on_dict() -> None:
c = OmegaConf.create({"a": {}})
OmegaConf.set_struct(c, True)
# Throwing when it hits foo, so exception key is a.foo and not a.foo.bar
with pytest.raises(AttributeError, match=re.escape("a.foo")):
with raises(AttributeError, match=re.escape("a.foo")):
# noinspection PyStatementEffect
c.a.foo.bar


def test_struct_set_on_nested_dict() -> None:
c = OmegaConf.create({"a": {"b": 10}})
OmegaConf.set_struct(c, True)
with pytest.raises(AttributeError):
with raises(AttributeError):
# noinspection PyStatementEffect
c.foo

assert "a" in c
assert c.a.b == 10
with pytest.raises(AttributeError, match=re.escape("a.foo")):
with raises(AttributeError, match=re.escape("a.foo")):
# noinspection PyStatementEffect
c.a.foo


def test_merge_dotlist_into_struct() -> None:
c = OmegaConf.create({"a": {"b": 10}})
OmegaConf.set_struct(c, True)
with pytest.raises(AttributeError, match=re.escape("foo")):
with raises(AttributeError, match=re.escape("foo")):
c.merge_with_dotlist(["foo=1"])


@pytest.mark.parametrize("in_base, in_merged", [(dict(), dict(a=10))])
@mark.parametrize("in_base, in_merged", [({}, {"a": 10})])
def test_merge_config_with_struct(
in_base: Dict[str, Any], in_merged: Dict[str, Any]
) -> None:
base = OmegaConf.create(in_base)
merged = OmegaConf.create(in_merged)
OmegaConf.set_struct(base, True)
with pytest.raises(ConfigKeyError):
with raises(ConfigKeyError):
OmegaConf.merge(base, merged)


Expand All @@ -59,6 +59,6 @@ def test_struct_contain_missing() -> None:
assert "foo" not in c


@pytest.mark.parametrize("cfg", [{}, OmegaConf.create({}, flags={"struct": True})])
@mark.parametrize("cfg", [{}, OmegaConf.create({}, flags={"struct": True})])
def test_struct_dict_get(cfg: Any) -> None:
assert cfg.get("z") is None

0 comments on commit 88586d8

Please sign in to comment.