Skip to content

Commit 1afc2a6

Browse files
jeremie6windsamuel-gauthier
authored andcommitted
schema: add store_only parameter to parse_data_dict
Sometimes it is necessary to store only the data. Signed-off-by: Jeremie Leska <[email protected]> Acked-by: Samuel Gauthier <[email protected]>
1 parent 74e08c4 commit 1afc2a6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libyang/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def parse_data_dict(
241241
rpc: bool = False,
242242
rpcreply: bool = False,
243243
notification: bool = False,
244+
store_only: bool = False,
244245
) -> "libyang.data.DNode":
245246
"""
246247
Convert a python dictionary to a DNode object following the schema of this
@@ -276,6 +277,7 @@ def parse_data_dict(
276277
rpc=rpc,
277278
rpcreply=rpcreply,
278279
notification=notification,
280+
store_only=store_only,
279281
)
280282

281283

tests/test_data.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,3 +1112,22 @@ def test_dnode_builtin_plugins_only(self):
11121112
self.assertIsInstance(dnode, DLeaf)
11131113
self.assertEqual(dnode.value(), "test")
11141114
dnode.free()
1115+
1116+
def test_merge_store_only(self):
1117+
MAIN = {"yolo-nodetypes:test1": 50}
1118+
module = self.ctx.load_module("yolo-nodetypes")
1119+
dnode = module.parse_data_dict(MAIN, validate=False, store_only=True)
1120+
self.assertIsInstance(dnode, DLeaf)
1121+
self.assertEqual(dnode.value(), 50)
1122+
dnode.free()
1123+
1124+
def test_merge_builtin_plugins_only(self):
1125+
MAIN = {"yolo-nodetypes:ip-address": "test"}
1126+
self.tearDown()
1127+
gc.collect()
1128+
self.ctx = Context(YANG_DIR, builtin_plugins_only=True)
1129+
module = self.ctx.load_module("yolo-nodetypes")
1130+
dnode = module.parse_data_dict(MAIN, validate=False, store_only=True)
1131+
self.assertIsInstance(dnode, DLeaf)
1132+
self.assertEqual(dnode.value(), "test")
1133+
dnode.free()

0 commit comments

Comments
 (0)