From 1afc2a63108e15431b4903d4f7c909bb8c6c1884 Mon Sep 17 00:00:00 2001 From: Jeremie Leska Date: Wed, 6 Nov 2024 17:29:08 +0100 Subject: [PATCH] schema: add store_only parameter to parse_data_dict Sometimes it is necessary to store only the data. Signed-off-by: Jeremie Leska Acked-by: Samuel Gauthier --- libyang/schema.py | 2 ++ tests/test_data.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libyang/schema.py b/libyang/schema.py index a47974e..db0514d 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -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 @@ -276,6 +277,7 @@ def parse_data_dict( rpc=rpc, rpcreply=rpcreply, notification=notification, + store_only=store_only, ) diff --git a/tests/test_data.py b/tests/test_data.py index 1728042..4b7914e 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -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()