Skip to content

Commit

Permalink
fix(node.py): Fix CN(new_allowed=True)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Vasenin committed Jan 25, 2021
1 parent 0a9d9cf commit 9fe1c70
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions ntc/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def _init_with_base(self, base: Union[dict, CfgNode]) -> None:
self._hooks = base._hooks + self._hooks
self._set_attrs(base.attrs)
self._desc = base._desc
self._new_allowed = base._new_allowed
self.freeze_schema()
elif isinstance(base, dict):
for key, value in base.items():
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-e .
-r requirements.dev
-r tests/requirements.txt
2 changes: 1 addition & 1 deletion tests/data/bad/bad_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from ..good.good import cfg

cfg = CN(cfg)
cfg.NEW = "bar"
cfg.BAR = "bar"
1 change: 1 addition & 0 deletions tests/data/base_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
cfg.CLASSES = CN(BaseClass)
cfg.SUBCLASS = BaseClass
cfg.SUBCLASSES = CN(CL(None, BaseClass, subclass=True))
cfg.NEW = CN(new_allowed=True)


def transform(cfg: CN):
Expand Down
5 changes: 5 additions & 0 deletions tests/data/good/new_allowed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ntc import CN
from tests.data.base_cfg import cfg

cfg = CN(cfg)
cfg.NEW.one = "one"
5 changes: 5 additions & 0 deletions tests/test_good.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ def test_inheritance_changes_multiple_loads():

assert cfg1.DICT.BAR == "BAZ"
assert cfg2.DICT.BAR == "QUUX"


def test_new_allowed():
cfg = CN.load(DATA_DIR / "new_allowed.py")
assert cfg.NEW.one == "one"

0 comments on commit 9fe1c70

Please sign in to comment.