Skip to content

Commit

Permalink
refactor[node.py]: Make plain value to be set as required
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Vasenin committed Oct 2, 2020
1 parent 0e6e1fc commit fdfd9b2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ntc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .leaf import *
from .node import *

__version__ = "0.3.3"
__version__ = "0.4.0"
2 changes: 1 addition & 1 deletion ntc/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _set_new(self, key: str, value: Any) -> None:
value_to_set = leaf_spec.clone()
value_to_set.value = value
else:
value_to_set = CfgLeaf(value, type(value))
value_to_set = CfgLeaf(value, type(value), required=True)

if isinstance(value_to_set, CfgLeaf):
if leaf_spec:
Expand Down
5 changes: 5 additions & 0 deletions tests/data/required/bad_plain_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ntc import CN
from tests.data.required.required_plain_value import cfg

cfg = CN(cfg)
cfg.REQUIRED = None
5 changes: 5 additions & 0 deletions tests/data/required/plain_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ntc import CN
from tests.data.required.required_plain_value import cfg

cfg = CN(cfg)
cfg.REQUIRED = 12
4 changes: 4 additions & 0 deletions tests/data/required/required_plain_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ..base_cfg import cfg

cfg = cfg.clone()
cfg.REQUIRED = 42
10 changes: 10 additions & 0 deletions tests/test_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ def test_subclass():
cfg = CN.load(DATA_DIR / "subclass.py")
assert len(cfg.REQUIRED_SUBCLASSES) > 0
assert issubclass(cfg.REQUIRED_SUBCLASSES.ONE, BaseClass)


def test_plain_value():
cfg = CN.load(DATA_DIR / "plain_value.py")
assert cfg.REQUIRED == 12


def test_bad_plain_value():
with pytest.raises(MissingRequired):
CN.load(DATA_DIR / "bad_plain_value.py")

0 comments on commit fdfd9b2

Please sign in to comment.