-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hhell/stuff' into 'master'
feat(transforms): load_from_key_value See merge request utilities/ntc!23
- Loading branch information
Showing
5 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
DICT: | ||
FOO: "bar" | ||
FOO: "Foo value from yaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
from pathlib import Path | ||
|
||
from ntc import CN | ||
from ntc.transforms import load_from_key_value | ||
|
||
DATA_DIR = Path(__file__).parent / "data" / "transforms" | ||
|
||
|
||
def test_load_from_file(): | ||
cfg = CN.load(DATA_DIR / "load_from_file_changes.py") | ||
assert cfg.DICT.FOO == "bar" | ||
assert cfg.DICT.FOO == "Foo value from yaml" | ||
assert cfg.DICT.FOO2 == "Foo2 value from changes" | ||
|
||
|
||
def test_load_from_key_value(): | ||
from .data.base_cfg import cfg as cfg_base | ||
|
||
cfg = cfg_base.inherit() | ||
flat_data = { | ||
"DICT.FOO": "Foo value from flat data", | ||
"STR": "Str value from flat data", | ||
} | ||
cfg.add_transform(load_from_key_value(flat_data)) | ||
cfg.transform() | ||
assert cfg.DICT.FOO == flat_data["DICT.FOO"] | ||
assert cfg.DICT.FOO2 == "Default foo2 value" | ||
assert cfg.STR == flat_data["STR"] |