Skip to content

Commit 9d86ad9

Browse files
committed
schema: adds ability to get when context nodes
This patch adds ability to get context schema node from which when contition is evaluated. Signed-off-by: Stefan Gula <[email protected]>
1 parent 3072af0 commit 9d86ad9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

libyang/schema.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,14 @@ def when_conditions(self):
13961396
for cond in ly_array_iter(wh):
13971397
yield c2str(lib.lyxp_get_expr(cond.cond))
13981398

1399+
def when_conditions_nodes(self) -> Iterator[Optional["SNode"]]:
1400+
wh = ffi.new("struct lysc_when **")
1401+
wh = lib.lysc_node_when(self.cdata)
1402+
if wh == ffi.NULL:
1403+
return
1404+
for cond in ly_array_iter(wh):
1405+
yield None if cond.context == ffi.NULL else SNode.new(self.context, cond.context)
1406+
13991407
def parsed(self) -> Optional["PNode"]:
14001408
if self.cdata_parsed is None or self.cdata_parsed == ffi.NULL:
14011409
return None

tests/test_schema.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,14 @@ def tearDown(self):
843843
self.ctx.destroy()
844844
self.ctx = None
845845

846+
def test_anydata(self):
847+
snode = next(self.ctx.find_path("/yolo-nodetypes:any1"))
848+
self.assertIsInstance(snode, SAnydata)
849+
assert next(snode.when_conditions()) is not None
850+
snode2 = next(snode.when_conditions_nodes())
851+
assert isinstance(snode2, SAnydata)
852+
assert snode2.cdata == snode.cdata
853+
846854
def test_anydata_parsed(self):
847855
snode = next(self.ctx.find_path("/yolo-nodetypes:any1"))
848856
self.assertIsInstance(snode, SAnydata)

0 commit comments

Comments
 (0)