Skip to content

Commit

Permalink
schema: add store_only parameter to parse_data_dict
Browse files Browse the repository at this point in the history
Sometimes it is necessary to store only the data.

Signed-off-by: Jeremie Leska <[email protected]>
Acked-by: Samuel Gauthier <[email protected]>
  • Loading branch information
jeremie6wind authored and samuel-gauthier committed Nov 15, 2024
1 parent 74e08c4 commit 1afc2a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def parse_data_dict(
rpc: bool = False,
rpcreply: bool = False,
notification: bool = False,
store_only: bool = False,
) -> "libyang.data.DNode":
"""
Convert a python dictionary to a DNode object following the schema of this
Expand Down Expand Up @@ -276,6 +277,7 @@ def parse_data_dict(
rpc=rpc,
rpcreply=rpcreply,
notification=notification,
store_only=store_only,
)


Expand Down
19 changes: 19 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,3 +1112,22 @@ def test_dnode_builtin_plugins_only(self):
self.assertIsInstance(dnode, DLeaf)
self.assertEqual(dnode.value(), "test")
dnode.free()

def test_merge_store_only(self):
MAIN = {"yolo-nodetypes:test1": 50}
module = self.ctx.load_module("yolo-nodetypes")
dnode = module.parse_data_dict(MAIN, validate=False, store_only=True)
self.assertIsInstance(dnode, DLeaf)
self.assertEqual(dnode.value(), 50)
dnode.free()

def test_merge_builtin_plugins_only(self):
MAIN = {"yolo-nodetypes:ip-address": "test"}
self.tearDown()
gc.collect()
self.ctx = Context(YANG_DIR, builtin_plugins_only=True)
module = self.ctx.load_module("yolo-nodetypes")
dnode = module.parse_data_dict(MAIN, validate=False, store_only=True)
self.assertIsInstance(dnode, DLeaf)
self.assertEqual(dnode.value(), "test")
dnode.free()

0 comments on commit 1afc2a6

Please sign in to comment.